spring-graphql

How to use Spring GraphQL in an existing server


I have an existing application running in a non-Spring application server. I'd like to integrate a GraphQL API into that application using spring-graphql. How would I go about that? My intention was to get a reference to the GraphQlSource to execute queries sent to an HTTP endpoint implemented in this server. In learning about spring-graphql, I went through the tutorial by generating a Spring Boot application using Spring GraphQL and MVC. I also created a component that obtained a reference to the GraphQlSource via auto-wiring and was able to execute GraphQL queries on the server side.

Now, I want to take what I've prototyped and integrate that into my existing application server without requiring a full-fledged application. I think what this boils down to is creating a GraphQLSource that is configured identically to the one created by GraphQlAutoConfiguration without actually having to call SpringApplication.run() on a SpringBootApplication.

I realize that I could just create a GraphQLSource directly, but I like some of the additional configuration magic that GraphQlAutoConfiguration applies.


Solution

  • This documentation enhancement was requested by the community. In general, you should consider 3 essential beans for your infrastructure:

    A minimal Spring for GraphQL "standalone" setup is now described in a dedicated section of the reference documentation.