简体   繁体   English

如何使用 spqr-spring-boot-starter 在 graphql 中获取模式文件?

[英]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.

相关问题 如何使用 spring-spqr graphql-spqr-spring-boot-starter graphQL 的注释创建片段 - how to create fragments using Annotations of spring-spqr graphql-spqr-spring-boot-starter graphQL 我们如何从 GraphQL 的 RequestContextHolder 中获取 GraphQL 的 HttpServletRequest(DefaultGlobalContext)(使用 graphql-spqr-spring-boot-starter)? - How can we get HttpServletRequest(DefaultGlobalContext) for GraphQL from RequestContextHolder for GraphQL (using graphql-spqr-spring-boot-starter)? 为什么我会收到与使用 graphql-spqr-spring-boot-starter 的“类型名称冲突”相关的警告? - Why am I getting a warning related to 'type name collision' using graphql-spqr-spring-boot-starter? 带有 Spring Boot 和事务边界的 graphql-spqr - graphql-spqr with Spring Boot and Transactional Boundary spring boot starter graphql无法正常工作 - spring boot starter graphql not working 如何使用 SPQR 获取生成的方案文件 .graphqls? - How to get the generated scheme file .graphqls using SPQR? Spring 使用 GraphQL 引导 - 架构问题 - Spring Boot with GraphQL - schema issue 我可以将 HandshakeInterceptor 与 graphql-spring-boot-starter 一起使用来获取 Cookies 吗? - Can I use HandshakeInterceptor With graphql-spring-boot-starter To Get Cookies? 如何在spring-boot-starter-data-redis中获取Jedis实例? - How to get a Jedis instance in spring-boot-starter-data-redis? graphql-spring-boot-starter 应用程序只有 websockets - graphql-spring-boot-starter Application with only websockets
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM