3 ms·
I've recently been exploring GraphQL. It's an excellent way to design and maintain Web APIs imo. GitHub is a great resource for learning how GraphQL works. I've
by j_m_b 9y ago
I've recently been exploring GraphQL. It's an excellent way to design and maintain Web APIs imo. GitHub is a great resource for learning how GraphQL works. I've been using the GraphiQL tool to experiment with it. However, there is a big issue with the GraphQL implementation in that requests using the POST method work, but the mirror GET requests do not return the same results. For example, see the response for the simple query
"query { viewer { login }}"
My understanding is that
this request should return the same result, whether or not it is a POST or GET request (http://graphql.org/learn/serving-over-http/#get-request http://graphql.org/learn/serving-over-http/#get-request). Could someone provide some clarity on this?
- jlouis 9y agoYou are correct. The transport is a detail and if the query is the same, the response should be the same. What sometimes do create a difference is if one transport has one way of authenticating whereas the other transport-path hasn't. Perhaps this is what happens with the `viewer` output here. I'm fond of the idea of allowing the query itself to contain every head-meta-data as well, i.e.,: `query { viewer(auth_token: "...") { login }}` because such queries are possible to copy in a URL without having to worry about side-channels of auth.
- shurcooL 9y agoPerhaps https://developer.github.com/v4/guides/forming-calls/#communicating-with-graphql https://developer.github.com/v4/guides/forming-calls/#commun... is relevant: > In REST, HTTP verbs determine the operation performed. In GraphQL, you'll provide a JSON-encoded body whether you're performing a query or a mutation, so the HTTP verb is POST. The exception is an introspection query, which is a simple GET to the endpoint.
- j_m_b 9y agoThanks. I'm not sure that this conforms to GraphQL best practices. http://graphql.org/learn/serving-over-http/ http://graphql.org/learn/serving-over-http/ It seems GET methods should be supported for more than just introspection queries.
- eridius 9y agoGET requests don't have HTTP bodies. How are you passing that JSON string in a GET request?
- lilactown 9y agoIt gets serialized into the URL.