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

add first draft of API Lifecycle docs #6229

Merged
merged 5 commits into from
Jul 4, 2018
Merged

Conversation

tsiq-swyx
Copy link
Contributor

closes #6197

@gatsbybot
Copy link
Collaborator

gatsbybot commented Jun 29, 2018

Deploy preview for using-drupal ready!

Built with commit 1cb7ba7

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

@gatsbybot
Copy link
Collaborator

gatsbybot commented Jun 29, 2018

Deploy preview for gatsbygram ready!

Built with commit 1cb7ba7

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

@m-allanson
Copy link
Contributor

👍 I'm going to try pointing this at master instead.

@m-allanson m-allanson changed the base branch from v1 to master June 29, 2018 15:00
m-allanson
m-allanson previously approved these changes Jun 29, 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.

LGTM, thanks @tsiq-swyx 👍

Copy link
Contributor

@KyleAMathews KyleAMathews left a comment

Choose a reason for hiding this comment

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

Great start! This will be a fantastic resource once it's done!

- extracts, runs, and replaces graphql queries for pages and `StaticQuery`s
- writes out the pages to cache

In development this is a running process powered by [Webpack](https://github.com/gatsbyjs/gatsby/blob/dd91b8dceb3b8a20820b15acae36529799217ae4/packages/gatsby/package.json#L128) and [react-hot-loader](https://github.com/gatsbyjs/gatsby/blob/dd91b8dceb3b8a20820b15acae36529799217ae4/packages/gatsby/package.json#L104), so changes to any files get re-run through the sequence again, with smart cache invalidation.
Copy link
Contributor

Choose a reason for hiding this comment

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

We should also mention that source plugins like gatsby-source-filesystem can also be watching files for changes which can trigger re-running queries. Also that queries are watched so if you modify a query it's reloaded.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

sure thing. i dont know this part very well myself haha


In development this is a running process powered by [Webpack](https://github.com/gatsbyjs/gatsby/blob/dd91b8dceb3b8a20820b15acae36529799217ae4/packages/gatsby/package.json#L128) and [react-hot-loader](https://github.com/gatsbyjs/gatsby/blob/dd91b8dceb3b8a20820b15acae36529799217ae4/packages/gatsby/package.json#L104), so changes to any files get re-run through the sequence again, with smart cache invalidation.

The core of the bootstrap process is the "api-runner", which helps to execute APIs in sequence, with state managed in Redux. Gatsby exposes a number of lifecycle APIs which can either be implemented by you or any of your provided plugins in `gatsby-node.js`, `gatsby-browser.js` or `gatsby-ssr.js`. **The sequence of your plugins matter**, so if the output of one plugin depends on another you should be sure to reflect this in `gatsby-config.js`.
Copy link
Contributor

Choose a reason for hiding this comment

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

The sequence of plugins should not matter. If they do, it's a bug. Plugins shouldn't ever depend on each other. If they do, there should be an explicit hierarchal relationship between the plugins e.g. gatsby-transformer-remark and its family of gatsby-remark-* plugins.

Copy link
Contributor Author

@tsiq-swyx tsiq-swyx Jun 29, 2018

Choose a reason for hiding this comment

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

I mean.. respectfully... these two conflict:

Plugins shouldn't ever depend on each other.

If they do, *

which is it? "shouldn't ever" or "usually dont"?

edit: i later realize what you meant by "explicit hierarchical relationship"... but leaving my confusion here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

i realize this can touch on some unresolved questions in gatsby itself - im happy to simply omit the sentence. but i just wrote that based on what i saw in the issues, just trying to help not misinform.

Copy link
Contributor

Choose a reason for hiding this comment

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

By design it's very hard but not impossible for plugins to depend on each other. So occasionally there can be implicit dependencies but these should be treated as bugs and fixed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

hmm: example to maybe motivate discussion #5196 (comment)


The sequence of the **main** bootstrap Node API lifecycles are:

- [onPreBootstrap](https://www.gatsbyjs.org/docs/node-apis/#onPreBootstrap) eg implemented by [gatsby-plugin-typography](https://github.com/gatsbyjs/gatsby/blob/06e4fccb1abc32ba29e878bb3de303afac390e4a/packages/gatsby-plugin-typography/src/gatsby-node.js)
Copy link
Contributor

Choose a reason for hiding this comment

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

eg should be e.g.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

The sequence of the **main** bootstrap Node API lifecycles are:

- [onPreBootstrap](https://www.gatsbyjs.org/docs/node-apis/#onPreBootstrap) eg implemented by [gatsby-plugin-typography](https://github.com/gatsbyjs/gatsby/blob/06e4fccb1abc32ba29e878bb3de303afac390e4a/packages/gatsby-plugin-typography/src/gatsby-node.js)
- [sourceNodes](https://www.gatsbyjs.org/docs/node-apis/#sourceNodes) eg implemented by [gatsby-source-wikipedia](https://github.com/gatsbyjs/gatsby/blob/1fb19f9ad16618acdac7eda33d295d8ceba7f393/packages/gatsby-source-wikipedia/src/gatsby-node.js)
Copy link
Contributor

Choose a reason for hiding this comment

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

Please link to the master version of packages

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@tsiq-swyx
Copy link
Contributor Author

ok thanks! i pointed at v1 cos the pull request template said docs go to v1.. is that not accurate?

@KyleAMathews
Copy link
Contributor

v1 would be fine but since you created your branch from master, the PR won't work. Pointing at master is fine too as we can just cherry-pick the PR back to v1.

I hope this is right...
@tsiq-swyx
Copy link
Contributor Author

by the way i'm totally ready to trash this PR because my brain wasn't functioning well yesterday. we still have the content, it'd be easy to just cut and paste. just tell me what to do @m-allanson

@shannonbux
Copy link
Contributor

Just left a couple comments. I'm not able to give feedback on accuracy, mostly just on clarity!

@swyxio
Copy link
Contributor

swyxio commented Jun 30, 2018

hi Shannon, thanks for that! where did you leave the comments? cos i don't see them here?

@m-allanson
Copy link
Contributor

by the way i'm totally ready to trash this PR

@sw-yx no need to trash the PR unless you're unhappy with it? We can keep iterating here and merge once it's 👍. Commits will be squashed to one as part of the merge.

@swyxio
Copy link
Contributor

swyxio commented Jul 3, 2018

ok sure @m-allanson. may I ask what else has to be edited? I addressed your and Kyles comments, haven't seen Shannon's yet

@m-allanson
Copy link
Contributor

may I ask what else has to be edited?

I think we just need to find out where Shannon's comments went. @shannonbux it looks like your comments didn't show up? Can you add again?

@pieh
Copy link
Contributor

pieh commented Jul 3, 2018

inline comments not showing up on github can happen if person started review and didn't finish it (something like commit review :) ) - happened to me once or twice

- writes out the pages to cache

In development this is a running process powered by [Webpack](https://github.com/gatsbyjs/gatsby/blob/dd91b8dceb3b8a20820b15acae36529799217ae4/packages/gatsby/package.json#L128) and [react-hot-loader](https://github.com/gatsbyjs/gatsby/blob/dd91b8dceb3b8a20820b15acae36529799217ae4/packages/gatsby/package.json#L104), so changes to any files get re-run through the sequence again, with [smart cache invalidation](https://github.com/gatsbyjs/gatsby/blob/ffd8b2d691c995c760fe380769852bcdb26a2278/packages/gatsby/src/bootstrap/index.js#L141). In particular, source plugins like gatsby-source-filesystem can also be watching files for changes which can trigger re-running queries. Queries are also watched so if you modify a query your development environment is reloaded.

Copy link
Contributor

Choose a reason for hiding this comment

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

it says that "source plugins like gatsby-source-filesystem can watch files for changes which can trigger re-running queries." The can words make it sound like source re-running queries only gets triggered sometimes. Is that true? If so, how would I know which file changes would trigger re-running queries?

Copy link
Contributor

Choose a reason for hiding this comment

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

Also it seems like our documentation so far always uses bacticks for names of plugins and packages, like gatsby-source-filesystem

Copy link
Contributor

Choose a reason for hiding this comment

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

The can words make it sound like source re-running queries only gets triggered sometimes.

ah well I mean it really depends on what plugins you have. I think what the phrase is trying to express is that if you have a plugin like gatsby-source-filesystem it -will- watch the files for changes, but if you have other plugins it might not. so its deterministic based on the plugin, but its not like we're not gonna know what plugins you have. how best to express this? I don't know. personally from working with Gatsby enough I don't even feel like this is an important detail, I just always assume the queries re-run.

Copy link
Contributor

Choose a reason for hiding this comment

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

always uses backticks

ok sure. I will address this once we finalize the other comment, didn't want GitHub to swallow it while its still unaddressed

@shannonbux
Copy link
Contributor

Yes, thanks everyone for your patience! Turns out I just didn't click "submit review." GitHub did save my comments though, so I didn't have to rewrite them 👍

@shannonbux
Copy link
Contributor

shannonbux commented Jul 3, 2018 via email

@swyxio
Copy link
Contributor

swyxio commented Jul 3, 2018

Meant the latter. wow, words are hard 😂 . Ok I like including that sentence.

address Shannon's comments
@swyxio
Copy link
Contributor

swyxio commented Jul 3, 2018

Done! @m-allanson

@shannonbux
Copy link
Contributor

shannonbux commented Jul 3, 2018 via email

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.

Alright, this is going in! Thanks @tsiq-swyx 👍

@m-allanson m-allanson merged commit 0986a67 into gatsbyjs:master Jul 4, 2018
m-allanson pushed a commit that referenced this pull request Jul 4, 2018
* first attempt at lifecycle sequence docs

closes #6197

* address Kyle's review

I hope this is right...

* address Shannon's comments

address Shannon's comments
@m-allanson
Copy link
Contributor

Cherry-picked to v1

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.

[docs] add Lifecycle Sequence, and then Diagrams
7 participants