简体   繁体   English

如何禁用 GraphQL-Java 中的自省查询?

[英]How to disbale introspection query in GraphQL-Java?

I am using GraphQL-Java version:11.0我正在使用 GraphQL-Java 版本:11.0

From Official GraphQL-Java docum.netation I found that I can disable the introspection query as belwo:Official GraphQL-Java docum.netation中,我发现我可以将内省查询禁用为 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这个 SO 问题的答案中给出了同样的内容

But the issue is in above solutions the fieldVisibility is available with object returned by GraphQLSchema.newSchema() .但问题出在上述解决方案中, fieldVisibility可用于GraphQLSchema.newSchema()返回的 object 。

I am building the GraphQL schema as below:我正在构建 GraphQL 架构,如下所示:

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?正如您在上面的代码中看到的,我没有在任何地方使用GraphQLSchema.newSchema() ,所以我无法为 introspectionQuery 设置fieldVisibility ,谁能建议我如何修改上面的代码以适应fieldVisibility选项?

Any help is much appreciated.任何帮助深表感谢。 Thanks!谢谢!

The fieldVisibility option is also available on RuntimeWiring , so I just did fieldVisibility选项也可以在RuntimeWiring上使用,所以我只是做了

RuntimeWiring.Builder builder = graphQLResolvers.newRuntimeWiringBuilder();
 builder.fieldVisibility(NoIntrospectionGraphqlFieldVisibility.NO_INTROSPECTION_FIELD_VISIBILITY);

Hope it helps someone:)希望它能帮助某人:)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM