Skip to content

Commit

Permalink
Forgot can't do multiple underscores at start of GraphQL names
Browse files Browse the repository at this point in the history
  • Loading branch information
KyleAMathews committed Sep 28, 2017
1 parent 93943f5 commit aa04073
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Array [
Object {
"children": Array [],
"frontmatter": Object {
"___PARENT": "whatever",
"_PARENT": "whatever",
"date": "2017-09-18T23:19:51.246Z",
"parent": "whatever",
"title": "my little pony",
Expand Down Expand Up @@ -36,7 +36,7 @@ Array [
"child": Object {
"children": Array [],
"frontmatter": Object {
"___PARENT": "whatever",
"_PARENT": "whatever",
"date": "2017-09-18T23:19:51.246Z",
"parent": "whatever",
"title": "my little pony",
Expand Down
8 changes: 4 additions & 4 deletions packages/gatsby-transformer-remark/src/on-node-create.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,23 +48,23 @@ module.exports = async function onCreateNode({
},
}

// Add ___PARENT to sub-object in the frontmatter so we can
// Add _PARENT to sub-object in the frontmatter so we can
// use this to find the root markdown node when running GraphQL
// queries. Yes this is lame. But it's because in GraphQL child nodes
// can't access their parent nodes so we use this ___PARENT convention
// can't access their parent nodes so we use this _PARENT convention
// to get around this.
_.each(data.data, (v, k) => {
if (_.isArray(v) && _.isObject(v[0])) {
data.data[k] = v.map(o => {
return { ...o, ___PARENT: node.id }
return { ...o, _PARENT: node.id }
})
}
})

markdownNode.frontmatter = {
title: ``, // always include a title
...data.data,
___PARENT: node.id,
_PARENT: node.id,
// TODO Depreciate this at v2 as much larger chance of conflicting with a
// user supplied field.
parent: node.id,
Expand Down
8 changes: 4 additions & 4 deletions packages/gatsby/src/schema/infer-graphql-type.js
Original file line number Diff line number Diff line change
Expand Up @@ -345,12 +345,12 @@ function findRootNode(node) {
let rootNode = node
let whileCount = 0
while (
(rootNode.___PARENT || rootNode.parent) &&
(getNode(rootNode.parent) !== undefined || getNode(rootNode.___PARENT)) &&
(rootNode._PARENT || rootNode.parent) &&
(getNode(rootNode.parent) !== undefined || getNode(rootNode._PARENT)) &&
whileCount < 101
) {
if (rootNode.___PARENT) {
rootNode = getNode(rootNode.___PARENT)
if (rootNode._PARENT) {
rootNode = getNode(rootNode._PARENT)
} else {
rootNode = getNode(rootNode.parent)
}
Expand Down

0 comments on commit aa04073

Please sign in to comment.