13

I'm trying to test the GraphQL server I built, by sending GraphQL queries to the server using Postman.

It works when I'm using raw radio button, but when I'm trying to use GraphQL radio button, it returns "message": "Syntax Error: Expected Name, found String \"query\"".

I have tried to change the syntax: mainly add or delete curly braces but nothing happened.

The query I sent in raw mode (working):

{
    person(id:"123456789") {
        personal_info {
            address
        }
    }
} 

The query I sent in GraphQL mode:

QUERY:

query getPerson ($id: String){
    person(id: $id){
        personal_info {
            address
        }
    }
}

GRAPHQL VARIABLES:

{
    "id": "123456789"
}

I expect to get the data I asked for, but I get the error message:

{
    "errors": [
        {
            "message": "Syntax Error: Expected Name, found String \"query\"",
            "locations": [
                {
                    "line": 1,
                    "column": 2
                }
            ]
        }
    ]
}
n-verbitsky
  • 552
  • 2
  • 9
  • 20
liadperetz
  • 149
  • 1
  • 1
  • 5
  • try to replace: query getPerson ($id: String){...} by mutation getPerson ($id: String){...} – Nemer Aug 27 '19 at 23:22
  • the same occurred for me when query parameter type was changed from simple 'String' type to graphql 'input' type. **Restarting server did the trick – CodeWorld Oct 08 '21 at 12:53

1 Answers1

4

I had the same problem. During researching I have found the next answer on stackoverflow, thanks @gbenga_ps.

Resolved by adding the correct header to Postman request: Adding header Content-Type: application/json

Body of request should be something like next:

{
    courses {
        title
    }
}

Request example

If incorrect content-type set, error like next happened:

{
    "errors": [
        {
            "message": "Syntax Error: Expected Name, found String \"query\"",
            "locations": [
                {
                    "line": 1,
                    "column": 2
                }
            ]
        }
    ]
}

Error response example

n-verbitsky
  • 552
  • 2
  • 9
  • 20
Vaha
  • 2,179
  • 2
  • 17
  • 29