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 Mar 9, 2022
1 parent a6274d1 commit ecd71eb
Show file tree
Hide file tree
Showing 23 changed files with 733 additions and 316 deletions.
2 changes: 1 addition & 1 deletion e2e-tests/contentful/src/components/references/text.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from "react"

export const ContentfulText = ({ short, longPlain }) => (
<p data-cy-id="text">[ContentfulText] {short || longPlain?.longPlain}</p>
<p data-cy-id="text">[ContentfulText] {short || longPlain?.raw}</p>
)
21 changes: 15 additions & 6 deletions e2e-tests/contentful/src/pages/boolean.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,26 +50,35 @@ export default BooleanPage
export const pageQuery = graphql`
query BooleanQuery {
default: allContentfulBoolean(
sort: { fields: contentful_id }
filter: { node_locale: { eq: "en-US" }, booleanLocalized: { eq: null } }
sort: { fields: sys___id }
filter: {
sys: { locale: { eq: "en-US" } }
booleanLocalized: { eq: null }
}
) {
nodes {
title
boolean
}
}
english: allContentfulBoolean(
sort: { fields: contentful_id }
filter: { node_locale: { eq: "en-US" }, booleanLocalized: { ne: null } }
sort: { fields: sys___id }
filter: {
sys: { locale: { eq: "en-US" } }
booleanLocalized: { ne: null }
}
) {
nodes {
title
booleanLocalized
}
}
german: allContentfulBoolean(
sort: { fields: contentful_id }
filter: { node_locale: { eq: "de-DE" }, booleanLocalized: { ne: null } }
sort: { fields: sys___id }
filter: {
sys: { locale: { eq: "de-DE" } }
booleanLocalized: { ne: null }
}
) {
nodes {
title
Expand Down
79 changes: 57 additions & 22 deletions e2e-tests/contentful/src/pages/content-reference.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const ContentReferencePage = ({ data }) => {
return (
<Layout>
<h1>Default</h1>
{defaultEntries.map(({ contentful_id, title, one, many }) => {
{defaultEntries.map(({ sys: { id }, title, one, many }) => {
const slug = slugify(title, { strict: true, lower: true })

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

return (
<div data-cy-id={`default-${slug}`} key={contentful_id}>
<div data-cy-id={`default-${slug}`} key={id}>
<h2>{title}</h2>
{content}
</div>
)
})}
<h1>English Locale</h1>
{englishEntries.map(
({ contentful_id, title, oneLocalized, manyLocalized }) => {
({ sys: { id }, title, oneLocalized, manyLocalized }) => {
const slug = slugify(title, { strict: true, lower: true })

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

return (
<div data-cy-id={`english-${slug}`} key={contentful_id}>
<div data-cy-id={`english-${slug}`} key={id}>
<h2>{title}</h2>
{content}
</div>
Expand All @@ -67,7 +67,7 @@ const ContentReferencePage = ({ data }) => {
)}
<h1>German Locale</h1>
{germanEntries.map(
({ contentful_id, title, oneLocalized, manyLocalized }) => {
({ sys: { id }, title, oneLocalized, manyLocalized }) => {
const slug = slugify(title, { strict: true, lower: true })

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

return (
<div data-cy-id={`german-${slug}`} key={contentful_id}>
<div data-cy-id={`german-${slug}`} key={id}>
<h2>{title}</h2>
{content}
</div>
Expand All @@ -97,25 +97,40 @@ export const pageQuery = graphql`
query ContentReferenceQuery {
default: allContentfulContentReference(
sort: { fields: title }
filter: { node_locale: { eq: "en-US" }, title: { glob: "!*Localized*" } }
filter: {
sys: { locale: { eq: "en-US" } }
title: { glob: "!*Localized*" }
}
) {
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 @@ -137,7 +152,9 @@ export const pageQuery = graphql`
}
many {
__typename
contentful_id
sys {
id
}
... on ContentfulText {
title
short
Expand All @@ -153,6 +170,10 @@ export const pageQuery = graphql`
title
short
}
... on ContentfulNumber {
title
integer
}
... on ContentfulContentReference {
title
}
Expand All @@ -176,16 +197,23 @@ export const pageQuery = graphql`
}
english: allContentfulContentReference(
sort: { fields: title }
filter: { node_locale: { eq: "en-US" }, title: { glob: "*Localized*" } }
filter: {
sys: { locale: { eq: "en-US" } }
title: { glob: "*Localized*" }
}
) {
nodes {
title
contentful_id
sys {
id
}
oneLocalized {
__typename
title
decimal
integer
... on ContentfulNumber {
title
decimal
integer
}
}
manyLocalized {
__typename
Expand All @@ -198,24 +226,31 @@ export const pageQuery = graphql`
title
short
longPlain {
longPlain
raw
}
}
}
}
}
german: allContentfulContentReference(
sort: { fields: title }
filter: { node_locale: { eq: "de-DE" }, title: { glob: "*Localized*" } }
filter: {
sys: { locale: { eq: "de-DE" } }
title: { glob: "*Localized*" }
}
) {
nodes {
title
contentful_id
sys {
id
}
oneLocalized {
__typename
title
decimal
integer
... on ContentfulNumber {
title
decimal
integer
}
}
manyLocalized {
__typename
Expand All @@ -228,7 +263,7 @@ export const pageQuery = graphql`
title
short
longPlain {
longPlain
raw
}
}
}
Expand Down
12 changes: 5 additions & 7 deletions e2e-tests/contentful/src/pages/date.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,34 +32,32 @@ 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")
}
dateEnglish: contentfulDate(
contentful_id: { eq: "1ERWZvDiYELryAZEP1dmKG" }
node_locale: { eq: "en-US" }
sys: { id: { eq: "1ERWZvDiYELryAZEP1dmKG" }, locale: { eq: "en-US" } }
) {
title
date: dateLocalized
formatted: dateLocalized(formatString: "D.M.YYYY - HH:mm:ss")
}
dateGerman: contentfulDate(
contentful_id: { eq: "1ERWZvDiYELryAZEP1dmKG" }
node_locale: { eq: "de-DE" }
sys: { id: { eq: "1ERWZvDiYELryAZEP1dmKG" }, locale: { eq: "de-DE" } }
) {
title
date: dateLocalized
Expand Down
28 changes: 14 additions & 14 deletions e2e-tests/contentful/src/pages/gatsby-plugin-image.js
Original file line number Diff line number Diff line change
Expand Up @@ -215,16 +215,18 @@ export const pageQuery = graphql`
query GatsbyPluginImageQuery {
default: allContentfulAsset(
filter: {
contentful_id: {
in: [
"3ljGfnpegOnBTFGhV07iC1"
"3BSI9CgDdAn1JchXmY5IJi"
"65syuRuRVeKi03HvRsOkkb"
]
sys: {
id: {
in: [
"3ljGfnpegOnBTFGhV07iC1"
"3BSI9CgDdAn1JchXmY5IJi"
"65syuRuRVeKi03HvRsOkkb"
]
}
locale: { eq: "en-US" }
}
node_locale: { eq: "en-US" }
}
sort: { fields: contentful_id }
sort: { fields: sys___id }
) {
nodes {
title
Expand Down Expand Up @@ -259,10 +261,9 @@ export const pageQuery = graphql`
}
english: allContentfulAsset(
filter: {
contentful_id: { in: ["4FwygYxkL3rAteERtoxxNC"] }
node_locale: { eq: "en-US" }
sys: { id: { in: ["4FwygYxkL3rAteERtoxxNC"] }, locale: { eq: "en-US" } }
}
sort: { fields: contentful_id }
sort: { fields: sys___id }
) {
nodes {
title
Expand All @@ -276,10 +277,9 @@ export const pageQuery = graphql`
}
german: allContentfulAsset(
filter: {
contentful_id: { in: ["4FwygYxkL3rAteERtoxxNC"] }
node_locale: { eq: "de-DE" }
sys: { id: { in: ["4FwygYxkL3rAteERtoxxNC"] }, locale: { eq: "de-DE" } }
}
sort: { fields: contentful_id }
sort: { fields: sys___id }
) {
nodes {
title
Expand Down
24 changes: 7 additions & 17 deletions e2e-tests/contentful/src/pages/json.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const JSONPage = ({ data }) => {
<p>Name: {actor.name}</p>
<p>Photo: {actor.photo}</p>
<p>Birthdate: {actor.Birthdate}</p>
<p>Born at: {actor.Born_At}</p>
<p>Born at: {actor["Born At"]}</p>
<p>Weight: {actor.weight}</p>
<p>Age: {actor.age}</p>
<p>Wife: {actor.wife}</p>
Expand Down Expand Up @@ -61,33 +61,23 @@ 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
}
english: contentfulJson(
node_locale: { eq: "en-US" }
jsonLocalized: { id: { ne: null } }
sys: { id: { eq: "7DvTBEPg5P6TRC7dI9zXuO" }, locale: { eq: "en-US" } }
) {
title
jsonLocalized {
age
city
name
}
jsonLocalized
}
german: contentfulJson(
node_locale: { eq: "de-DE" }
jsonLocalized: { id: { ne: null } }
sys: { id: { eq: "7DvTBEPg5P6TRC7dI9zXuO" }, locale: { eq: "de-DE" } }
) {
title
jsonLocalized {
age
city
name
}
jsonLocalized
}
}
`
Loading

0 comments on commit ecd71eb

Please sign in to comment.