gatsbyjs / gatsby

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

Error: Schema must contain uniquely named types but contains multiple types named "Sys" #26313

Closed MikeyUchiha closed 4 years ago

MikeyUchiha commented 4 years ago

Description

Trying to use a Hasura GraphQL endpoint that has a remote graphql to Contentful throws the error: Error: Schema must contain uniquely named types but contains multiple types named "Sys"

Steps to reproduce

Create a new Space in Contentful. Upload anything in the Media tab. (This is due to a bug when attempting to query.) Head to Settings > API keys and either use the available API Key or create a new one.

Follow the guide below to install a local version of Hasura using docker. https://hasura.io/docs/1.0/graphql/manual/getting-started/docker-simple.html

Or you can use the one-click option for Heroku. (You will need to update the .env file to point to the app URL.) https://hasura.io/docs/1.0/graphql/manual/deployment/deployment-guides/heroku.html#deploy-heroku

Head to your Hasura Console and select the Remote Schema tab at the top. GraphQL Server URL - https://graphql.contentful.com/content/v1/spaces/{your-space-id} Headers - Authorization : Bearer {your-CDA-key-from-contentful}

Here is a link to a minimum reproducible repo: https://github.com/MikeyUchiha/gatsby-source-graphql-bug-repro

Expected result

I am able to see the hasura node in the Gatsby GraphQL endpoint: http://localhost:8000/___graphql

Actual result

I get the error: Error: Schema must contain uniquely named types but contains multiple types named "Sys" and the Gatsby GraphQL endpoint: http://localhost:8000/___graphql does not display the hasura node.

Environment

System: OS: Windows 10 10.0.19041 CPU: (8) x64 Intel(R) Core(TM) i7-4790K CPU @ 4.00GHz Binaries: Node: 12.13.0 - C:\Program Files\nodejs\node.EXE
Yarn: 1.17.3 - ~\AppData\Roaming\npm\yarn.CMD
npm: 6.14.7 - C:\Program Files\nodejs\npm.CMD
Languages: Python: 2.7.17 Browsers: Edge: 44.19041.1.0 npmPackages: gatsby: ^2.24.26 => 2.24.26 gatsby-source-graphql: 2.7.0 => 2.7.0 npmGlobalPackages: gatsby-cli: 2.12.62

pvdz commented 4 years ago

I'm just triaging new issues. One thing I'm wondering is whether this is a problem with graphql or with contentful. Is it possible to post a minimal test case that shows this can be reproduced with just graphql or contentful? Would be most helpful. (sys is a property that Contentful generates for/from its internal data model)

vladar commented 4 years ago

Hi @MikeyUchiha !

Could you provide access to a simple GraphQL API that causes this issue? So that we could reproduce this easily. We need an endpoint URL and auth token. If it's private - you can create a temporary token and send it to me directly via email (will post it in the next message)

In the meantime, you could try the following:

  1. Make sure GraphQL queries work correctly with your Hasura GraphQL schema directly (to eliminate the possibility that this is a Hasura issue)

  2. Try the previous version of the gatsby-source-graphql plugin (2.6.2)

MikeyUchiha commented 4 years ago

@vladar You can use this: https://hasura-test-00001.herokuapp.com/console

It has the Space ID and a temporary API Key for Contentful put in there.

I have included the Git Repository. Just make sure you update the .env file with: HASURA_GRAPHQL_URL=https://hasura-test-00001.herokuapp.com/v1/graphql

  1. Hasura GraphQL works fine.
  2. I will try to use the previous version you mentioned.

@pvdz It's not an issue with Contentful. It's an issue with the Gatsby Source GraphQL Plugin.

MikeyUchiha commented 4 years ago

Using version 2.6.2 didn't help at all.

vladar commented 4 years ago

Thanks for the repro! I can reproduce it. This seems like a dependency issue (multiple versions of the same package thing). Should be fixed by #26392

In the meantime you can work around it by using yarn resolutions. Add this to your package.json:

  "resolutions": {
    "@graphql-tools/wrap": "^6.0.15",
    "@graphql-tools/utils": "^6.0.15",
    "@graphql-tools/links": "^6.0.15"
  },
vladar commented 4 years ago

Also, if you start a new project, consider using https://github.com/vladar/gatsby-graphql-toolkit instead of gatsby-source-graphql as it will be the recommended way to integrate GraphQL APIs with Gatsby in the future. Any feedback is welcome!

vladar commented 4 years ago

Published in gatsby-source-graphql@2.7.1