I am trying to disable GraphQL Introspection in my project and not having much luck with specific framework I am using. Some articles say it can be done in CcodeRegistry module but that is a decompiled source which is read only. Has anyone achieved this with the GraphQL-java-kickstart framework ?
Below are the dependencies in my pom file:
<dependency>
<groupId>com.graphql-java</groupId>
<artifactId>graphql-java</artifactId>
<version>${graphql.java.version}</version>
</dependency>
<dependency>
<groupId>com.graphql-java-kickstart</groupId>
<artifactId>graphql-java-tools</artifactId>
<version>${graphql.java.tools.version}</version>
</dependency>
<dependency>
<groupId>com.graphql-java</groupId>
<artifactId>graphql-java-extended-validation</artifactId>
<version>0.0.3</version>
</dependency>
Graphql-java
With graphql-java, you build a
GraphQLSchemausing aGraphQLSchema.Builder. You need to set the builder visibility for the introspection field before building to disable the introspection query.You can use the graphql-java-tools implementation as a reference.
Graphql-java-tools
With graphql-java-tools, you build a
SchemaParserusing aSchemaParserBuilder. The SchemaParserBuilder needs a SchemaParserOptions object. When building the SchemaParserOptions, you can enable or disable the introspection query. Here is a very simplified implementation.You can use the graphql-spring-boot implementation as a reference.
Graphql-spring-boot
If you are using graphql-spring-boot, according to the graphql-java-tools README, you can disable the introspection query by setting the
graphql.tools.introspection-enabledproperty to false in your application.properties or application.yml file.Graphql-spqr
With Graphql-spqr, the idea is the same as in graphql-java: the setting the builder field visibility. See my answer to this question for how to implement it.