Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Documentation includes deprecated/dead code #3576

Open
ataylormays-duetto opened this issue Apr 25, 2024 · 1 comment
Open

Documentation includes deprecated/dead code #3576

ataylormays-duetto opened this issue Apr 25, 2024 · 1 comment
Labels
keep-open Tells Stale Bot to keep PRs and issues open

Comments

@ataylormays-duetto
Copy link

Description

https://www.graphql-java.com/documentation/sdl-directives includes the following code:

class AuthorisationDirective implements SchemaDirectiveWiring {

    @Override
    public GraphQLFieldDefinition onField(SchemaDirectiveWiringEnvironment<GraphQLFieldDefinition> environment) {
        String targetAuthRole = (String) environment.getDirective().getArgument("role").getValue();

        GraphQLFieldDefinition field = environment.getElement();
        GraphQLFieldsContainer parentType = environment.getFieldsContainer();
        //
        // build a data fetcher that first checks authorisation roles before then calling the original data fetcher
        //
        DataFetcher originalDataFetcher = environment.getCodeRegistry().getDataFetcher(parentType, field);
        DataFetcher authDataFetcher = new DataFetcher() {
            @Override
            public Object get(DataFetchingEnvironment dataFetchingEnvironment) throws Exception {
                Map<String, Object> contextMap = dataFetchingEnvironment.getContext();
                AuthorisationCtx authContext = (AuthorisationCtx) contextMap.get("authContext");

                if (authContext.hasRole(targetAuthRole)) {
                    return originalDataFetcher.get(dataFetchingEnvironment);
                } else {
                    return null;
                }
            }
        };
        //
        // now change the field definition to have the new authorising data fetcher
        environment.getCodeRegistry().dataFetcher(parentType, field, authDataFetcher);
        return field;
    }
}

However, DataFetcher originalDataFetcher = environment.getCodeRegistry().getDataFetcher(parentType, field); is a deprecated method, which has now been removed in the latest v22 of graphql-java: https://github.com/graphql-java/graphql-java/pull/3514/files.

@ajkerr
Copy link

ajkerr commented May 2, 2024

I opened a PR at graphql-java/graphql-java-page#160 to address another case of this.

@dondonz dondonz added the keep-open Tells Stale Bot to keep PRs and issues open label Jun 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
keep-open Tells Stale Bot to keep PRs and issues open
Projects
None yet
Development

No branches or pull requests

3 participants