在GraphQL java工具中禁用GraphQL内省

在GraphQL java工具中禁用GraphQL内省,graphql,graphql-java,graphql-schema,graphql-java-tools,Graphql,Graphql Java,Graphql Schema,Graphql Java Tools,我试图在我的项目中禁用GraphQL内省,但在我使用的特定框架中运气不太好。一些文章说它可以在CcodeRegistry模块中完成,但这是一个只读的反编译源代码。有人通过graphqljavakickstart框架实现了这一点吗 以下是我的pom文件中的依赖项: com.graphql-java graphql java ${graphql.java.version} com.graphql-java-kickstart graphql java工具 ${graphql.java.tools.

我试图在我的项目中禁用
GraphQL
内省,但在我使用的特定框架中运气不太好。一些文章说它可以在
CcodeRegistry
模块中完成,但这是一个只读的反编译源代码。有人通过
graphqljavakickstart
框架实现了这一点吗

以下是我的pom文件中的依赖项:


com.graphql-java
graphql java
${graphql.java.version}
com.graphql-java-kickstart
graphql java工具
${graphql.java.tools.version}
com.graphql-java
graphql java扩展验证
0.0.3
Graphql java 使用GraphQLJava,您可以使用
GraphQLSchema.Builder
构建一个
GraphQLSchema
。在生成之前,需要为“内省”字段设置生成器可见性,以禁用内省查询

GraphQLSchema.Builder builder = GraphQLSchema.newSchema()
                                     .query(query)
                                     .mutation(mutation)
                                     .subscription(subscription)
                                     .additionalTypes(dictionary);

builder.fieldVisibility(NoIntrospectionGraphqlFieldVisibility.NO_INTROSPECTION_FIELD_VISIBILITY);

GraphQLSchema = builder.build();
您可以使用作为参考

Graphql java工具 使用GraphQLJava工具,您可以使用
SchemaParserBuilder
构建
SchemaParser
。SchemaParserBuilder需要一个SchemaParserOptions对象。在构建SchemaParseProptions时,可以启用或禁用内省查询。这里是一个非常简化的实现

SchemaParserBuilder builder = new SchemaParserBuilder();
final SchemaParserOptions.Builder optionsBuilder = newOptions();
optionsBuilder.introspectionEnabled(introspectionEnabled);
return builder.options(optionsBuilder.build()).build();
您可以使用作为参考

Graphql弹簧靴 如果您使用的是graphql spring boot,根据graphql java工具,您可以通过在application.properties或application.yml文件中将
graphql.tools.introspection enabled
属性设置为false来禁用内省查询

graphql:
    tools:
        schema-location-pattern: "**/*.graphqls"
        # Enable or disable the introspection query. Disabling it puts your server in contravention of the GraphQL
        # specification and expectations of most clients, so use this option with caution
        introspection-enabled: false  
图ql-spqr
对于Graphql spqr,其思想与Graphql java中的相同:设置生成器字段可见性。请参阅我的答案以了解如何实现它。

问题是我没有使用springboot,该项目基于Google Dagger 2,因此必须通过代码完成。抱歉,我误读了您的依赖项。我更新了我的答案以涵盖GraphQLJava和GraphQLJava工具。