Skip to content

Commit

Permalink
[v2] Don't allow unknown keys on node.internal object (#5770)
Browse files Browse the repository at this point in the history
* [v2] Don't allow unknown fields on node.internal object

Validate against changes like #5557

* Document the change
  • Loading branch information
KyleAMathews authored and m-allanson committed Jun 7, 2018
1 parent 968c6d0 commit fb18fc1
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
6 changes: 6 additions & 0 deletions docs/docs/migrating-from-v1-to-v2.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ This is a reference for upgrading your site from Gatsby v1 to Gatsby v2. While t
- [Change `modifyBabelrc` to `onCreateBabelConfig`](#change-modifybabelrc-to-oncreatebabelconfig)
- [Change `modifyWebpackConfig` to `onCreateWebpackConfig`](#change-modifywebpackconfig-to-oncreatewebpackconfig)
- [Remove inlined CSS in `html.js`](#remove-inlined-css-in-htmljs)
- [Only allow defined keys on node.internal object](#only-allow-defined-keys-on-the-node-internal-object)

You can start with a few of the most important steps - install Gatsby v2 dependencies and update your layout components.

Expand Down Expand Up @@ -378,3 +379,8 @@ See [Gatsby's webpack docs for more details](/docs/add-custom-webpack-config) ab
Gatsby v2 automatically inlines CSS. You can remove any custom CSS inlining from your custom `html.js`.

See an example in [this PR that upgrades the `using-remark` site to Gatsby v2](https://github.com/gatsbyjs/gatsby/commit/765b679cbc222fd5f527690427ee431cca7ccd61#diff-637c76e3c059ed8efacedf6e30de2d61).

## Only allow defined keys on the node internal object

The node internal object isn't meant for adding node data. Those should be added to the top-level object. We
didn't document this in v1 nor validate against it but are now for v2.
20 changes: 11 additions & 9 deletions packages/gatsby/src/joi-schemas/joi.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,16 @@ export const nodeSchema = Joi.object()
`"parent" must be the "id" of another node or if there is no parent (common), "null"`
),
fields: Joi.object(),
internal: Joi.object().keys({
contentDigest: Joi.string().required(),
mediaType: Joi.string(),
type: Joi.string().required(),
owner: Joi.string().required(),
fieldOwners: Joi.array(),
content: Joi.string().allow(``),
description: Joi.string(),
}),
internal: Joi.object()
.keys({
contentDigest: Joi.string().required(),
mediaType: Joi.string(),
type: Joi.string().required(),
owner: Joi.string().required(),
fieldOwners: Joi.array(),
content: Joi.string().allow(``),
description: Joi.string(),
})
.unknown({ allow: false }), // Don't allow non-standard fields
})
.unknown()

0 comments on commit fb18fc1

Please sign in to comment.