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

application/graphql support

Open zombor opened this issue 7 years ago • 1 comments

Is there any support (or plans for it) for this content type for input? e.g. I expected the following request to work from the simple server example in the readme:

curl -XPOST -d 'query { hello }' -H "Content-Type:application/graphql" localhost:8080/query

But I get invalid character 'q' looking for beginning of value (since I assume it's just trying to parse json).

zombor avatar Jun 26 '18 14:06 zombor

Take a look at the handler code here https://github.com/graph-gophers/graphql-go/blob/master/relay/relay.go#L50 Indeed the handler expects a JSON request with query and optional variables and operationName.

It should be trivial for you to build a custom handler and invoke:

h.Schema.Exec(r.Context(), params.Query, params.OperationName, params.Variables)

where params.Query comes from the request body.

pavelnikolov avatar Jun 27 '18 13:06 pavelnikolov