Skip to content
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

refactor(gatsby): update gatsby-source-faker to use createContentDigest helper #11214

Merged
merged 3 commits into from
Jan 31, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/gatsby-source-faker/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"license": "MIT",
"main": "index.js",
"peerDependencies": {
"gatsby": ">2.0.0-alpha"
"gatsby": "^2.0.15"
},
"repository": "https://github.com/gatsbyjs/gatsby/tree/master/packages/gatsby-source-faker",
"scripts": {
Expand Down
12 changes: 5 additions & 7 deletions packages/gatsby-source-faker/src/gatsby-node.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
const faker = require(`faker`)
const crypto = require(`crypto`)

exports.sourceNodes = ({ actions, createNodeId }, pluginOptions) => {
exports.sourceNodes = (
{ actions, createNodeId, createContentDigest },
pluginOptions
) => {
const { createNode } = actions
const { schema, count, type } = pluginOptions
for (let i = 0; i < count; i++) {
Expand All @@ -14,18 +16,14 @@ exports.sourceNodes = ({ actions, createNodeId }, pluginOptions) => {
item[schemaKey][schemaItem] = faker[schemaKey][schemaItem]()
})
})
const contentDigest = crypto
.createHash(`md5`)
.update(JSON.stringify(item))
.digest(`hex`)

const nodeBase = {
id: createNodeId(JSON.stringify(faker.random.number())),
parent: null,
children: [],
internal: {
type,
contentDigest,
contentDigest: createContentDigest(item),
},
}
createNode(Object.assign({}, nodeBase, item))
Expand Down