Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GraphQLParser errors unhelpful #4888

Closed
thekevinbrown opened this issue Apr 8, 2018 · 2 comments · Fixed by #4889
Closed

GraphQLParser errors unhelpful #4888

thekevinbrown opened this issue Apr 8, 2018 · 2 comments · Fixed by #4889
Assignees

Comments

@thekevinbrown
Copy link
Contributor

thekevinbrown commented Apr 8, 2018

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): gatsby@1.9.246
  • 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.

@jquense
Copy link
Contributor

jquense commented Apr 8, 2018

Thanks for reproduction, it'll help a lot. I'm suprised there is still a vague one like this somewhere, generally we do show the file, query and the exact line that's wrong and why. We must of missed a place so the repro is helpful!

@pieh
Copy link
Contributor

pieh commented Apr 8, 2018

This seems to be regression after #4618 it added capturing parenthesis but didn't adjust indices later used for passing error messages. Will submit PR with fix soonish

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants