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

ctf-next: use link extension instead of adding ___NODE to field names #37021

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ Array [
"extensions": Object {
"link": Object {
"by": "id",
"from": "contentType___NODE",
"from": "sys.contentType",
},
},
"type": "ContentfulContentType",
Expand Down Expand Up @@ -83,7 +83,7 @@ Array [
"extensions": Object {
"link": Object {
"by": "id",
"from": "tags___NODE",
"from": "tags",
},
},
"type": "[ContentfulTag]!",
Expand Down Expand Up @@ -402,7 +402,7 @@ Ignored if layout = FLUID.",
"extensions": Object {
"link": Object {
"by": "id",
"from": "longLocalized___NODE",
"from": "longLocalized",
},
},
"type": "ContentfulText",
Expand All @@ -411,7 +411,7 @@ Ignored if layout = FLUID.",
"extensions": Object {
"link": Object {
"by": "id",
"from": "longMarkdown___NODE",
"from": "longMarkdown",
},
},
"type": "ContentfulText",
Expand All @@ -420,7 +420,7 @@ Ignored if layout = FLUID.",
"extensions": Object {
"link": Object {
"by": "id",
"from": "longPlain___NODE",
"from": "longPlain",
},
},
"type": "ContentfulText",
Expand Down Expand Up @@ -468,7 +468,7 @@ Ignored if layout = FLUID.",
"extensions": Object {
"link": Object {
"by": "id",
"from": "many___NODE",
"from": "many",
},
},
"type": "[ContentfulAsset]",
Expand All @@ -477,7 +477,7 @@ Ignored if layout = FLUID.",
"extensions": Object {
"link": Object {
"by": "id",
"from": "manyLocalized___NODE",
"from": "manyLocalized",
},
},
"type": "[ContentfulAsset]",
Expand All @@ -489,7 +489,7 @@ Ignored if layout = FLUID.",
"extensions": Object {
"link": Object {
"by": "id",
"from": "one___NODE",
"from": "one",
},
},
"type": "ContentfulAsset",
Expand All @@ -498,7 +498,7 @@ Ignored if layout = FLUID.",
"extensions": Object {
"link": Object {
"by": "id",
"from": "oneLocalized___NODE",
"from": "oneLocalized",
},
},
"type": "ContentfulAsset",
Expand Down Expand Up @@ -717,7 +717,7 @@ Ignored if layout = FLUID.",
"extensions": Object {
"link": Object {
"by": "id",
"from": "many___NODE",
"from": "many",
},
},
"type": "[UnionContentfulContentReferenceNumberText]",
Expand All @@ -726,7 +726,7 @@ Ignored if layout = FLUID.",
"extensions": Object {
"link": Object {
"by": "id",
"from": "manyLocalized___NODE",
"from": "manyLocalized",
},
},
"type": "[ContentfulEntry]",
Expand All @@ -738,7 +738,7 @@ Ignored if layout = FLUID.",
"extensions": Object {
"link": Object {
"by": "id",
"from": "one___NODE",
"from": "one",
},
},
"type": "ContentfulEntry",
Expand All @@ -747,7 +747,7 @@ Ignored if layout = FLUID.",
"extensions": Object {
"link": Object {
"by": "id",
"from": "oneLocalized___NODE",
"from": "oneLocalized",
},
},
"type": "ContentfulEntry",
Expand Down Expand Up @@ -783,7 +783,7 @@ Ignored if layout = FLUID.",
"extensions": Object {
"link": Object {
"by": "id",
"from": "multipleItemsAllTypes___NODE",
"from": "multipleItemsAllTypes",
},
},
"type": "[ContentfulEntry]",
Expand All @@ -792,7 +792,7 @@ Ignored if layout = FLUID.",
"extensions": Object {
"link": Object {
"by": "id",
"from": "multipleItemsManyTypes___NODE",
"from": "multipleItemsManyTypes",
},
},
"type": "[UnionContentfulNumberText]",
Expand All @@ -801,7 +801,7 @@ Ignored if layout = FLUID.",
"extensions": Object {
"link": Object {
"by": "id",
"from": "multipleItemsSingleType___NODE",
"from": "multipleItemsSingleType",
},
},
"type": "[ContentfulContentTypeText]",
Expand All @@ -810,7 +810,7 @@ Ignored if layout = FLUID.",
"extensions": Object {
"link": Object {
"by": "id",
"from": "oneItemAllTypes___NODE",
"from": "oneItemAllTypes",
},
},
"type": "ContentfulEntry",
Expand All @@ -819,7 +819,7 @@ Ignored if layout = FLUID.",
"extensions": Object {
"link": Object {
"by": "id",
"from": "oneItemManyTypes___NODE",
"from": "oneItemManyTypes",
},
},
"type": "UnionContentfulNumberText",
Expand All @@ -828,7 +828,7 @@ Ignored if layout = FLUID.",
"extensions": Object {
"link": Object {
"by": "id",
"from": "oneItemSingleType___NODE",
"from": "oneItemSingleType",
},
},
"type": "ContentfulContentTypeText",
Expand Down
28 changes: 14 additions & 14 deletions packages/gatsby-source-contentful/src/__tests__/gatsby-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ describe(`gatsby-node`, () => {
type: value.sys.linkType || value.sys.type,
})
)
matchedObject[`${field}___NODE`] = linkId
matchedObject[field] = linkId

if (
value.sys.type !== `Asset` &&
Expand All @@ -250,7 +250,7 @@ describe(`gatsby-node`, () => {
references.set(linkId, {})
}

const referenceKey = `${currentContentType.name.toLowerCase()}___NODE`
const referenceKey = currentContentType.name.toLowerCase()
const reference = references.get(linkId)
const linkedNode = getNode(linkId)
reference[referenceKey] =
Expand All @@ -264,7 +264,7 @@ describe(`gatsby-node`, () => {
}
case `Text`: {
const linkId = createNodeId(`${nodeId}${field}TextNode`)
matchedObject[`${field}___NODE`] = linkId
matchedObject[field] = linkId
break
}
default:
Expand Down Expand Up @@ -313,7 +313,7 @@ describe(`gatsby-node`, () => {
// check if all references got removed references should be removed
for (const value of currentNodeMap.values()) {
Object.keys(value).forEach(field => {
if (field.endsWith(`___NODE`)) {
if (![`id`, `parent`].includes(field)) {
expect([].concat(value[field])).not.toContain(nodeId)
}
})
Expand Down Expand Up @@ -654,7 +654,7 @@ describe(`gatsby-node`, () => {

createdBlogEntryIds.forEach(blogEntryId => {
const blogEntry = getNode(blogEntryId)
expect(getNode(blogEntry[`author___NODE`])).toBeTruthy()
expect(getNode(blogEntry[`author`])).toBeTruthy()
})

expect(actions.createNode).toHaveBeenCalledTimes(44)
Expand Down Expand Up @@ -744,7 +744,7 @@ describe(`gatsby-node`, () => {
updatedBlogEntryIds.forEach(blogEntryId => {
const blogEntry = getNode(blogEntryId)
expect(blogEntry.title).toBe(`Hello world 1234`)
expect(getNode(blogEntry[`author___NODE`])).toBeTruthy()
expect(getNode(blogEntry[`author`])).toBeTruthy()
})

expect(actions.createNode).toHaveBeenCalledTimes(52)
Expand Down Expand Up @@ -812,8 +812,8 @@ describe(`gatsby-node`, () => {
for (const author of getNodes().filter(
n => n.internal.type === `ContentfulPerson`
)) {
expect(author[`blog post___NODE`].length).toEqual(3)
expect(author[`blog post___NODE`]).toEqual(
expect(author[`blog post`].length).toEqual(3)
expect(author[`blog post`]).toEqual(
expect.not.arrayContaining([
makeId({
spaceId: removedBlogEntry.sys.space.sys.id,
Expand All @@ -833,15 +833,15 @@ describe(`gatsby-node`, () => {
// check if blog post exists
removedBlogEntryIds.forEach(entryId => {
const blogEntry = getNode(entryId)
authorIds.push(blogEntry[`author___NODE`])
authorIds.push(blogEntry[`author`])
expect(blogEntry).not.toBeUndefined()
})

for (const author of getNodes().filter(
n => n.internal.type === `ContentfulPerson`
)) {
expect(author[`blog post___NODE`].length).toEqual(4)
expect(author[`blog post___NODE`]).toEqual(
expect(author[`blog post`].length).toEqual(4)
expect(author[`blog post`]).toEqual(
expect.arrayContaining([
makeId({
spaceId: removedBlogEntry.sys.space.sys.id,
Expand Down Expand Up @@ -879,8 +879,8 @@ describe(`gatsby-node`, () => {
for (const author of getNodes().filter(
n => n.internal.type === `ContentfulPerson`
)) {
expect(author[`blog post___NODE`].length).toEqual(3)
expect(author[`blog post___NODE`]).toEqual(
expect(author[`blog post`].length).toEqual(3)
expect(author[`blog post`]).toEqual(
expect.not.arrayContaining([
makeId({
spaceId: removedBlogEntry.sys.space.sys.id,
Expand All @@ -895,7 +895,7 @@ describe(`gatsby-node`, () => {

// check if references are gone
authorIds.forEach(authorId => {
expect(getNode(authorId)[`blog post___NODE`]).toEqual(
expect(getNode(authorId)[`blog post`]).toEqual(
expect.not.arrayContaining(deletedEntryIds)
)
})
Expand Down
8 changes: 4 additions & 4 deletions packages/gatsby-source-contentful/src/__tests__/normalize.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,11 +154,11 @@ describe(`Process contentful data (by name)`, () => {
})

expect(foreignReferenceMap[`24DPGBDeGEaYy8ms4Y8QMQ___Entry`][0].name).toBe(
`product___NODE`
`product`
)

expect(foreignReferenceMap[`2Y8LhXLnYAYqKCGEWG4EKI___Asset`][0].name).toBe(
`brand___NODE`
`brand`
)
})

Expand Down Expand Up @@ -355,11 +355,11 @@ describe(`Process contentful data (by id)`, () => {
})

expect(foreignReferenceMap[`24DPGBDeGEaYy8ms4Y8QMQ___Entry`][0].name).toBe(
`2pqfxujwe8qsykum0u6w8m___NODE`
`2pqfxujwe8qsykum0u6w8m`
)

expect(foreignReferenceMap[`2Y8LhXLnYAYqKCGEWG4EKI___Asset`][0].name).toBe(
`sfztzbsum8coewygeuyes___NODE`
`sfztzbsum8coewygeuyes`
)
})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const ContentfulDataTypes = new Map([
return {
type: `ContentfulText`,
extensions: {
link: { by: `id`, from: `${field.id}___NODE` },
link: { by: `id`, from: field.id },
},
}
},
Expand Down Expand Up @@ -112,7 +112,7 @@ const getLinkFieldType = (linkType, field, schema, createTypes) => {
return {
type: translatedTypeNames.shift(),
extensions: {
link: { by: `id`, from: `${field.id}___NODE` },
link: { by: `id`, from: field.id },
},
}
}
Expand All @@ -133,7 +133,7 @@ const getLinkFieldType = (linkType, field, schema, createTypes) => {
return {
type: unionName,
extensions: {
link: { by: `id`, from: `${field.id}___NODE` },
link: { by: `id`, from: field.id },
},
}
}
Expand All @@ -142,7 +142,7 @@ const getLinkFieldType = (linkType, field, schema, createTypes) => {
return {
type: `Contentful${linkType}`,
extensions: {
link: { by: `id`, from: `${field.id}___NODE` },
link: { by: `id`, from: field.id },
},
}
}
Expand Down Expand Up @@ -280,7 +280,7 @@ export async function createSchemaCustomization(
contentType: {
type: `ContentfulContentType`,
extensions: {
link: { by: `id`, from: `contentType___NODE` },
link: { by: `id`, from: `sys.contentType` },
},
},
firstPublishedAt: { type: ` Date!` },
Expand All @@ -300,7 +300,7 @@ export async function createSchemaCustomization(
tags: {
type: `[ContentfulTag]!`,
extensions: {
link: { by: `id`, from: `tags___NODE` },
link: { by: `id`, from: `tags` },
},
},
},
Expand Down
Loading