Skip to content

Commit

Permalink
refactor: reintroduce contentful sys common resource attribute #31007
Browse files Browse the repository at this point in the history
  • Loading branch information
axe312ger committed Apr 29, 2021
1 parent 0ed7cbb commit 777e5fd
Show file tree
Hide file tree
Showing 28 changed files with 3,910 additions and 4,469 deletions.
2 changes: 1 addition & 1 deletion e2e-tests/contentful/cypress.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"baseUrl": "http://localhost:9000",
"retries": {
"runMode": 2,
"runMode": 0,
"openMode": 0
},
"viewportWidth": 1440,
Expand Down
17 changes: 12 additions & 5 deletions e2e-tests/contentful/cypress/integration/gatsby-image.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
const testConfig = {
retries: {
runMode: 2,
openMode: 0,
},
}

function hasSVGPlaceholder(el) {
el.children(`img`)
.should(`have.attr`, `src`)
Expand Down Expand Up @@ -41,9 +48,9 @@ describe(`gatsby-image`, () => {
beforeEach(() => {
cy.visit("/gatsby-image").waitForRouteChange()
})
it(`fluid`, () => testGatsbyImage(`fluid`, hasJPEGPlaceholder))
it(`fixed`, () => testGatsbyImage(`fixed`, hasJPEGPlaceholder))
it(`webp`, () => testGatsbyImage(`webp`, hasJPEGPlaceholder))
it(`traced`, () => testGatsbyImage(`traced`, hasSVGPlaceholder))
it(`sqip`, () => testGatsbyImage(`sqip`, hasSVGPlaceholder))
it(`fluid`, testConfig, () => testGatsbyImage(`fluid`, hasJPEGPlaceholder))
it(`fixed`, testConfig, () => testGatsbyImage(`fixed`, hasJPEGPlaceholder))
it(`webp`, testConfig, () => testGatsbyImage(`webp`, hasJPEGPlaceholder))
it(`traced`, testConfig, () => testGatsbyImage(`traced`, hasSVGPlaceholder))
it(`sqip`, testConfig, () => testGatsbyImage(`sqip`, hasSVGPlaceholder))
})
35 changes: 26 additions & 9 deletions e2e-tests/contentful/cypress/integration/gatsby-plugin-image.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
const testConfig = {
retries: {
runMode: 2,
openMode: 0,
},
}

function hasSVGPlaceholder(el) {
el.find(`img`)
.should(`have.attr`, `src`)
Expand Down Expand Up @@ -54,13 +61,23 @@ describe(`gatsby-plugin-image`, () => {
cy.visit("/gatsby-plugin-image").waitForRouteChange()
})

it(`constrained`, () =>
testGatsbyPluginImage(`constrained`, hasColorPlaceholder))
it(`full-width`, () => testGatsbyPluginImage(`full-width`, hasNoPlaceholder))
it(`fixed`, () => testGatsbyPluginImage(`fixed`, hasNoPlaceholder))
it(`dominant-color`, () =>
testGatsbyPluginImage(`dominant-color`, hasColorPlaceholder))
it(`traced`, () => testGatsbyPluginImage(`traced`, hasSVGPlaceholder))
it(`blurred`, () => testGatsbyPluginImage(`blurred`, hasJPEGPlaceholder))
it(`sqip`, () => testGatsbyPluginImage(`sqip`, hasSVGPlaceholder))
it(`constrained`, testConfig, () =>
testGatsbyPluginImage(`constrained`, hasColorPlaceholder)
)
it(`full-width`, testConfig, () =>
testGatsbyPluginImage(`full-width`, hasNoPlaceholder)
)
it(`fixed`, testConfig, () =>
testGatsbyPluginImage(`fixed`, hasNoPlaceholder)
)
it(`dominant-color`, testConfig, () =>
testGatsbyPluginImage(`dominant-color`, hasColorPlaceholder)
)
it(`traced`, testConfig, () =>
testGatsbyPluginImage(`traced`, hasSVGPlaceholder)
)
it(`blurred`, testConfig, () =>
testGatsbyPluginImage(`blurred`, hasJPEGPlaceholder)
)
it(`sqip`, testConfig, () => testGatsbyPluginImage(`sqip`, hasSVGPlaceholder))
})
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
Loading

0 comments on commit 777e5fd

Please sign in to comment.