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

[1.0] Question: why can you use graphql in templates? #1143

Closed
rstacruz opened this issue Jun 11, 2017 · 6 comments
Closed

[1.0] Question: why can you use graphql in templates? #1143

rstacruz opened this issue Jun 11, 2017 · 6 comments
Labels
type: question or discussion Issue discussing or asking a question about Gatsby

Comments

@rstacruz
Copy link
Contributor

rstacruz commented Jun 11, 2017

The 1.0 boilerplate has this in template pages:

export const pageQuery = graphql`
  query MyQuery($slug: String!) {
    ..
  }
`

But linters will complain here:

'graphql' is not defined.

True enough, when you try to do see what graphql is, it's not defined:

console.log(graphql)
// => undefined

How does this sorcery work?

@jbolda jbolda added type: question or discussion Issue discussing or asking a question about Gatsby v1 labels Jun 11, 2017
@0x80
Copy link
Contributor

0x80 commented Jun 11, 2017

The sources are processed with Babylon in file-parser.js and the queries are extracted from the AST in query-compiler.js

@jquense
Copy link
Contributor

jquense commented Jun 11, 2017

yeah the down and dirty reason it works is that the queries are removed from the source code before they are run.

@KyleAMathews
Copy link
Contributor

Several people have asked about this — perhaps we just need to make sure this is covered in the tutorial + GraphQL docs so people aren't confused? I remember being confused for similar reasons back in the day when I first used Relay :-)

@bradennapier
Copy link

Seems like what you really need is an eslint plugin so people aren't having to make a bunch of comments or remove their linting to support Gatsby without a bunch of errors everywhere.

@jlengstorf
Copy link
Contributor

I just ran into this question while setting up ESLint, so I took a crack at expanding the tutorial to explain why this doesn't explode in #2965. Someone who understands this better should probably review pretty closely, though, because I only sorta get how this works. 😅

@KyleAMathews
Copy link
Contributor

Closing this as there's another issue about including a custom gatsby eslint plugin #2446 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: question or discussion Issue discussing or asking a question about Gatsby
Projects
None yet
Development

No branches or pull requests

7 participants