gatsbyjs / gatsby

The best React-based framework with performance, scalability and security built in.
https://www.gatsbyjs.com
MIT License
55.28k stars 10.31k forks source link

[gatsby-source-contentful] Generating conflicting field types for node id during schema generation #18902

Closed kibagateaux closed 5 years ago

kibagateaux commented 5 years ago

Description

As far as I can tell it's an issue with the Gatsby id field generation in the contentful-plugin. Obviously one is generating an array of string and the other is just a string. I'm not familiar with the library at all but I think I've narrowed it down to this section of code in normalize.js. Sometimes when I run build there are multiple items in the array, but most times it's only a single string.

...
success source and transform nodes - 21.534s
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.

ContentfulPage.seo___NODE:
 - type: [string]
   value: [ 'a1698287-9f78-53dd-82c2-cf393306ca52' ]
 - type: string
   value: '43e1e1a7-8f2f-5cfc-bb01-2a4d7e442877'
success building schema - 1.433s

 ERROR #85901  GRAPHQL

There was an error in your GraphQL query:

Cannot query field "seo" on type "ContentfulPage".
...

Not sure what caused this because everything was working last night and then this morning, after adding more seo content for testing, this error started occurring.

I think this might be caused by the setup of my SEO module. In Contentful I have two different models for pages - ContentfulPage and ContentfulArticlePage. Both have a single-reference field with the same name/id of seo that points to my SEO model. The SEO model also has a reference field seoPage that points back to a ContentfulPage or ContentfulArticlePage for ease of querying in Gatsby and navigation in Contentful. This seoPage field used to be single-reference but after hitting #3535 I converted it to a multi-reference with a 1 ref max.

This error only occurs on ContentfulPage, I can still query the seo field on my ContentfulArticlePage even though there are multiple pages of both that reference SEO modules.

seo works on ContentfulArticlePage

Screen Shot 2019-10-22 at 3 04 03 PM

seo DOES NOT work on ContentfulPage

Screen Shot 2019-10-22 at 3 04 25 PM

This leads me to believe that it is something wrong with the plugin and not my content model but I can't be sure.

Maybe important detail - all SEO modules are in a 1-1 relationship with a page. They are not referenced multiple times.

Seeing as this is an error generating from an automated process in the plugin, are there any suggestions for a workaround? This error is preventing any builds from succeeding so it's a big blocker.

I looked through #15344 and nothing helped :/

Steps to reproduce

Not sure what is actually causing this but here is what I did with the SEO module which appears to be the trigger.

  1. Create two Content Models called parent1 and parent2
  2. Create a Content Model called child that has a multi-reference field. Add validation rules to this field so it can only select types parent1/2 and at most 1 reference
  3. Add a single-reference field to parent1 and parent2 called child that only accepts child types
  4. Populate dummy data for all types. Make sure that there are childs that reference both parent types

Expected result

Auto generated schema types to be consistent for each content type.

Actual result

Inconsistent types for standard GraphQL field causes build to fail.

Environment

  System:
    OS: macOS 10.14.6
    CPU: (4) x64 Intel(R) Core(TM) i7-5557U CPU @ 3.10GHz
    Shell: 3.2.57 - /bin/bash
  Binaries:
    Node: 11.10.1 - ~/.nvm/versions/node/v11.10.1/bin/node
    Yarn: 1.16.0 - ~/.nvm/versions/node/v11.10.1/bin/yarn
    npm: 6.7.0 - ~/.nvm/versions/node/v11.10.1/bin/npm
  Languages:
    Python: 2.7.16 - /usr/local/bin/python
  Browsers:
    Chrome: 77.0.3865.120
    Safari: 13.0.1
  npmPackages:
    gatsby: ^2.17.0 => 2.17.0 
    gatsby-cli: ^2.7.57 => 2.8.3 
    gatsby-image: ^2.2.25 => 2.2.29 
    gatsby-plugin-manifest: ^2.2.21 => 2.2.23 
    gatsby-plugin-offline: ^3.0.13 => 3.0.16 
    gatsby-plugin-react-helmet: ^3.1.11 => 3.1.13 
    gatsby-plugin-sharp: 2.2.29 => 2.2.29 
    gatsby-plugin-sitemap: ^2.2.17 => 2.2.19 
    gatsby-plugin-styled-components: ^3.1.9 => 3.1.11 
    gatsby-source-airtable: https://github.com/traversal/gatsby-source-airtable.git => 2.0.3 
    gatsby-source-contentful: ^2.1.50 => 2.1.50 
    gatsby-source-filesystem: ^2.1.31 => 2.1.33 
    gatsby-transformer-sharp: ^2.2.21 => 2.3.0 
kibagateaux commented 5 years ago

Mysteriously started working again today. Didn't update or reinstall packages, just checked out from master into the feature branch that had the problems as always and it worked. 🤷‍♂

ebello commented 4 years ago

Just wanted to second this, we are faced with this same issue now. It had been working before but now mysteriously broke. The quick fix for us was to rename one of the fields.

skrbnv commented 4 years ago

It seems like gatsby is not a big fan when two documents of the same content type have different types. In example above first value is array and second is a string.

kibagateaux commented 4 years ago

I haven't touched this project or Gatsby in months but I believe Gatsby should handle different types by creating a GraphQL union of the two as mentioned here https://github.com/gatsbyjs/gatsby/issues/3535

jasonbiondo commented 4 years ago

I'm also seeing this in the prismic plugin as well.