Skip to content
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

[Discuss] Force GraphQL introspection queries to use different Content-Type #1510

Open
mxmlnglt opened this issue May 20, 2019 · 5 comments
Open

Comments

@mxmlnglt
Copy link

mxmlnglt commented May 20, 2019

  • Insomnia Version: 6.5.3
  • Operating System: Windows 10 Pro (64-bit)

Details

When requesting the schema from the GraphQL server, Insomnia uses the user-input HTTP header "Content-Type" to POST the IntrospectionQuery, whatever its value is.
However this value should always be application/json as that's how the IntrospectionQuery is formatted.

In the case below (using the open API at https://countries.trevorblades.com/ ) I purposely entered a fictitious Content-Type to reflect how the value is picked-up by Insomnia. And the server fails with a 500 error.

To be noted: when I send GraphQL queries to my local/dev server, I usually use Content-Type: application/graphql but Insomnia fails to retrieve a schema too because the library handling the request (GraphQL Java) doesn't expect JSON in place of a pure GraphQL query.

* Preparing request to https://countries.trevorblades.com/
* Using libcurl/7.57.0-DEV OpenSSL/1.0.2o zlib/1.2.11 libssh2/1.7.0_DEV
* Current time is 2019-05-20T12:31:23.482Z
* Disable timeout
* Enable automatic URL encoding
* Enable SSL validation
* Enable cookie sending with jar of 3 cookies
* Found bundle for host countries.trevorblades.com: 0x1ce6933a850 [can pipeline]
* Re-using existing connection! (#2) with host countries.trevorblades.com
* Connected to countries.trevorblades.com (52.22.145.207) port 443 (#2)

> POST / HTTP/1.1
> Host: countries.trevorblades.com
> User-Agent: insomnia/6.5.3
> Content-Type: **application/whatever**
> Accept: */*
> Content-Length: 1765

| {"query":"\n    query IntrospectionQuery {\n      __schema {\n        queryType { name }\n        mutationType { name }\n        subscriptionType { name }\n        types {\n          ...FullType\n        }\n        directives {\n          name\n          description\n          locations\n          args {\n            ...InputValue\n          }\n        }\n      }\n    }\n\n    fragment FullType on __Type {\n      kind\n      name\n      description\n      fields(includeDeprecated: true) {\n        name\n        description\n        args {\n          ...InputValue\n        }\n        type {\n          ...TypeRef\n        }\n        isDeprecated\n        deprecationReason\n      }\n      inputFields {\n        ...InputValue\n      }\n      interfaces {\n        ...TypeRef\n      }\n      enumValues(includeDeprecated: true) {\n        name\n        description\n        isDeprecated\n        deprecationReason\n      }\n      possibleTypes {\n        ...TypeRef\n      }\n    }\n\n    fragment InputValue on __InputValue {\n      name\n      description\n      type { ...TypeRef }\n      defaultValue\n    }\n\n    fragment TypeRef on __Type {\n      kind\n      name\n      ofType {\n        kind\n        name\n        ofType {\n          kind\n          name\n          ofType {\n            kind\n            name\n            ofType {\n              kind\n              name\n              ofType {\n                kind\n                name\n                ofType {\n                  kind\n                  name\n                  ofType {\n                    kind\n                    name\n                  }\n                }\n              }\n            }\n          }\n        }\n      }\n    }\n  ","operationName":"IntrospectionQuery"}

* upload completely sent off: 1765 out of 1765 bytes

< HTTP/1.1 **500 Internal Server Error**
< Server: Cowboy
< Connection: keep-alive
< X-Powered-By: Express
< Access-Control-Allow-Origin: *
< Date: Mon, 20 May 2019 12:31:23 GMT
< Transfer-Encoding: chunked
< Via: 1.1 vegur


* Received 67 B chunk
* Received 5 B chunk
* Connection #2 to host countries.trevorblades.com left intact
@gschier
Copy link
Contributor

gschier commented May 20, 2019

However this value should always be application/json as that's how the IntrospectionQuery is formatted.

I agree that, ideally, this is true. However, I've seen GraphQL servers that accept JSON but still require the Content-Type application/graphql

To be noted: when I send GraphQL queries to my local/dev server, I usually use Content-Type: application/graphql but Insomnia fails to retrieve a schema too because the library handling the request (GraphQL Java) doesn't expect JSON in place of a pure GraphQL query.

Does this not cause an issue for sending regular queries as well, since Insomnia only supports sending GraphQL requests in JSON format? (ie. raw GraphQL query bodies are not supported)

@gschier gschier added the N-discussion Needs: Discussion label May 20, 2019
@gschier gschier changed the title Bug: Insomnia using wrong Content-Type header to send IntrospectionQuery (POST) [Discuss] Force GraphQL introspection queries to use different Content-Type May 20, 2019
@mxmlnglt
Copy link
Author

raw GraphQL query bodies are not supported

Ah. Didn't know that. In fact, I thought choosing GraphQL as "structured" type (vs "JSON" as "Text") would send the "application/graphql" Content-Type, which I noticed is not the case, after a round of testing (e.g. when creating a new request POST, or when changing the body type).

Also the reference for supporting the application/graphql is here: https://graphql.org/learn/serving-over-http/#post-request

If the "application/graphql" Content-Type header is present, treat the HTTP POST body contents as the GraphQL query string.

I know it's optional, but as soon as some backend libraries support it (as said in the text, express-graphql; but also GraphQL (Java) Servlet - although it's not clear in the README but I opened an issue for that: graphql-java-kickstart/graphql-java-servlet#186 - and probably some others...) I think why not supporting it.

However I also learned that in this case, variables should be sent in the URL (https://rs.http3.lol/index.php?q=aHR0cHM6Ly9naXRodWIuY29tL0tvbmcvaW5zb21uaWEvaXNzdWVzL3NlZSBsYXN0IGFuc3dlcg): https://stackoverflow.com/questions/43675933/in-graphql-can-i-send-variables-with-content-type-application-graphql

@mxmlnglt
Copy link
Author

Just been informed the GraphQL Java Servlet's README has been fixed: graphql-java-kickstart/graphql-java-servlet#186

@stale
Copy link

stale bot commented Jun 2, 2021

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the wontfix label Jun 2, 2021
@mxmlnglt
Copy link
Author

mxmlnglt commented Jun 3, 2021

@Stale stale bot added the wontfix label yesterday

hu ho? I still needs this...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants