Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GraphQL gql Syntax Error: Expected Name, found }

I'm attempting to set up Apollo GraphQL support in a new React project, but when I try to compile a query using gql I keep receiving the error:

Syntax Error: Expected Name, found }

This is generated by the following code:

import gql from 'graphql-tag'  const query = gql`     {       user(id: 5) {         firstName         lastName       }     }   `  console.log(query) 

I'm basing this code off the example code found here: https://github.com/apollographql/graphql-tag

What is the Name referred to in the error message? Does anyone know what I'm doing wrong here?

like image 422
Nathan Avatar asked Jan 18 '18 22:01

Nathan


People also ask

What is ID in GraphQL?

ID : The ID scalar type represents a unique identifier, often used to refetch an object or as the key for a cache. The ID type is serialized in the same way as a String; however, defining it as an ID signifies that it is not intended to be human‐readable.


1 Answers

This error occurs mostly when there are unclosed curly braces or when some fields are not properly defined while calling the query.

like image 193
Razi Abdul Rasheed Avatar answered Oct 05 '22 22:10

Razi Abdul Rasheed