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

[v2][tutorial] Add importing graphql function #6092

Merged
merged 5 commits into from
Jun 28, 2018
Merged

[v2][tutorial] Add importing graphql function #6092

merged 5 commits into from
Jun 28, 2018

Conversation

ryanditjia
Copy link
Contributor

Closes #6055.

@gatsbybot
Copy link
Collaborator

Deploy preview for using-drupal ready!

Built with commit c35f6d8

https://deploy-preview-6092--using-drupal.netlify.com

@gatsbybot
Copy link
Collaborator

Deploy preview for gatsbygram ready!

Built with commit c35f6d8

https://deploy-preview-6092--gatsbygram.netlify.com

m-allanson
m-allanson previously approved these changes Jun 22, 2018
Copy link
Contributor

@m-allanson m-allanson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🙏 thanks!

Copy link
Contributor

@m-allanson m-allanson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've been thinking about this over the weekend and have added a comment on the removed graphql tag question.

@@ -346,28 +347,6 @@ So almost everywhere, changes you make will immediately take effect.
Try editing the title in `siteMetadata`—change the title back to "Pandas Eating
Lots". The change should show up very quickly in your browser.

## Wait — where did the graphql tag come from?
Copy link
Contributor

@m-allanson m-allanson Jun 25, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've held off on merging this as I'm wondering what to do about this section. It's great that we don't have to explain how the graphql tag works without being imported. BUT this is still working in the same way behind the scenes. So I wonder if a simplified version of this question and answer should stay in the tutorial?

Maybe something like:

How does the graphql tag work?

You may have noticed that you used a tag function called graphql. Behind the scenes Gatsby handles these tags in a particular way - let's explore what actually happens when you use Gatsby's graphql tag:

The short answer is this: during the Gatsby build process, GraphQL queries are
pulled out of the original source for parsing.

The longer answer is a little more involved: Gatsby borrows a technique from
Relay that converts your source code into an abstract syntax tree (AST) during the build step. file-parser.js and query-compiler.js pick out your graphql-tagged templates and effectively remove them from the original source code.

This means that the graphql tag isn’t executed the way that you might expect.
For example, you cannot use expression interpolation with Gatsby's graphql tag.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cc @KyleAMathews for thoughts on this too.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the sort of "optional" content that could fit well in a note or callout component (#5612)

@m-allanson m-allanson dismissed their stale review June 25, 2018 09:50

I had another thought about this PR

Copy link
Contributor

@pieh pieh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @ryanditjia and @m-allanson ! ❤️

@pieh pieh merged commit 1b457b6 into gatsbyjs:master Jun 28, 2018
@ryanditjia ryanditjia deleted the tutorial-import-graphql branch July 30, 2018 09:06
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 this pull request may close these issues.

4 participants