[英]How to get a schema file in graphql using spqr-spring-boot-starter?
Could anyone please help me how to get a schema file using spqr-spring-boot-starter?谁能帮助我如何使用 spqr-spring-boot-starter 获取模式文件?
I looked for the solutions online and found this: How to get the generated scheme file.graphqls using SPQR?我在网上找了解决方案,发现了这个: How to get the generated scheme file.graphqls using SPQR?
new SchemaPrinter(
// Tweak the options accordingly
SchemaPrinter.Options.defaultOptions()
.includeScalarTypes(true)
.includeExtendedScalarTypes(true)
.includeIntrospectionTypes(true)
.includeSchemaDefintion(true)
).print(schema);
But I'm not sure what should I pass for schema?但我不确定我应该为模式传递什么? As I'm using spqr-spring-boot-starter, I'm not writing anything related to GraphQLSchema instance.
当我使用 spqr-spring-boot-starter 时,我没有写任何与 GraphQLSchema 实例相关的内容。
I need the schema file to enable auto-completion in Postman.我需要架构文件来启用 Postman 中的自动完成功能。 Please assist if you know anything about this, this will be really helpful.
如果您对此有所了解,请提供帮助,这将非常有帮助。 Thanks!
谢谢!
Per spqr tutorial, you would want to define your graphQL schema in the RestController class, you can use that object for SchemaPrinter.根据 spqr 教程,您需要在 RestController class 中定义 graphQL 模式,您可以将 object 用于 SchemaPrinter。 You can set it public and use it elsewhere in the code
您可以将其设置为公开并在代码中的其他地方使用它
@Autowired
public GraphQLController(CheckConfigurationDemoResolver checkConfigurationDemoResolver) {
GraphQLSchema schema = new GraphQLSchemaGenerator()
schema = new GraphQLSchemaGenerator()
.withBasePackages("com.acme.mygraphqlproj")
.withOperationsFromSingleton(checkConfigurationDemoResolver)
.generate();
graphQL = GraphQL.newGraphQL(schema).build();
String schemaString = new SchemaPrinter().print(schema);
System.out.println("schemaString = " + schemaString);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.