【问题标题】:How to get a schema file in graphql using spqr-spring-boot-starter?如何使用 spqr-spring-boot-starter 在 graphql 中获取模式文件?
【发布时间】:2020-11-16 07:03:40
【问题描述】:

谁能帮助我如何使用 spqr-spring-boot-starter 获取架构文件?

我在网上寻找解决方案,发现: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);

但我不确定我应该为模式传递什么?由于我使用的是 spqr-spring-boot-starter,因此我没有编写任何与 GraphQLSchema 实例相关的内容。

我需要架构文件来启用 Postman 中的自动完成功能。如果您对此有所了解,请提供帮助,这将非常有帮助。谢谢!

【问题讨论】:

    标签: java graphql graphql-spqr graphql-spqr-spring-boot-starter


    【解决方案1】:

    根据 spqr 教程,您可能希望在 RestController 类中定义您的 graphQL 模式,您可以将该对象用于 SchemaPrinter。 您可以将其设置为公开并在代码的其他地方使用它

    @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);
    }
    

    【讨论】:

      猜你喜欢
      • 2021-02-07
      • 2020-08-19
      • 2020-10-01
      • 2023-03-21
      • 2021-08-31
      • 2020-09-23
      • 2019-10-13
      • 2020-09-16
      • 2021-12-14
      相关资源
      最近更新 更多