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

refactor: reintroduce contentful sys commen resource attribute #31007

2 changes: 1 addition & 1 deletion e2e-tests/contentful/snapshots.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion e2e-tests/contentful/src/pages/boolean.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export default BooleanPage

export const pageQuery = graphql`
query BooleanQuery {
allContentfulBoolean(sort: { fields: contentful_id }) {
allContentfulBoolean(sort: { fields: sys___id }) {
nodes {
title
boolean
Expand Down
28 changes: 23 additions & 5 deletions e2e-tests/contentful/src/pages/content-reference.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const ContentReferencePage = ({ data }) => {
const entries = data.allContentfulContentReference.nodes
return (
<Layout>
{entries.map(({ contentful_id, title, one, many }) => {
{entries.map(({ sys: { id }, title, one, many }) => {
const slug = slugify(title, { strict: true, lower: true })

let content = null
Expand All @@ -33,7 +33,7 @@ const ContentReferencePage = ({ data }) => {
}

return (
<div data-cy-id={slug} key={contentful_id}>
<div data-cy-id={slug} key={id}>
<h2>{title}</h2>
{content}
</div>
Expand All @@ -50,21 +50,33 @@ export const pageQuery = graphql`
allContentfulContentReference(sort: { fields: title }) {
nodes {
title
contentful_id
sys {
id
}
one {
__typename
contentful_id
sys {
id
}
... on ContentfulText {
title
short
}
... on ContentfulNumber {
title
integer
}
... on ContentfulContentReference {
title
one {
... on ContentfulText {
title
short
}
... on ContentfulNumber {
title
integer
}
... on ContentfulContentReference {
title
}
Expand All @@ -86,7 +98,9 @@ export const pageQuery = graphql`
}
many {
__typename
contentful_id
sys {
id
}
... on ContentfulText {
title
short
Expand All @@ -102,6 +116,10 @@ export const pageQuery = graphql`
title
short
}
... on ContentfulNumber {
title
integer
}
... on ContentfulContentReference {
title
}
Expand Down
6 changes: 3 additions & 3 deletions e2e-tests/contentful/src/pages/date.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,19 @@ export default DatePage

export const pageQuery = graphql`
query DateQuery {
dateTime: contentfulDate(contentful_id: { eq: "38akBjGb3T1t4AjB87wQjo" }) {
dateTime: contentfulDate(sys: { id: { eq: "38akBjGb3T1t4AjB87wQjo" } }) {
title
date: dateTime
formatted: dateTime(formatString: "D.M.YYYY - hh:mm")
}
dateTimeTimezone: contentfulDate(
contentful_id: { eq: "6dZ8pK4tFWZDZPHgSC0tNS" }
sys: { id: { eq: "6dZ8pK4tFWZDZPHgSC0tNS" } }
) {
title
date: dateTimeTimezone
formatted: dateTimeTimezone(formatString: "D.M.YYYY - hh:mm (z)")
}
date: contentfulDate(contentful_id: { eq: "5FuULz0jl0rKoKUKp2rshf" }) {
date: contentfulDate(sys: { id: { eq: "5FuULz0jl0rKoKUKp2rshf" } }) {
title
date
formatted: date(formatString: "D.M.YYYY")
Expand Down
16 changes: 9 additions & 7 deletions e2e-tests/contentful/src/pages/gatsby-image.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,15 +119,17 @@ export const pageQuery = graphql`
query GatsbyImageQuery {
allContentfulAsset(
filter: {
contentful_id: {
in: [
"3ljGfnpegOnBTFGhV07iC1"
"3BSI9CgDdAn1JchXmY5IJi"
"65syuRuRVeKi03HvRsOkkb"
]
sys: {
id: {
in: [
"3ljGfnpegOnBTFGhV07iC1"
"3BSI9CgDdAn1JchXmY5IJi"
"65syuRuRVeKi03HvRsOkkb"
]
}
}
}
sort: { fields: contentful_id }
sort: { fields: sys___id }
) {
nodes {
title
Expand Down
16 changes: 9 additions & 7 deletions e2e-tests/contentful/src/pages/gatsby-plugin-image.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,15 +158,17 @@ export const pageQuery = graphql`
query GatsbyPluginImageQuery {
allContentfulAsset(
filter: {
contentful_id: {
in: [
"3ljGfnpegOnBTFGhV07iC1"
"3BSI9CgDdAn1JchXmY5IJi"
"65syuRuRVeKi03HvRsOkkb"
]
sys: {
id: {
in: [
"3ljGfnpegOnBTFGhV07iC1"
"3BSI9CgDdAn1JchXmY5IJi"
"65syuRuRVeKi03HvRsOkkb"
]
}
}
}
sort: { fields: contentful_id }
sort: { fields: sys___id }
) {
nodes {
title
Expand Down
7 changes: 4 additions & 3 deletions e2e-tests/contentful/src/pages/json.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import Layout from "../components/layout"
const JSONPage = ({ data }) => {
const simple = data.simple.json
const actors = data.complex.json.Actors

return (
<Layout>
<h1>Simple:</h1>
Expand All @@ -29,7 +30,7 @@ const JSONPage = ({ data }) => {
<p data-cy-value-name>Name: {actor.name}</p>
<p data-cy-value-photo>Photo: {actor.photo}</p>
<p data-cy-value-birthdate>Birthdate: {actor.Birthdate}</p>
<p data-cy-value-born-at>Born at: {actor.Born_At}</p>
<p data-cy-value-born-at>Born at: {actor["Born At"]}</p>
<p data-cy-value-weight>Weight: {actor.weight}</p>
<p data-cy-value-age>Age: {actor.age}</p>
<p data-cy-value-wife>Wife: {actor.wife}</p>
Expand All @@ -51,10 +52,10 @@ export default JSONPage

export const pageQuery = graphql`
query JSONQuery {
simple: contentfulJson(contentful_id: { eq: "2r6tNjP8brkyy5yLR39hhh" }) {
simple: contentfulJson(sys: { id: { eq: "2r6tNjP8brkyy5yLR39hhh" } }) {
json
}
complex: contentfulJson(contentful_id: { eq: "2y71nV0cpW9vzTmJybq571" }) {
complex: contentfulJson(sys: { id: { eq: "2y71nV0cpW9vzTmJybq571" } }) {
json
}
}
Expand Down
2 changes: 1 addition & 1 deletion e2e-tests/contentful/src/pages/location.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export default LocationPage

export const pageQuery = graphql`
query LocationQuery {
allContentfulLocation(sort: { fields: contentful_id }) {
allContentfulLocation(sort: { fields: sys___id }) {
nodes {
title
location {
Expand Down
8 changes: 5 additions & 3 deletions e2e-tests/contentful/src/pages/media-reference.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const MediaReferencePage = ({ data }) => {
const entries = data.allContentfulMediaReference.nodes
return (
<Layout>
{entries.map(({ contentful_id, title, one, many }) => {
{entries.map(({ sys: { id }, title, one, many }) => {
const slug = slugify(title, { strict: true, lower: true })

let content = null
Expand All @@ -24,7 +24,7 @@ const MediaReferencePage = ({ data }) => {
}

return (
<div data-cy-id={slug} key={contentful_id}>
<div data-cy-id={slug} key={id}>
<h2>{title}</h2>
{content}
</div>
Expand All @@ -41,7 +41,9 @@ export const pageQuery = graphql`
allContentfulMediaReference(sort: { fields: title }) {
nodes {
title
contentful_id
sys {
id
}
one {
fluid(maxWidth: 200) {
...GatsbyContentfulFluid
Expand Down
2 changes: 1 addition & 1 deletion e2e-tests/contentful/src/pages/number.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export default NumberPage

export const pageQuery = graphql`
query NumberQuery {
allContentfulNumber(sort: { fields: contentful_id }) {
allContentfulNumber(sort: { fields: sys___id }) {
nodes {
title
integer
Expand Down
15 changes: 9 additions & 6 deletions e2e-tests/contentful/src/pages/rich-text.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,30 +96,31 @@ export const pageQuery = graphql`
raw
references {
__typename
sys {
id
}
... on ContentfulAsset {
contentful_id
fluid(maxWidth: 200) {
...GatsbyContentfulFluid
}
}
... on ContentfulText {
contentful_id
title
short
}
... on ContentfulLocation {
contentful_id
location {
lat
lon
}
}
... on ContentfulContentReference {
contentful_id
title
one {
__typename
contentful_id
sys {
id
}
... on ContentfulText {
title
short
Expand All @@ -140,7 +141,9 @@ export const pageQuery = graphql`
}
many {
__typename
contentful_id
sys {
id
}
... on ContentfulText {
title
short
Expand Down
10 changes: 5 additions & 5 deletions e2e-tests/contentful/src/pages/text.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,19 +53,19 @@ export default TextPage

export const pageQuery = graphql`
query TextQuery {
short: contentfulText(contentful_id: { eq: "5ZtcN1o7KpN7J7xgiTyaXo" }) {
short: contentfulText(sys: { id: { eq: "5ZtcN1o7KpN7J7xgiTyaXo" } }) {
short
}
shortList: contentfulText(contentful_id: { eq: "7b5U927WTFcQXO2Gewwa2k" }) {
shortList: contentfulText(sys: { id: { eq: "7b5U927WTFcQXO2Gewwa2k" } }) {
shortList
}
longPlain: contentfulText(contentful_id: { eq: "6ru8cSC9hZi3Ekvtw7P77S" }) {
longPlain: contentfulText(sys: { id: { eq: "6ru8cSC9hZi3Ekvtw7P77S" } }) {
longPlain {
raw
}
}
longMarkdownSimple: contentfulText(
contentful_id: { eq: "NyPJw0mcSuCwY2gV0zYny" }
sys: { id: { eq: "NyPJw0mcSuCwY2gV0zYny" } }
) {
longMarkdown {
childMarkdownRemark {
Expand All @@ -74,7 +74,7 @@ export const pageQuery = graphql`
}
}
longMarkdownComplex: contentfulText(
contentful_id: { eq: "3pwKS9UWsYmOguo4UdE1EB" }
sys: { id: { eq: "3pwKS9UWsYmOguo4UdE1EB" } }
) {
longMarkdown {
childMarkdownRemark {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -694,7 +694,7 @@ describe(`gatsby-node`, () => {
const initNodes = getNodes()

const homeNodes = initNodes.filter(
({ contentful_id: id }) => id === `6KpLS2NZyB3KAvDzWf4Ukh`
({ sys: { id } }) => id === `6KpLS2NZyB3KAvDzWf4Ukh`
)
homeNodes.forEach(homeNode => {
expect(homeNode.content.references___NODE).toStrictEqual([
Expand Down
15 changes: 4 additions & 11 deletions packages/gatsby-source-contentful/src/__tests__/normalize.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
const normalize = require(`../normalize`)
const { restrictedNodeFields } = require(`../config`)

const {
currentSyncData,
contentTypeItems,
Expand All @@ -8,15 +10,6 @@ const {
} = require(`./data.json`)

const conflictFieldPrefix = `contentful_test`
// restrictedNodeFields from here https://www.gatsbyjs.org/docs/node-interface/
const restrictedNodeFields = [
`id`,
`children`,
`contentful_id`,
`parent`,
`fields`,
`internal`,
]

describe(`Process contentful data (by name)`, () => {
let entryList
Expand Down Expand Up @@ -134,7 +127,7 @@ describe(`Skip existing nodes in warm build`, () => {
// returned is not relevant to test so update if anything breaks.
return {
id,
internal: { contentDigest: entryList[0][0].sys.updatedAt },
internal: { contentDigest: entryList[0][0].sys.publishedAt },
}
}
// All other nodes are new ("unknown")
Expand Down Expand Up @@ -218,7 +211,7 @@ describe(`Process existing mutated nodes in warm build`, () => {
return {
id,
internal: {
contentDigest: entryList[0][0].sys.updatedAt + `changed`,
contentDigest: entryList[0][0].sys.publishedAt + `changed`,
},
}
}
Expand Down
Loading