Graphql-tag: Bad syntax throws 'ReferenceError: gql is not defined'

Created on 2 Feb 2018  Â·  3Comments  Â·  Source: apollographql/graphql-tag

This code:

import gql from 'graphql-tag'

const query = gql`
    query ViewerQuery() {
        viewer() {
            id
            displayName
            username
        }
    }
`

Throws the error Uncaught ReferenceError: gql is not defined. Which is a little baffling because it's clearly imported two lines above, the same way it is in other files:

image

When I fix the syntax of the query by removing the parentheses, everything works as expected.

    query ViewerQuery {
        viewer {
                         ....

Version: 2.6.1

Most helpful comment

@jnwng I wasn't very clear in my initial post - The issue as I see it is that the error is confusing & misleading. Throwing some kind of "Error: Invalid GraphQL syntax" would be helpful.

All 3 comments

having empty parentheses there is invalid GraphQL syntax and _might_ be why the import isn't working, but i think there might be a couple of issues here. closing for now — please re-open if you think that there's something wrong with this library.

@jnwng the same problem...

@jnwng I wasn't very clear in my initial post - The issue as I see it is that the error is confusing & misleading. Throwing some kind of "Error: Invalid GraphQL syntax" would be helpful.

Was this page helpful?
0 / 5 - 0 ratings