2

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.

Jeff
  • 267
  • 5
  • 20
  • May not help but this tutorial (which I'm following) is using graphiql. https://www.howtographql.com/graphql-java/0-introduction/ – kometen Sep 19 '19 at 09:03

2 Answers2

2

It can be enabled in properties: graphql.graphiql.enabled=true It is accessible via the root url +/graphiql example http://localhost:8080/graphiql

You can find a good detailed example here : https://github.com/NoorKrichen/GraphQL-Spring-Boot-Example

Romero
  • 33
  • 1
  • 9
0

Do you have a sample of your setup in git?

  • It sounds like some configuration problem. But naturally using graphql-java-spring-boot-starter-webmvc all your *.graphql schemas should be picked up in the configured schema resource path. check if you have the path set in your application.yml or if your schema is in the configured path if its already set or by default.

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

  • This makes sense for quick guides and demos as using Springboot the plumbing is somehow hidden away from you so that you can focus on the technology at hand being demo'd in this case GraphQl.

On GraphiQL:

  • Sounds like you are intending to have this embedded with your application, you may not want to do so in production. Depending on your use case there are many other alternatives that are standalone and gives you all the functionality of GraphiQL plus more e.g Altair Graphql Client and Insomnia to name a few.
DaddyMoe
  • 990
  • 1
  • 14
  • 20
  • Thank you DaddyMoe. Agree with you graphql-java-spring-boot-starter will easy my development work. However, this framework could not meet my requirement so I have to work with common spring web mvc + graphql-java. Furthermore, I need to introduce graphiql into my project so I'm trying to use graphiql-spring-boot-starter (thus of course without graphql-java-spring-boot-starter) in my project. so I have to deal with the communication between graphql+spring and graphiql by myself. I don't find enough information about this so all my tries are failed. Now I succeeded with Vert.x + GraphQL-java – Jeff Sep 23 '19 at 02:08