-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
What is the response format of a multi-operations query? #29
Comments
We'd describe that as a When executing, we need to know which If you only have one operation in a Hope this helps! |
@dschafer thanks for your answer but it doesn't help me a lot. I understand how it is supposed to work internally. But, let's forget the server, consider it a black box and imagine I am a client. If I send this document:
What do I get in response from the server? |
An error. The The spec:
In our reference implementation, we implemented a helper where if there's only one operation in the document, it's implied that the operation name is the name of that operation (since that simplifies the common case). But you can't run multiple queries in the same request; if that's the desired behavior, a single query that combines them can be run instead. With fragments, that would become simple:
|
Ok I understand, thank you. I understood that the executor could only handle one operation at a time but maybe it could have been called many times one operation after the other. So now what wonder me is... what's the point of having a document that can contains many operations ? |
And to finish: how the client is supposed to send which operation to run if there are many operations in the document ? Until now I imagined graphql as a simple |
Up to the server; the reference implementation just has the
This is definitely the right way to think about things; a Document is just an additional concept that can contain many GraphQLQueries. If you send a document with only one query, then graphql is just QueryInDocument => Server => Response. If the document has many queries, then you specify a query so that we can go Document => Query => Server => Response
The use is threefold:
You're absolutely correct that in the model we describe (pass a string to the server, get a response back), a Document with multiple operations isn't that useful; we wanted to permit it for the reasons described above. |
Ok thanks a lot for your answers. I started to think like that about the argument for the operation to run, and for the "storage" of queries on the server (like redis does for lua scripts). I now have a better understanding of the whole thing and can go back to my graphql server in python. Thanks a lot. |
Thanks for the great questions! |
@dschafer I saw this and it peaked my curiosity. Did this ever make it into the spec? I haven't been able to find it anywhere yet.
|
There's not an official spec for Facebook's implementation as far as I know; but Hot Chocolate have great documentation around their implementation of it via the |
If we have a simple query, with only a SelectionSet:
which is the same as
The tests in
graphql.js
show this expected answer:I know we can have many root in one query:
Resulting in this answer:
But, and it's my main concern, what if we have more that one operation in one query, which seems to be valid in the specifications (examples in http://facebook.github.io/graphql/#sec-All-Variable-Uses-Defined and http://facebook.github.io/graphql/#sec-All-Variables-Used).
For example what is the expected answer for this graphql query (dumb query just for the example):
I currently have no idea, except that there should be one more level between
data
and a query result using the name of the operation (which must be unique in the document, as said in the specification).Or each query have its own "object" response, with
data
,errors
... But in this case how are they "encapsulated"? In a main object with the operation names used as keys ? I could not find anything about this in the specification or the graphql.js tests.Thanks for your answer, I'm currently writing a python graphql server and it will help me to know that ;)
The text was updated successfully, but these errors were encountered: