dillonkearns / elm-graphql

Autogenerate type-safe GraphQL queries in Elm.

Home Page:https://package.elm-lang.org/packages/dillonkearns/elm-graphql/latest

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Add operationName JSON field or querystring parameter

yonigibbs opened this issue · comments

When posting a GraphQL request, if an operationName is specified, this is included in the text of the query JSON field, e.g.

{
	"query": "query MyOperationName { ... }"
}

It is also valid to additionally specify this as an extra JSON field:

{
	"operationName": "MyOperationName"
	"query": "query MyOperationName { ... }"
}

elm-graphql currently uses the first approach above, and this is definitely valid according to the schema (see https://spec.graphql.org/June2018/#GetOperation()). However, it looks like some libraries don't seem to implement this correctly, and only extract the operation name from the operationName JSON field (e.g. see graphql-java-kickstart/graphql-java-servlet#264). Additionally, if/when elm-graphql adds the ability for one HTTP request to contain multiple queries/mutations, then at that point the operationName will have to be explicitly included as a JSON field (see previous link to the GraphQL spec, and also see https://graphql.org/learn/serving-over-http/#post-request).

So, would it possibly make sense to add this JSON field in?

The above applies to sending a POST request. When doing a GET, the same logic applies, but for a querystring argument called operationName instead of a JSON field.

Another useful reference might be the Apollo documentation, which follows the same rules explained above, but in their examples always includes the operationName JSON field (or querystring parameter) even though their example HTTP request only includes one query: https://www.apollographql.com/docs/apollo-server/requests/.