11
votes

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
                }
            ]
        }
    ]
}
1
try to replace: query getPerson ($id: String){...} by mutation getPerson ($id: String){...}Nemer
the same occurred for me when query parameter type was changed from simple 'String' type to graphql 'input' type. **Restarting server did the trickCodeWorld

1 Answers

3
votes

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