Skip to content

Normalize reserved fields on nodes #14

@jessevdp

Description

@jessevdp

The content (fields) of a node are a combination of whatever is retrieved from the Umbraco API and Gatsby's node metadata. (With some slight modifications for file and FK fields.) But what happens when the name of a field fetched from the API collides with the name of a reserved Gatsby internal field?

Looking at the loadNode function in load-umbraco-nodes.js, the data is merged with the metadata object. I guess the metadata field will overwrite the one from the regular data. (See lines 31-34.)

async function loadNode(helpers, sitemapNode, parent) {
const { gatsby } = helpers
const data = await fetchDataForSitemapNode(helpers, sitemapNode)
const nodeMeta = createGatsbyNodeMeta(gatsby, data, sitemapNode, parent)
let fields = await loadRemoteFiles(helpers, data, nodeMeta)
fields = handleForeignKeyFields(helpers, fields)
const node = {
...fields,
...nodeMeta,
}
gatsby.actions.createNode(node)
registerType(node.internal.type)
if (parent) gatsby.actions.createParentChildLink({ parent, child: node })
return node
}

This is fine, honestly. As long as the developer working with it knows about what is happening and why.

I've seen other plugins replace the overlapping field name by appending some sort of _normalized suffix to it. That way the data will always show up.

It would probably be best to log a warning to the developer, indicating that the plugin encountered a duplicate/reserved field name and how it will handle it. That way the developer can choose to rename the field. (The warning would tell the developer what is happening and why 😄)

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions