Skip to content

Commit

Permalink
sanitize field owner key when using createNodeField with name contain…
Browse files Browse the repository at this point in the history
…ing ___NODE

this fixes issue with inferring fieldOwners types - gatsby would try to link to not existing nodes
  • Loading branch information
pieh committed Apr 19, 2018
1 parent d2290ef commit eea66e6
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions packages/gatsby/src/redux/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -748,8 +748,15 @@ actions.createNodeField = (
node.fields = {}
}

/**
* Normalized name of the field that will be used in schema
*/
const schemaFieldName = _.includes(name, `___NODE`)
? name.split(`___`)[0]
: name

// Check that this field isn't owned by another plugin.
const fieldOwner = node.internal.fieldOwners[name]
const fieldOwner = node.internal.fieldOwners[schemaFieldName]
if (fieldOwner && fieldOwner !== plugin.name) {
throw new Error(
stripIndent`
Expand All @@ -765,7 +772,7 @@ actions.createNodeField = (

// Update node
node.fields[name] = value
node.internal.fieldOwners[name] = plugin.name
node.internal.fieldOwners[schemaFieldName] = plugin.name

return {
type: `ADD_FIELD_TO_NODE`,
Expand Down

0 comments on commit eea66e6

Please sign in to comment.