Skip to content

GraphQLParser errors unhelpful #4888

@thekevinbrown

Description

@thekevinbrown

Description

While working on a site, we will sometimes create invalid GraphQL for various reasons. The current error message looks like this:

...
success createPagesStatefully — 0.130 s
success onPreExtractQueries — 0.001 s
success update schema — 0.415 s
GraphQL Error There was an error while compiling your site's GraphQL queries.
  GraphQLParser
    
success extract queries from components — 0.553 s
success run graphql queries — 0.171 s
...

Steps to reproduce

Repro: https://github.com/blargity/gatsby-graphql-error-demo

Create a GraphQL query that references a non-existent property, run gatsby build or gatsby develop.

Expected result

The error message should give me some level of information to go on here. Either the raw text of the query that could not be parsed, or the file it came from.

Actual result

Gatsby tells me there is a problem but gives me absolutely no information to go on to fix it. When I was working on a small site this was fine, but now with a large site and CMS it often takes a long time to track these errors down.

Environment

  • Gatsby version (npm list gatsby): [email protected]
  • gatsby-cli version (gatsby --version): Not in use, I use package.json scripts to run the embedded gatsby in the project's node_modules folder.
  • Node.js version: v8.9.4
  • Operating System: OS X 10.13.3

File contents (if changed):

Here's a repro case:
https://github.com/blargity/gatsby-graphql-error-demo

I took the standard gatsby starter then did these steps:

  • Removed Page 2 and the 404 page to simplify
  • Added gatsby-source-filesystem and gatsby-transformer-json
  • Added a query in index.js which is invalid. It tries to query a body field when none exists.

When you run gatsby develop:

$ gatsby develop
success delete html and css files from previous builds — 0.006 s
success open and validate gatsby-config.js — 0.005 s
success copy gatsby files — 0.017 s
success onPreBootstrap — 0.025 s
success source and transform nodes — 0.039 s
success building schema — 0.144 s
success createLayouts — 0.006 s
success createPages — 0.001 s
success createPagesStatefully — 0.011 s
success onPreExtractQueries — 0.000 s
success update schema — 0.090 s
GraphQL Error There was an error while compiling your site's GraphQL queries.
  GraphQLParser
    
success extract queries from components — 0.031 s
success run graphql queries — 0.011 s
success write out page data — 0.004 s
success write out redirect data — 0.001 s
success onPostBootstrap — 0.001 s

info bootstrap finished - 1.778 s

 DONE  Compiled successfully in 2171ms                                                                                                                                        15:25:50


You can now view gatsby-starter-default in the browser.

  http://localhost:8000/

View GraphiQL, an in-browser IDE, to explore your site's data and schema

  http://localhost:8000/___graphql

Note that the development build is not optimized.
To create a production build, use gatsby build

It'd be fantastic if this error message could be improved.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions