-
Notifications
You must be signed in to change notification settings - Fork 10.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
perf: implement shouldOnCreateNode for all our plugins
- Loading branch information
Showing
30 changed files
with
360 additions
and
200 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,57 +1,69 @@ | ||
const agility = require('./src/agility/utils') | ||
const agility = require("./src/agility/utils") | ||
const { createRemoteFileNode } = require("gatsby-source-filesystem") | ||
|
||
//gatsy-node.js | ||
//CREATE RESOLVERS ******************************************************************************************* | ||
exports.createResolvers = (args) => { | ||
const { | ||
createResolvers, | ||
getNode, | ||
createNodeId, | ||
createNode, | ||
createContentDigest, | ||
configOptions, | ||
} = args | ||
|
||
const { createResolvers, getNode, createNodeId, createNode, createContentDigest, configOptions } = args; | ||
const resolvers = { | ||
//on the 'agilityPost' node type... | ||
agilityPost: { | ||
//get the sitemap node that represents this item - useful for retrieving the URL for the item | ||
sitemapNode: agility.getDynamicPageItemSitemapNode(), | ||
|
||
const resolvers = { | ||
//on the 'agilityPost' node type... | ||
agilityPost: { | ||
//get the sitemap node that represents this item - useful for retrieving the URL for the item | ||
sitemapNode: agility.getDynamicPageItemSitemapNode(), | ||
//[Not Implemented] | ||
//if we had a linked content field for 'author', this is how we'd get the author for this post in a single GraphQl query | ||
//linkedContent_agilityAuthor: agility.getLinkedContentItem({ type: 'agilityAuthor', linkedContentFieldName: 'author' }) | ||
}, | ||
|
||
//[Not Implemented] | ||
//if we had a linked content field for 'author', this is how we'd get the author for this post in a single GraphQl query | ||
//linkedContent_agilityAuthor: agility.getLinkedContentItem({ type: 'agilityAuthor', linkedContentFieldName: 'author' }) | ||
}, | ||
//[Not Implemented] | ||
//if we had an 'Image Slider' module and it had a list of slides via a linked content field called 'slides', this is how we'd retrieve a list of those slides in a single GraphQL query | ||
// agilityImageSlider: { | ||
// linkedContent_agilitySlides: agility.getLinkedContentList({ type: 'agilitySlide', linkedContentFieldName: 'slides' }) | ||
// } | ||
} | ||
createResolvers(resolvers) | ||
} | ||
|
||
//[Not Implemented] | ||
//if we had an 'Image Slider' module and it had a list of slides via a linked content field called 'slides', this is how we'd retrieve a list of those slides in a single GraphQL query | ||
// agilityImageSlider: { | ||
// linkedContent_agilitySlides: agility.getLinkedContentList({ type: 'agilitySlide', linkedContentFieldName: 'slides' }) | ||
// } | ||
} | ||
createResolvers(resolvers) | ||
function unstable_shouldOnCreateNode({node}) { | ||
return ( | ||
node.properties && node.properties.referenceName.toLowerCase() === `posts` | ||
) | ||
} | ||
|
||
exports.unstable_shouldOnCreateNode = unstable_shouldOnCreateNode | ||
|
||
exports.onCreateNode = async ({ | ||
node, | ||
actions: { createNode }, | ||
store, | ||
cache, | ||
createNodeId, | ||
node, | ||
actions: { createNode }, | ||
store, | ||
cache, | ||
createNodeId, | ||
}) => { | ||
|
||
if (node.properties | ||
&& node.properties.referenceName.toLowerCase() === `posts`) { | ||
let field = "image" | ||
let imageUrl = node.customFields[field] | ||
if (imageUrl) { | ||
let fileNode = await createRemoteFileNode({ | ||
url: imageUrl, // string that points to the URL of the image | ||
parentNodeId: node.id, // id of the parent node of the fileNode you are going to create | ||
createNode, // helper function in gatsby-node to generate the node | ||
createNodeId, // helper function in gatsby-node to generate the node id | ||
cache, // Gatsby's cache | ||
store, // Gatsby's redux store | ||
}) | ||
// if the file was created, attach the new node to the parent node | ||
if (fileNode) { | ||
node.customFields[`${field}LocalImg___NODE`] = fileNode.id | ||
} | ||
} | ||
} | ||
} | ||
if (unstable_shouldOnCreateNode({node})) { | ||
let field = "image" | ||
let imageUrl = node.customFields[field] | ||
if (imageUrl) { | ||
let fileNode = await createRemoteFileNode({ | ||
url: imageUrl, // string that points to the URL of the image | ||
parentNodeId: node.id, // id of the parent node of the fileNode you are going to create | ||
createNode, // helper function in gatsby-node to generate the node | ||
createNodeId, // helper function in gatsby-node to generate the node id | ||
cache, // Gatsby's cache | ||
store, // Gatsby's redux store | ||
}) | ||
// if the file was created, attach the new node to the parent node | ||
if (fileNode) { | ||
node.customFields[`${field}LocalImg___NODE`] = fileNode.id | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.