Skip to content

[gatsby-source-contentful] - Gatsby errors trying to create two Union types with the same name #3544

@JasonStoltz

Description

@JasonStoltz

Description

I have two Content Types in Contentful. They both have a media field that can be a Link to one of two types, BackgroundVideo or ImageWithAltText.

mediaModuleFull (Entity)
  media: (Link: BackgroundVideo|ImageWithAltText)

mediaModuleHalf (Entity)
  media: (Link: BackgroundVideo|ImageWithAltText)

When running gatsby develop, the above setup errors out with the following error message:

Error: Schema must contain unique named types but contains multiple types named "Union_media___NODE_ContentfulBackgroundVideo__ContentfulImageWithAltText"

I believe the error stems from this: https://github.com/gatsbyjs/gatsby/blob/master/packages/gatsby/src/schema/infer-graphql-type.js#L318. There is no check here to see if this Union type already exists, it appears that it always attempts to create a new Union.

Environment

Gatsby version: 1.9.149
Node.js version: v8.9.4
Operating System: macOS 10.12.1

Actual result

An error is throw

Expected behavior

The Union already exists, so it is reused for this field.

Steps to reproduce

  1. Create 4 types in Contentful, mediaModuleFull, mediaModuleHalf, backgroundVideo, imageWithAltText`
  2. Add a multi-reference field both mediaModuleHalf and mediaModuleFull, named media
  3. Create 2 instances of mediaModuleFull, one with a backgroundVideo linked in media, and 1 with a imageWithAltText linked in media.
  4. Do the same for mediaModuleFull.
  5. Make sure all of this is fully published.
  6. Fire up a Gatsby project with gatsby develop, which is connected to this Contentful space via that gatsby-contentful-source plugin.

...

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions