diff --git a/e2e-tests/contentful/cypress/integration/delivery/custom-fields.js b/e2e-tests/contentful/cypress/integration/delivery/custom-fields.js new file mode 100644 index 0000000000000..337d5964eb097 --- /dev/null +++ b/e2e-tests/contentful/cypress/integration/delivery/custom-fields.js @@ -0,0 +1,19 @@ +describe(`custom-fields`, () => { + beforeEach(() => { + cy.visit("/custom-fields").waitForRouteChange() + }) + + it(`custom-fields: custom field`, () => { + cy.get(`[data-cy-id="field"] [data-cy-value]`).should( + `have.text`, + `customFieldValue` + ) + }) + + it(`custom-fields: custom resolver`, () => { + cy.get(`[data-cy-id="resolver"] [data-cy-value]`).should( + `have.text`, + `customResolverResult` + ) + }) +}) diff --git a/e2e-tests/contentful/gatsby-node.js b/e2e-tests/contentful/gatsby-node.js new file mode 100644 index 0000000000000..4a90b408c7c57 --- /dev/null +++ b/e2e-tests/contentful/gatsby-node.js @@ -0,0 +1,39 @@ +exports.onCreateNode = ({ node, actions }) => { + const { createNodeField } = actions + + if (node.internal.type === "ContentfulContentTypeText") { + createNodeField({ + node, + name: "customField", + value: "customFieldValue", + }) + } +} + +exports.createSchemaCustomization = ({ actions, schema }) => { + const { createTypes } = actions + + const typeDefs = ` + type ContentfulContentTypeTextFields { + customField: String! + } + type ContentfulContentTypeText { + fields: ContentfulContentTypeTextFields! + } + ` + + createTypes(typeDefs) +} + +exports.createResolvers = ({ createResolvers }) => { + createResolvers({ + ContentfulContentTypeText: { + customResolver: { + type: 'String!', + resolve(source, args, context, info) { + return "customResolverResult" + }, + }, + }, + }) +} \ No newline at end of file diff --git a/e2e-tests/contentful/src/pages/custom-fields.js b/e2e-tests/contentful/src/pages/custom-fields.js new file mode 100644 index 0000000000000..7d665ec629973 --- /dev/null +++ b/e2e-tests/contentful/src/pages/custom-fields.js @@ -0,0 +1,35 @@ +import { graphql } from "gatsby" +import * as React from "react" + +import Layout from "../components/layout" + +const CustomFieldsPage = ({ data }) => { + const { + contentfulContentTypeText + } = data + return ( + +

Custom Field:

+
+

{contentfulContentTypeText.fields.customField}

+
+

Custom Resolver:

+
+

{contentfulContentTypeText.customResolver}

+
+
+ ) +} + +export default CustomFieldsPage + +export const pageQuery = graphql` + query TextQuery { + contentfulContentTypeText { + fields { + customField + } + customResolver + } + } +` diff --git a/e2e-tests/contentful/src/pages/index.js b/e2e-tests/contentful/src/pages/index.js index f216240c58633..867dccd3922b0 100644 --- a/e2e-tests/contentful/src/pages/index.js +++ b/e2e-tests/contentful/src/pages/index.js @@ -59,6 +59,9 @@ const IndexPage = () => (
  • SSR
  • +
  • + Custom Fields & Resolver +
  • )