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

fix(gatsby-source-contentful): fix structured content fields #9768

Merged
merged 1 commit into from Nov 8, 2018

Conversation

macklinu
Copy link
Contributor

@macklinu macklinu commented Nov 7, 2018

This PR fixes an issue with gatsby-source-contentful where the internal prepareStructuredTextNode() was trying to call an undefined function.

You can see here that the function defines 5 expected arguments:

function prepareStructuredTextNode(
node,
key,
content,
createNode,
createNodeId
) {
const str = JSON.stringify(content)
const structuredTextNode = {
...content,
id: createNodeId(`${node.id}${key}RichTextNode`),
parent: node.id,
children: [],
[key]: str,
internal: {
type: _.camelCase(`${node.internal.type} ${key} RichTextNode`),
mediaType: `text/richtext`,
content: str,
contentDigest: digest(str),
},
}
node.children = node.children.concat([structuredTextNode.id])
return structuredTextNode
}

The 4th argument is createNode (which is unused). And the only usage I could find of this function receives 4 arguments (with createNodeId being the last argument):

const richTextNode = prepareStructuredTextNode(
entryNode,
entryItemFieldKey,
entryItemFields[entryItemFieldKey],
createNodeId
)

@macklinu
Copy link
Contributor Author

macklinu commented Nov 7, 2018

I'm working with Rich Text nodes in a Contentful space, and there isn't a unit test for this currently that I can tell in the normalize.js file, so I'm testing changes locally now. Will push up another commit or comment if something isn't working with this PR.

@macklinu
Copy link
Contributor Author

macklinu commented Nov 7, 2018

Confirmed by modifying the gatsby-source-contentful package in my project's node_modules directory by removing the createNode argument, and I am now seeing my rich text models in the GraphQL inspector after running gatsby develop. 👍

image

@pieh pieh changed the title fix(source-contentful): fix argument arity fix(gatsby-source-contentful): fix structured content fields Nov 8, 2018
Copy link
Contributor

@pieh pieh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh yeah! Thanks for the fix @macklinu!

@pieh pieh merged commit b7992fb into master Nov 8, 2018
@pieh pieh deleted the macklinu/fix-createNodeId branch November 8, 2018 01:23
gpetrioli pushed a commit to gpetrioli/gatsby that referenced this pull request Jan 22, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants