GraphQL gql Syntax Error: Expected Name, found }
The accepted answer didn't solve my issue. Instead, it worked if you remove the initial curly brackets.
The query should look like this instead:
const query=gql`
user(id: 5) {
firstName
lastName
}
`
This error occurs mostly when there are unclosed curly braces or when some fields are not properly defined while calling the query.