-
Notifications
You must be signed in to change notification settings - Fork 10.3k
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
behind the scenes docs #7510
behind the scenes docs #7510
Conversation
Was causing gatsby build to freeze on createPages
Was causing gatsby build to freeze on createPages
Closing this PR as I've updated the docs significantly. Will reopen when they're pushed. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Woah this is great stuff @Moocar!
I started reviewing this but tbh it's mainly nitpicking. It probably makes more sense to merge this in, then followup with any changes if that sounds good to you?
docs/docs/behind-the-scenes.md
Outdated
title: Behind the Scenes | ||
--- | ||
|
||
Curious how Gatsby works under the hood? This pages in this section describe how a Gatsby build works from an internal code/architecture point of view. It should be useful for anyone who needs to work on the internals of Gatsby, or for those who are simply curious how it all works, or perhaps you're a plugin author and need to understand how core works to track down a bug? Come one, come all! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Typo
- This pages in this section
+ The pages in this section
|
||
During the schema generation phase, we must generate what's called a `ProcessedNodeType` in Gatsby. This is a simple structure that builds on top of a [graphql-js GraphQLObjectType](https://graphql.org/graphql-js/type/#graphqlobjecttype). Our goal in the below steps is to infer and construct this object for each unique node type in redux. | ||
|
||
The flow is summarized by the below graph. It shows the intermediate transformations that are performed by code in the Gatsby [schema folder](https://github.com/gatsbyjs/gatsby/tree/master/packages/gatsby/src/schema), finally resulting in the [ProcessedNoteType](https://github.com/gatsbyjs/gatsby/blob/master/packages/gatsby/src/schema/build-node-types.js#L182). It uses the example of building a `File` GraphQL type. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Typo
- resulting in the [ProcessedNoteType]
+ resulting in the [ProcessedNodeType]
"resolve" [ label = "ProcessedNodeType.resolve()", shape = box ]; | ||
"gqlType" [ label = "gqlType (GraphQLObjectType)\l{\l fields,\l name: `File`\l}\l ", shape = box ]; | ||
"parentChild" [ label = "Parent/Children fields\lnode {\l childMarkdownRemark { html }\l parent { id }\l}\l ", shape = "box" ]; | ||
"objectFields" [ label = "Object node fields\l node {\l relativePath,\l accessTime }\l }\l ", shape = "box" ]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
digraph graphname { | ||
"pluginFields" [ label = "custom plugin fields\l{\l publicURL: {\l type: GraphQLString,\l resolve(file, a, c) { ... }\l }\l}\l ", shape = box ]; | ||
"typeNodes" [ label = "all redux nodes of type\le.g internal.type === `File`", shape = "box" ]; | ||
"exampleValue" [ label = "exampleValue\l{\l relativePath: `bogs/my-blog.md`,\l accessTime: 8292387234\l}\l ", shape = "box" ]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
less bogs, more blogs :)
- relativePath: `bogs/my
+ relativePath: `blogs/my
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My favorite typo
|
||
#### 2. Create a "GQLType" | ||
|
||
This step is quite complex, but at its most basic, it infers GraphQL Fields by constructing an `exampleObject` that merges all fields of the type in Redux. It uses this to infer all possible fields and their types, and construct GraphQL versions of them. It does the same for fields created by plugins (like in step 2). This step is explained in detail in [GraphQL Node Types Creation](/docs/schema-gql-type). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
update step number?
- (like in step 2)
+ (like in step 1)
docs/docs/schema-gql-type.md
Outdated
|
||
#### Foreign Key reference (`___NODE`) | ||
|
||
If not a mapping field, it might instead end in `___NODE`, signifying that its value is an ID that is a foreign key reference to another node in redux. Check out the [Create a Source Plugin](/docs/create-source-plugin/#create-source-plugin) for how this works from a user point of view. Behind the scenes, the field inference is handled by [inferFromFieldName](https://github.com/gatsbyjs/gatsby/blob/master/packages/gatsby/src/schema/infer-graphql-type.js#L204). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+ Check out the [Create a Source Plugin]
- Check out [Create a Source Plugin]
docs/docs/schema-gql-type.md
Outdated
} | ||
``` | ||
|
||
To resolve `file.childMarkdownRemark`, we filter over all the node's (that we're resolving) `children`, until we find one of type `markdownRemark`, which is returned. Remember that in redux, `children` is a collection of IDs. So as part of this, we lookup the node by ID in redux too. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- all the node's
+ all the nodes
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this one is correct as is, but the brackets between node's
and children
confuse it. I'll rearrange the sentence.
docs/docs/schema-gql-type.md
Outdated
|
||
#### parent field | ||
|
||
When a node is created as a child of some node, that fact is stored as a `parent` field on the redux node whose value is the ID of the parent. The parent GraphQL field resolver simply looks up the resolving node's `parent` field, and then looks up the parent in the redux `nodes` namespace map. It also creates a [page dependency](TODO have this in own section), as is done by child resolvers. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I found this paragraph quite confusing. I understood it as the parent
field is added to the parent node, which doesn't seem right?
docs/docs/schema-sift.md
Outdated
|
||
- field key is`elemMatch`? Change to `$elemMatch`. Recurse on value object | ||
- field value is regex? Apply regex cleaning | ||
- field value is globl, use [minimatch](https://www.npmjs.com/package/minimatch) library to convert to Regex |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- globl
+ glob
docs/docs/schema-sift.md
Outdated
|
||
The `resolve()` function calls `run-sift.js`, and provides it with the following arguments: | ||
|
||
- GraphQLArgs (as js object). Within a filter. E.g `wordcount: { paragraphs: { eg: 4 } }` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's a few eg's instead of eq's following this:
- eg: 4
+ eq: 4
@m-allanson Sounds good! Yeah, reviewing 1300+ lines of documentation is no easy feat. Thanks for the initial pass. I agree we should just merge it and fix typos/clarifications etc on the fly. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👌
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Per earlier conversation, I'll 👍 this so you can merge when you're ready @Moocar
@calcsam Thanks :). But looks like I might need elevated privileges to merge it. |
🎉 ❤️ |
I found myself having to relearn how the guts of Gatsby work every time I make a change. So I created some docs to stop myself having to learn from scratch each time.
I'm sure some of it could be moved into other parts of the docs (e.g
___NODE
andfrontmatter___date
). But most isn't important for regular users. Just those looking to learn about how Gatsby works behind the scenes.I've linked in quite a few places to lines of code on Github. I'm 50/50 on this approach. It's great to link from high level descriptions of the code straight to the code itself, but I'm worried these links will become stale. Open to suggestions here.
Lots more to document, but it's a start. Hopefully others knowledgeable with the code base can add to it over time.
I've also used the new gatsby-remark-graphviz to display graphs, which has the benefit of being able to source control graphs via a language vs an image drawing application.