javaspring-bootgraphql-javagraphiql

How to integrate GraphiQL with Spring-Boot?


My target is to build a GraphQL server on Spring with (1) GraphiQL IDE (2) dynamic GraphQL schema at run-time. My GraphQL engine is GraphQL-Java.

In my first try, I use graphql-java-spring-boot-starter-webmvc and graphiql-spring-boot-starter. Both the GraphQL server and the GraphiQL work well. However, under the graphql-java-spring-boot-starter-webmvc framework, a @Bean of GraphQL class is needed. In this bean, the schema is loaded when the server starts so it could not been updated.

In my second try, I don't use graphql-java-spring-boot-starter-webmvc. Instead, I choose spring-boot-starter-web to start the web server and define my own RestController. This is easy to update the GraphQL instance. But I don't find a way to integrate with GraphiQL. I googled GraphiQL+Spring but all solutions are with graphql-java-spring-boot-starter.

Appreciate if anyone could provide me an idea on either approach.


Solution

  • Do you have a sample of your setup in git?

    On your second point: "I googled GraphiQL+Spring but all solutions are with graphql-java-spring-boot-starter."

    On GraphiQL: