spring-graphql
spring-graphql copied to clipboard
Provide guidance on how to set up multiple GraphQL endpoints
I want two separate endpoints, each with their own schemas to not expose our internal schemas to clients through GraphiQL. Both will need have different security configurations as well. (Just reiterating that this is something we need to do)
I found this stack overflow asking for something similar, but was hoping to see if someone more familiar with this project had a better way of doing something like this?
https://stackoverflow.com/questions/62202051/is-there-a-way-to-expose-2-graphql-endpoints-using-spring-boot-starter-app-graph
Any advice would be appreciated here!
@rstoyanchev Just wanted to provide a little update here. This is something that I was able to implement over the past few days successfully. If this is something you think would be worthwhile, I would love to help get something concrete into the spring for graphql project here (Perhaps more relevant to the starter project now that I'm thinking of it).
Just a few notes:
- Turned off the graphql web mvc auto config, took that code and created a second
RouterFunction
set up with the separate schema files and stored each of theGraphQlSource
objects in a hashmap with their respective endpoints for later. - Created a
ExecutionGraphQlService
bean with my customMultiSourceExecutionGraphQlService
(Implements theExecutionGraphQlService
interface) that takes the hashmap mentioned in the last step and uses the request uri to determine whichGraphQlSource
to use
I'm sure there is more to this, especially if you would want to support not just web mvc, but it's a start. Would love to hear your thoughts on this.
Yes, I was going to comment along the same lines. The auto-config is really built for one GraphQL endpoint per JVM, but if you're willing to make your own config, it's not that much to replicate.
I think it would be useful to have a minimal sample of this for a start. The challenge with turning it into auto-config is that we won't be able to just detect the various beans like interceptors, exception resolvers, and others since it won't be clear which endpoint they belong to. However, we can give it more consideration if it becomes a common need.
Thanks for the reply here. I'll set up a sample project for you when I have some time. I'd love to see this get implemented at some point
@dsarlo we'll experiment and document how to this. There might also be some small changes needed.
Guys, can you show some example how to do this configuration?
Guys, can you show some example how to do this configuration?
Hey! The general approach is described above. Still haven’t had time to create an example project. When I find the time, I’ll post here!
We'll consider this as part of #208.