Skip to content

Commit

Permalink
BREAKING(gatsby-transformer-yaml): Prefix id and only use createNod…
Browse files Browse the repository at this point in the history
…eId (gatsbyjs#28943)

Co-authored-by: LekoArts <lekoarts@gmail.com>
  • Loading branch information
2 people authored and wardpeet committed Oct 29, 2021
1 parent 6a0c22f commit e58b594
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 14 deletions.
6 changes: 6 additions & 0 deletions packages/gatsby-transformer-yaml/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -238,3 +238,9 @@ module.exports = {
}
}
```

## Troubleshooting

### `id` and `yamlId` key

If your data contains an `id` key the transformer will automatically convert this key to `yamlId` as `id` is a reserved internal keyword for Gatsby.
Original file line number Diff line number Diff line change
Expand Up @@ -313,12 +313,13 @@ Array [
"blue": true,
"children": Array [],
"funny": "yup",
"id": "some",
"id": "uuid-from-gatsby",
"internal": Object {
"contentDigest": "contentDigest",
"type": "FooBarYaml",
},
"parent": "whatever",
"yamlId": "some",
},
],
]
Expand All @@ -332,12 +333,13 @@ Array [
"blue": true,
"children": Array [],
"funny": "yup",
"id": "some",
"id": "uuid-from-gatsby",
"internal": Object {
"contentDigest": "contentDigest",
"type": "FooBarYaml",
},
"parent": "whatever",
"yamlId": "some",
},
"parent": Object {
"children": Array [],
Expand Down Expand Up @@ -368,12 +370,13 @@ Array [
"blue": true,
"children": Array [],
"funny": "yup",
"id": "some",
"id": "uuid-from-gatsby",
"internal": Object {
"contentDigest": "contentDigest",
"type": "fixed",
},
"parent": "whatever",
"yamlId": "some",
},
],
]
Expand All @@ -387,12 +390,13 @@ Array [
"blue": true,
"children": Array [],
"funny": "yup",
"id": "some",
"id": "uuid-from-gatsby",
"internal": Object {
"contentDigest": "contentDigest",
"type": "fixed",
},
"parent": "whatever",
"yamlId": "some",
},
"parent": Object {
"children": Array [],
Expand Down Expand Up @@ -423,12 +427,13 @@ Array [
"blue": true,
"children": Array [],
"funny": "yup",
"id": "some",
"id": "uuid-from-gatsby",
"internal": Object {
"contentDigest": "contentDigest",
"type": "yup",
},
"parent": "whatever",
"yamlId": "some",
},
],
]
Expand All @@ -442,12 +447,13 @@ Array [
"blue": true,
"children": Array [],
"funny": "yup",
"id": "some",
"id": "uuid-from-gatsby",
"internal": Object {
"contentDigest": "contentDigest",
"type": "yup",
},
"parent": "whatever",
"yamlId": "some",
},
"parent": Object {
"children": Array [],
Expand Down Expand Up @@ -772,12 +778,13 @@ Array [
"blue": true,
"children": Array [],
"funny": "yup",
"id": "some",
"id": "uuid-from-gatsby",
"internal": Object {
"contentDigest": "contentDigest",
"type": "OtherYaml",
},
"parent": "whatever",
"yamlId": "some",
},
],
]
Expand All @@ -791,12 +798,13 @@ Array [
"blue": true,
"children": Array [],
"funny": "yup",
"id": "some",
"id": "uuid-from-gatsby",
"internal": Object {
"contentDigest": "contentDigest",
"type": "OtherYaml",
},
"parent": "whatever",
"yamlId": "some",
},
"parent": Object {
"children": Array [],
Expand Down Expand Up @@ -825,12 +833,13 @@ Array [
"blue": true,
"children": Array [],
"funny": "yup",
"id": "some",
"id": "uuid-from-gatsby",
"internal": Object {
"contentDigest": "contentDigest",
"type": "fixed",
},
"parent": "whatever",
"yamlId": "some",
},
],
]
Expand All @@ -844,12 +853,13 @@ Array [
"blue": true,
"children": Array [],
"funny": "yup",
"id": "some",
"id": "uuid-from-gatsby",
"internal": Object {
"contentDigest": "contentDigest",
"type": "fixed",
},
"parent": "whatever",
"yamlId": "some",
},
"parent": Object {
"children": Array [],
Expand Down Expand Up @@ -878,12 +888,13 @@ Array [
"blue": true,
"children": Array [],
"funny": "yup",
"id": "some",
"id": "uuid-from-gatsby",
"internal": Object {
"contentDigest": "contentDigest",
"type": "yup",
},
"parent": "whatever",
"yamlId": "some",
},
],
]
Expand All @@ -897,12 +908,13 @@ Array [
"blue": true,
"children": Array [],
"funny": "yup",
"id": "some",
"id": "uuid-from-gatsby",
"internal": Object {
"contentDigest": "contentDigest",
"type": "yup",
},
"parent": "whatever",
"yamlId": "some",
},
"parent": Object {
"children": Array [],
Expand Down
7 changes: 5 additions & 2 deletions packages/gatsby-transformer-yaml/src/gatsby-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ async function onCreateNode(
type,
},
}
if (obj.id) {
yamlNode[`yamlId`] = obj.id
}
createNode(yamlNode)
createParentChildLink({ parent: node, child: yamlNode })
}
Expand All @@ -52,14 +55,14 @@ async function onCreateNode(
parsedContent.forEach((obj, i) => {
transformObject(
obj,
obj.id ? obj.id : createNodeId(`${node.id} [${i}] >>> YAML`),
createNodeId(`${node.id} [${i}] >>> YAML`),
getType({ node, object: obj, isArray: true })
)
})
} else if (_.isPlainObject(parsedContent)) {
transformObject(
parsedContent,
parsedContent.id ? parsedContent.id : createNodeId(`${node.id} >>> YAML`),
createNodeId(`${node.id} >>> YAML`),
getType({ node, object: parsedContent, isArray: false })
)
}
Expand Down

0 comments on commit e58b594

Please sign in to comment.