Skip to content

Some kind of interceptor for validating accessToken for all inputs in all queries/mutations? #525

Answered by srinivasankavitha
ghost asked this question in Q&A
Discussion options

You must be logged in to vote

I just tried this in a project, and I see the exception handler being invoked as expected. Here is the sample code I tried with:

@Override
    public DataFetcher<?> instrumentDataFetcher(DataFetcher<?> dataFetcher, InstrumentationFieldFetchParameters parameters) {
        return environment -> {
            // Replace with your authorization logic or custom code to wrap each data fetcher call
            if (environment.getArgument("name") == null) {
                throw new AccessDeniedException("Denied test");
            }
            return dataFetcher.get(environment);
        };
    }

This method is invoked prior to executing each data fetcher, and the exception is caught as expec…

Replies: 3 comments 1 reply

Comment options

You must be logged in to vote
1 reply
@ghost
Comment options

Answer selected
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant