Security News
tea.xyz Spam Plagues npm and RubyGems Package Registries
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
gatsby-node-helpers
Advanced tools
Changelog
Readme
Gatsby node helper functions to aid node creation. To be used when creating Gatsby source plugins.
contentDigest
npm install --save gatsby-node-helpers
Import the named module:
import { createNodeHelpers } from 'gatsby-node-helpers'
Then call createNodeHelpers
with options. You will need to pass functions
available in Gatsby's Node APIs, such as sourceNodes
and
createSchemaCustomization
.
The following example shows usage in gatsby-node.js
's sourceNodes
API, but
it can be used elsewhere provided the appropriate helper functions are
available.
// gatsby-node.ts
import * as gatsby from 'gatsby'
import { createNodeHelpers } from 'gatsby-node-helpers'
export const sourceNodes: gatsby.GatsbyNode['sourceNodes'] = async (
gatsbyArgs: gatsby.SourceNodesArgs,
pluginOptions: gatsby.PluginOptions,
) => {
const { createNodeId, createContentDigest } = gatsbyArgs
const nodeHelpers = createNodeHelpers({
typePrefix: 'Shopify',
createNodeId,
createContentDigest,
})
}
The result of createNodeHelpers
includes a factory function named
createNodeFactory
that should be used to prepare an object just before calling
Gatsby's createNode
.
The created function will automatically assign Gatsby's required fields, like
internal
and contentDigest
, while renaming any conflicting fields.
const nodeHelpers = createNodeHelpers({
typePrefix: 'Shopify',
createNodeId: gatsbyArgs.createNodeId,
createContentDigest: gatsbyArgs.createContentDigest,
})
const ProductNode = nodeHelpers.createNodeFactory('Product')
const ProductVariantNode = nodeHelpers.createNodeFactory('ProductVariant')
In the above example, we can now pass Product objects to ProductNode
to
prepare the object for Gatsby's createNode
.
// gatsby-node.ts
import * as gatsby from 'gatsby'
import { createNodeHelpers } from 'gatsby-node-helpers'
export const sourceNodes: gatsby.GatsbyNode['sourceNodes'] = async (
gatsbyArgs: gatsby.SourceNodesArgs,
pluginOptions: gatsby.PluginOptions,
) => {
const { actions, createNodeId, createContentDigest } = gatsbyArgs
const { createNodes } = actions
const nodeHelpers = createNodeHelpers({
typePrefix: 'Shopify',
createNodeId,
createContentDigest,
})
const ProductNode = nodeHelpers.createNodeFactory('Product')
const ProductVariantNode = nodeHelpers.createNodeFactory('ProductVariant')
// `getAllProducts` is an API function that returns all Shopify products.
const products = await getAllProducts()
for (const product of products) {
const node = ProductNode(product)
// `node` now contains all the fields required by `createNode`.
createNode(node)
}
}
All functions and types are documented in the source files using TSDoc to provide documentation directly in your editor.
If you editor does not have TSDoc integration, you can read all documentation by viewing the source files.
FAQs
Gatsby node helper functions to aid node creation.
The npm package gatsby-node-helpers receives a total of 16,978 weekly downloads. As such, gatsby-node-helpers popularity was classified as popular.
We found that gatsby-node-helpers demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.
Security News
UnitedHealth Group disclosed that the ransomware attack on Change Healthcare compromised protected health information for millions in the U.S., with estimated costs to the company expected to reach $1 billion.