Skip to content

Commit

Permalink
Add pluginOptions as second callback param. Add note about api.
Browse files Browse the repository at this point in the history
  • Loading branch information
pvdz committed Oct 16, 2020
1 parent b91528c commit 823afb9
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
4 changes: 3 additions & 1 deletion packages/gatsby/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -309,9 +309,11 @@ export interface GatsbyNode {
/**
* Called before scheduling a `onCreateNode` callback for a plugin. If it returns falsy
* then Gatsby will not schedule the `onCreateNode` callback for this node for this plugin.
* Note: this API does not receive the regular `api` that other callbacks get as first arg.
*
* @gatsbyVersion 2.24.79
* @example
* exports.shouldOnCreateNode = node => node.internal.type === 'SharpNode'
* exports.shouldOnCreateNode = (node, pluginOptions) => node.internal.type === 'Image'
*/
shouldOnCreateNode?<TNode extends object = {}>(
node: TNode,
Expand Down
8 changes: 4 additions & 4 deletions packages/gatsby/src/utils/api-node-docs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,13 +134,13 @@ export const sourceNodes = true
export const onCreateNode = true

/**
* Called when a new node is created before the `onCreateNode` handler is called.
* This is an optimization that can prevent the `onCreateNode` handler to be scheduled
* if the plugin already knows it's not interested in processing this node.
* Called before scheduling a `onCreateNode` callback for a plugin. If it returns falsy
* then Gatsby will not schedule the `onCreateNode` callback for this node for this plugin.
* Note: this API does not receive the regular `api` that other callbacks get as first arg.
*
* @gatsbyVersion 2.24.79
* @example
* exports.shouldOnCreateNode = (node) => node.internal.type === 'Image'
* exports.shouldOnCreateNode = (node, pluginOptions) => node.internal.type === 'Image'
*/
export const shouldOnCreateNode = true

Expand Down
2 changes: 1 addition & 1 deletion packages/gatsby/src/utils/api-runner-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -540,7 +540,7 @@ module.exports = async (api, args = {}, { pluginSource, activity } = {}) =>
if (
api === `onCreateNode` &&
gatsbyNode?.shouldOnCreateNode && // Don't bail if this api is not exported
!gatsbyNode.shouldOnCreateNode(args.node)
!gatsbyNode.shouldOnCreateNode(args.node, plugin.pluginOptions)
) {
// Do not try to schedule an async event for this node for this plugin
return null
Expand Down

0 comments on commit 823afb9

Please sign in to comment.