You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
The text was updated successfully, but these errors were encountered:
Description
https://www.graphql-java.com/documentation/sdl-directives includes the following code:
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.The text was updated successfully, but these errors were encountered: