spring-graphql icon indicating copy to clipboard operation
spring-graphql copied to clipboard

Provide guidance on how to set up multiple GraphQL endpoints

Open dsarlo opened this issue 2 years ago • 6 comments

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!

dsarlo avatar Jul 15 '22 00:07 dsarlo

@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:

  1. 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 the GraphQlSource objects in a hashmap with their respective endpoints for later.
  2. Created a ExecutionGraphQlService bean with my custom MultiSourceExecutionGraphQlService (Implements the ExecutionGraphQlService interface) that takes the hashmap mentioned in the last step and uses the request uri to determine which GraphQlSource 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.

dsarlo-viso avatar Jul 20 '22 17:07 dsarlo-viso

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.

rstoyanchev avatar Jul 20 '22 20:07 rstoyanchev

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-viso avatar Jul 28 '22 18:07 dsarlo-viso

@dsarlo we'll experiment and document how to this. There might also be some small changes needed.

rstoyanchev avatar Aug 04 '22 07:08 rstoyanchev

Guys, can you show some example how to do this configuration?

danielgatis avatar Oct 11 '22 00:10 danielgatis

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!

dsarlo avatar Oct 11 '22 03:10 dsarlo

We'll consider this as part of #208.

bclozel avatar Nov 03 '22 11:11 bclozel