spring-projects / spring-graphql

Spring Integration for GraphQL
https://spring.io/projects/spring-graphql
Apache License 2.0
1.5k stars 297 forks source link

Support for Anyc creation of GraphQl Schema #989

Closed djett41 closed 1 month ago

djett41 commented 1 month ago

Hello! I have the following usecase and have been digging around but don't see any documentation that supports my usecase which requires generating a GraphQl schema at runtime. If anyone has seen this done before please point me in the right direction :-) I appreciate it!

  1. When the app starts, hit an external API to grab the configuration files of different Types and fields for that type.
  2. Dynamically create a graphql Schema with queries/mutations/subscriptions/query inputs etc based on those fields/types loaded from the exernal API
  3. Allow for the server to be able to perform CRUD operations against another API for each type
  4. Have a tool like Graphiql update to show the latest types and fields and allow you to query/mutate each type

Is this possible in spring-graphql at the moment? Thanks!

bclozel commented 1 month ago

Your application can provide its own GraphQlSource bean for that. Right now, there is a small limitation in the Spring Boot auto-configuration where a schema file on disk is still required, even if it is empty. This limitation is considered under https://github.com/spring-projects/spring-boot/issues/33096

Other than that, Spring for GraphQL should support your use case just fine.

rstoyanchev commented 1 month ago

AbstractGraphQlSourceBuilder has two sub-classes, one with the default way in which we initialize the GraphQLSchema e.g. by parsing schema files, and another with a given GraphQLSchema instance. You can probably use that as a base class, and override the initGraphQlSchema method.