Magento 2 GraphQL Syntax Error

Sometimes you get this error message from postman when running a GraphQL query on Magento 2

 "Syntax Error: Unexpected <EOF>",
{
    "errors": [
        {
            "message": "Syntax Error: Unexpected <EOF>",
            "extensions": {
                "category": "graphql"
            },
            "locations": [
                {
                    "line": 1,
                    "column": 1
                }
            ]
        }
    ]
}

In most cases the solution is the request has been sent as a GET request and no a POST request.

curl --location --request POST 'https://phoenix-magento.my127.site/graphql' \
--header 'Content-Type: application/json' \
--data-raw '{"query":"query {
  customerCart {
    id
    items {
      id
      product {
        name
        sku
      }
      quantity
    }
  }
}","variables":{}}'

 

Gareth
Buy Me A Coffee
back arrowBack to Index