gatsby-source-strapi icon indicating copy to clipboard operation
gatsby-source-strapi copied to clipboard

"Conflicting field types" warning when a rich text field is empty (Gatsby 4 / Strapi 4)

Open tms0 opened this issue 3 years ago • 2 comments

Hi,

I have a collection with an optional rich text field. If there is at least one entry with the rich text not empty and an other entry with the field empty, Gatsby will display a warning and the field will be omitted from the GraphQL schema:

warn There are conflicting field types in your data.

If you have explicitly defined a type for those fields, you can safely ignore this warning message.
Otherwise, Gatsby will omit those fields from the GraphQL schema.

If you know all field types in advance, the best strategy is to explicitly define them with the `createTypes` action, and skip inference with the `@dontInfer` directive.
See https://www.gatsbyjs.org/docs/actions/#createTypes
STRAPI_XXXXX.yyyyy:
 - type: object
   value: { data___NODE: [Object] }
 - type: string
   value: ''

NB: The associated "textNode" field will still be generated.

tms0 avatar Mar 13 '22 16:03 tms0

@tms0 did you managed to fix it?

I have the same issue.

I have a component called Sections/TextSection. Using the component as an example, I get these results for the following query:

query MyQuery {
  allStrapiComponentSectionsTextSection {
    nodes {
      copy {
        data {
          copy
        }
      }
    }
  }
}

All fields with content

All copy fields have content: no errors. Output looks fine.

GraphiQL

{
  "data": {
    "allStrapiComponentSectionsTextSection": {
      "nodes": [
        {
          "copy": {
            "data": {
              "copy": "Must not be empty"
            }
          }
        },
        {
          "copy": {
            "data": {
              "copy": "Lorem ipsum"
            }
          }
        }
      ]
    }
  },
  "extensions": {
    "enableRefresh": "true"
  }
}

One field empty

At least one copy field is empty. An error occured and the build would break.

warn There are conflicting field types in your data.

If you have explicitly defined a type for those fields, you can safely ignore this warning message.
Otherwise, Gatsby will omit those fields from the GraphQL schema.

If you know all field types in advance, the best strategy is to explicitly define them with the `createTypes` action, and skip inference with the `@dontInfer` directive.
See https://www.gatsbyjs.org/docs/actions/#createTypes
STRAPI__COMPONENT_SECTIONS_TEXT_SECTION.copy:
 - type: object
   value: { data___NODE: [Object] }
 - type: string
   value: ''

GraphiQL

{
  "errors": [
    {
      "message": "Cannot query field \"copy\" on type \"STRAPI__COMPONENT_SECTIONS_TEXT_SECTION\".",
      "locations": [
        {
          "line": 4,
          "column": 7
        }
      ],
      "extensions": {
        "stack": [
          "GraphQLError: Cannot query field \"copy\" on type \"STRAPI__COMPONENT_SECTIONS_TEXT_SECTION\".",
          "    at Object.Field (/Users/###PATH_TO_PROJECT###/node_modules/graphql/validation/rules/FieldsOnCorrectTypeRule.js:48:31)",
          "    at Object.enter (/Users/###PATH_TO_PROJECT###/node_modules/graphql/language/visitor.js:323:29)",
          "    at Object.enter (/Users/###PATH_TO_PROJECT###/node_modules/graphql/utilities/TypeInfo.js:370:25)",
          "    at visit (/Users/###PATH_TO_PROJECT###/node_modules/graphql/language/visitor.js:243:26)",
          "    at validate (/Users/###PATH_TO_PROJECT###/node_modules/graphql/validation/validate.js:69:24)",
          "    at graphqlMiddleware (/###PATH_TO_PROJECT###/node_modules/express-graphql/index.js:98:38)",
          "    at processTicksAndRejections (internal/process/task_queues.js:95:5)"
        ]
      }
    }
  ]
}

Defining types leads to data: null

Trying to fix the error by explicitly defining the corresponding types leads to the fact that although there is no error, I don't get any data either.

GraphiQL

// gatsby-node.js

exports.createSchemaCustomization = ({ actions }) => {
  const { createTypes } = actions
  const typeDefs = `
    type STRAPI__COMPONENT_SECTIONS_TEXT_SECTION_COPY_TEXTNODE implements Node {
      copy: String
    }

    type STRAPI__COMPONENT_SECTIONS_TEXT_SECTIONCopy {
      data: STRAPI__COMPONENT_SECTIONS_TEXT_SECTION_COPY_TEXTNODE
    }

    type STRAPI__COMPONENT_SECTIONS_TEXT_SECTION implements Node {
      copy: STRAPI__COMPONENT_SECTIONS_TEXT_SECTIONCopy
    }
  `
  createTypes(typeDefs)
}
{
  "data": {
    "allStrapiComponentSectionsTextSection": {
      "nodes": [
        {
          "copy": {
            "data": null
          }
        },
        {
          "copy": {
            "data": null
          }
        }
      ]
    }
  },
  "extensions": {
    "enableRefresh": "true"
  }
}

Am I missing something in the type definition or something else?

Environment

Gatsby

  • Node 14.19.0
  • NPM 6.14.16
  • Gatsby 4.2.0
  • gatsby-source-strapi 2.0.0

Strapi

  • @strapi/strapi 4.1.7
  • @strapi/plugin-graphql 4.1.7
  • The database type does not seem to make any difference:
    • sqlite3 5.0.2
    • pg: 8.7.3

thomaseckhardt avatar Apr 11 '22 13:04 thomaseckhardt

@thomaseckhardt I am having a similar issue. When setting up my createSchemaCustomization like you did with your types, I also received null values.

Instead of using the types in the documentation explorer I used the definitions on the left side of the /__graphql interface.

In your case that would change your code to:

type strapiComponentSectionsTextSectionCopyTextnode implements Node {
  copy: String
}

type strapiComponentSectionTextSectionCopy implements Node {
  data: strapiComponentSectionsTextSectionCopyTextnode
}

type strapiComponentSectionsTextSection implements Node {
  copy: strapiComponentSectionTextSectionCopy
}

Sailias avatar May 16 '22 00:05 Sailias

Thanks for your interest in this project. This plugin is moving into the Gatsby User Collective and this repo will be archived. Please open an issue in that repository, submit a PR if you'd like to see this implemented, or join us on Discord if you have questions!

moonmeister avatar Dec 27 '22 18:12 moonmeister