Page MenuHomePhabricator

Only accept JSON content type requests
Closed, ResolvedPublic

Description

The correct content type for GraphQL requests is application/graphql-response+json or application/json. Action API users may be used to sending multipart/form-data data requests which currently results in a confusing error.

Example curl request:

curl --request POST \
  --url 'http://default.mediawiki.local.wmftest.net:8080/w/api.php?action=wbgraphql&format=json' \
  --header 'content-type: multipart/form-data' \
  --form 'query={ __typename }'

This currently results in the following response:

{
  "warnings": {
    "main": {
      "*": "Unrecognized parameter: query."
    }
  },
  "errors": [
    {
      "message": "The 'query' field is required and must not be empty"
    }
  ]
}

Instead, the error response should be as follows, without the warning message:

{
  "errors": {
    "message": ["Requests must be sent as 'application/json' or 'application/graphql-response+json' "]
  }
}

Event Timeline

Change #1246906 had a related patch set uploaded (by Dima koushha; author: Dima koushha):

[mediawiki/extensions/Wikibase@master] GQL: Add check to only accept JSON content type requests

https://gerrit.wikimedia.org/r/1246906

Change #1246906 merged by jenkins-bot:

[mediawiki/extensions/Wikibase@master] GQL: Add check to only accept JSON content type requests

https://gerrit.wikimedia.org/r/1246906

Change #1247058 had a related patch set uploaded (by Dima koushha; author: Dima koushha):

[mediawiki/extensions/Wikibase@master] GQL: Correct content-type check to just accept `application/json'

https://gerrit.wikimedia.org/r/1247058

Change #1247058 merged by jenkins-bot:

[mediawiki/extensions/Wikibase@master] GQL: Correct content-type check to just accept `application/json'

https://gerrit.wikimedia.org/r/1247058