I am using GraphQL-Java version:11.0
From Official GraphQL-Java documenetation I found that I can disable the introspection query as belwo :
GraphQLSchema schema = GraphQLSchema.newSchema()
.query(StarWarsSchema.queryType)
.fieldVisibility(NoIntrospectionGraphqlFieldVisibility.NO_INTROSPECTION_FIELD_VISIBILITY)
.build();
Same has been given in this SO question's answer
But the issue is in above solutions the fieldVisibility
is available with object returned by GraphQLSchema.newSchema()
.
I am building the GraphQL schema as below:
public GraphQLProvider init(GraphQLResolvers graphQLResolvers) {
GraphQLSchema graphQLSchema = buildSchema (typeRegistry, runtimeWiring);
this.graphQL = createInstance (graphQLSchema);
return this;
}
private GraphQLSchema buildSchema (TypeDefinitionRegistry typeRegistry, RuntimeWiring runtimeWiring) {
SchemaGenerator schemaGenerator = new SchemaGenerator();
return schemaGenerator.makeExecutableSchema(typeRegistry, runtimeWiring);
}
private GraphQL createInstance (GraphQLSchema graphQLSchema) {
return GraphQL.newGraphQL(graphQLSchema).build();
}
As you can see in above code, I am not using GraphQLSchema.newSchema()
anywhere, so I am not able to set the fieldVisibility
for introspectionQuery, can anyone suggest how can I modify above code to accommodate fieldVisibility
option?
Any help is much appreciated. Thanks!
The fieldVisibility
option is also available on RuntimeWiring
, so I just did
RuntimeWiring.Builder builder = graphQLResolvers.newRuntimeWiringBuilder();
builder.fieldVisibility(NoIntrospectionGraphqlFieldVisibility.NO_INTROSPECTION_FIELD_VISIBILITY);
Hope it helps someone :)