spring-projects / spring-graphql

Spring Integration for GraphQL
https://spring.io/projects/spring-graphql
Apache License 2.0
1.52k stars 300 forks source link

Batch Multiple Queries #817

Closed bszeliga closed 2 months ago

bszeliga commented 1 year ago

It appears that being able to send multiple batched queries is not supported.

I would like to be able to make a single network call to be able to execute multiple queries.

bclozel commented 1 year ago

I don't understand, can you elaborate? What are you trying to achieve?

Can you share a sample GraphQL query that shows what's currently not supported? Which parts of Spring for GraphQL are you using?

bszeliga commented 1 year ago

So I'm able to execute a query for a random color

curl -v http://localhost:8080/graphql -H "Content-Type: application/json" --data '{"query":"query getRandomColor{ getRandomColor } "}'
*   Trying 127.0.0.1:8080...                                      
* Connected to localhost (127.0.0.1) port 8080 (#0)               
> POST /graphql HTTP/1.1                                          
> Host: localhost:8080                                            
> User-Agent: curl/8.1.2                                                                                                            
> Accept: */*                                                     
> Content-Type: application/json                                  
> Content-Length: 51                                              
>                                                                                                                                   
< HTTP/1.1 200 OK                                                                                                                   
< Content-Type: application/json                                                                                                    
< Content-Length: 33                                                                                                                
<                                                                                                                                                                                                                                                                        
* Connection #0 to host localhost left intact                     
{"data":{"getRandomColor":"RED"}}%                                

And I can execute a query for a random Int

curl -v http://localhost:8080/graphql -H "Content-Type: application/json" --data '{"query":"query getRandomInt{ getRandomInt } "}'
*   Trying 127.0.0.1:8080...
* Connected to localhost (127.0.0.1) port 8080 (#0)
> POST /graphql HTTP/1.1
> Host: localhost:8080
> User-Agent: curl/8.1.2
> Accept: */*
> Content-Type: application/json
> Content-Length: 47
> 
< HTTP/1.1 200 OK
< Content-Type: application/json
< Content-Length: 37
< 
* Connection #0 to host localhost left intact
{"data":{"getRandomInt":-1460752148}}%   

But I can't combine these two queries into a single remote call

curl -v http://localhost:8080/graphql -H "Content-Type: application/json" --data '[{"query":"query getRandomColor{ getRandomColor } "}, {"query":"query getRandomInt{ getRandomInt } "}]'
*   Trying 127.0.0.1:8080...                                      
* Connected to localhost (127.0.0.1) port 8080 (#0)
> POST /graphql HTTP/1.1                                          
> Host: localhost:8080                                            
> User-Agent: curl/8.1.2                                          
> Accept: */*                                                     
> Content-Type: application/json                                  
> Content-Length: 102                                             
>                                                                 
< HTTP/1.1 400 Bad Request                                        
< Content-Type: application/json                                  
< Content-Length: 123                                             
<                                                                 
* Connection #0 to host localhost left intact
{"timestamp":"2023-09-18T19:36:52.284+00:00","path":"/graphql","status":400,"error":"Bad Request","requestId":"af3ace97-9"}% 

This is possible however with the legacy com.graphql-java-kickstart:graphql-spring-boot-starter:15.0.0

bclozel commented 1 year ago

I think you're referring to batch requests, which is a non-standard feature supported by Apollo and others.

It doesn't look like the official issue for the GraphQL spec is getting traction. I will leave this issue opened for now to see if there is community demand for this, but at this time we are not likely to introduce features that are at odds with the spec.

trthsa commented 8 months ago

Up vote for this feature!

VnzBzk commented 8 months ago

Up vote!

SarahDiet commented 8 months ago

Up vote!

bclozel commented 8 months ago

Please use the upvote feature on the original description. Adding comments like this just adds noise to the issue tracker and doesn't count when ranking issues by popularity.

jimartinmoreno commented 7 months ago

Hi all. First off thank you for your great job! Any update here? We are facing a migration from kickstart to Spring from Graphql, everything is going smooth, but then we realize that we have an issue with executing multiple batched queries in one request. This feature was previously supported by the kickstart implementation: curl -Sss 'http://localhost:8080/graphql' -u xxx:xxx -H 'accept: application/json' -H 'content-type: application/json' \ --data-raw '{"batch":[{"query":"query FIND_PERSON {findPerson(searchCriteria: {email: \"a@b.com\"}) {id}}","variables":null},{"query":"query FIND_PERSON {findPerson(searchCriteria: {email: \"test@springboot.com\"}) {id}}","variables":null}]}'

ballanceps commented 2 months ago

Upvote from me!

bclozel commented 2 months ago

Thanks all for the interest and upvotes.

Unfortunately, this didn't get much traction on the spec side and I don't see ourselves investing in this feature while there are so many unknowns.

I thought about implementing a different protocol handler, just like we do for SSE, WebSocket and others. But here, there are major issues with this:

I don't see a way to solve those problems right now, so I'm closing this issue for now. We can reopen if we find a way to solve those and if this gets traction in the spec body.