How to get a schema file in graphql using spqr-spring-boot-starter?

962 views Asked by At

Could anyone please help me how to get a schema file using spqr-spring-boot-starter?

I looked for the solutions online and found this: 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.

I need the schema file to enable auto-completion in Postman. Please assist if you know anything about this, this will be really helpful. Thanks!

1

There are 1 answers

0
Ohad Green On

Per spqr tutorial, you would want to define your graphQL schema in the RestController class, you can use that object for 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);
}