Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to load a remote Contentful schema. #7837

Open
mjrobinson86 opened this issue May 10, 2022 · 6 comments
Open

Unable to load a remote Contentful schema. #7837

mjrobinson86 opened this issue May 10, 2022 · 6 comments
Labels
core Related to codegen core/cli

Comments

@mjrobinson86
Copy link

Describe the bug

Seemingly without an update to graphql-codegen or any of the associated packages / plugins I am using, the process can no longer load the schema. I am not aware of any changes to Contentful in terms of the service so its a bit of a mystery. I made no updates to versions of graphql-codegen (other than trying to update to latest to see if that resolved the issue) so I'm not sure why it has just suddenly stopped working. I have no changes in my source code since the last successful run so I'm out of ideas...

Really found this to be a useful tool in my workflow so it would be a shame to do without it.

To Reproduce

npm run graphql-codegen (config provided bellow).

  1. My GraphQL schema:

Too large, but could be provided if necessary.

  1. My GraphQL operations:

Too many to list, but could be provided if necessary.

  1. My codegen.yml config file:
{
	"schema": [{
		"https://graphql.contentful.com/content/v1/spaces/***/environments/master": {
			"headers": {
				"Authorization": "Bearer ***"
			}
		}
	}],
	"documents": [
		"**/*.{graphql,gql,js,ts,vue}"
	],
	"generates": {
		"./graphql/types.ts": {
			"plugins": [
				"typescript",
				"typescript-resolvers",
				"typescript-operations"
			]
		},
		"./graphql/operations.ts": {
			"plugins": [
				"typescript-resolvers",
				"typescript-document-nodes"
			]
		}
	}
}

Expected behavior

Codegen process should run as it has previously.

Environment:

  • OS: MacOS Monterey
  • "@graphql-codegen/cli": "2.6.2",
  • "@graphql-codegen/typescript": "2.4.7",
  • "@graphql-codegen/typescript-document-nodes": "2.2.7",
  • "@graphql-codegen/typescript-operations": "2.3.4",
  • "@graphql-codegen/typescript-resolvers": "2.5.4",
  • NodeJS: 16.14.2

Additional context

Terminal output error:

Failed to load schema for "./graphql/operations.ts"
        Failed to load schema from https://graphql.contentful.com/content/v1/spaces/***/environments/master:

        this.splice is not a function
        TypeError: this.splice is not a function
    at HeadersList.append (/Users/***/node_modules/cross-undici-fetch/dist/patch-headers-list.js:44:16)
    at Headers.append (/Users/***/node_modules/undici/lib/fetch/headers.js:215:31)
    at fill (/Users/***/node_modules/undici/lib/fetch/headers.js:72:15)
    at new Headers (/Users/***/node_modules/undici/lib/fetch/headers.js:168:5)
    at new Request (/Users/***/node_modules/cross-undici-fetch/dist/create-node-ponyfill.js:84:29)
    at Object.fetch (/Users/***/node_modules/cross-undici-fetch/dist/create-node-ponyfill.js:116:24)
    at defaultAsyncFetch (/Users/***/node_modules/@graphql-tools/url-loader/index.js:41:29)
    at /Users/***/node_modules/@graphql-tools/url-loader/index.js:492:36
    at new ValueOrPromise (/Users/***/node_modules/value-or-promise/build/main/ValueOrPromise.js:14:21)
    at executor (/Users/***/node_modules/@graphql-tools/url-loader/index.js:460:20)
    
        GraphQL Code Generator supports:
          - ES Modules and CommonJS exports (export as default or named export "schema")
          - Introspection JSON File
          - URL of GraphQL endpoint
          - Multiple files with type definitions (glob expression)
          - String in config file
    
        Try to use one of above options and run codegen again.

NOTE: triple stars represent redacted paths / credentials.

@bartels
Copy link

bartels commented May 11, 2022

I'm seeing the same error trying to load a schema from an apollo-server instance. The error appears to be happening in undici package (sub dependency of codegen). Using version 5.0.0 works fine for me, so some change in that package starting with version 5.1.0 is likely the culprit.

A temporary workaround using yarn resolutions in package.json:

  "resolutions": {
    "undici": "5.0.0"
  }

@mjrobinson86
Copy link
Author

mjrobinson86 commented May 12, 2022

@bartels thanks for this, I had identified where the problem came from but didn't think to provide an override.

After some digging I actually realised I had bumped a version of nuxt3 from rc.1 to rc.3 which resulted in a dedupe of the undici version causing 5.1.1 to be used which then triggered the version mismatch and issue.

I am using npm v8.5.0 so solution was:

"overrides": {
    "@graphql-codegen/cli@2.6.2": {
      "@graphql-tools/apollo-engine-loader@7.2.11": {
        "cross-undici-fetch@0.3.0": {
          "undici": "5.0.0" 
        }
      }
    }
  }

But this effectively mirrors the solution you mentioned.

Thanks again, not the first time I have been caught out with minor version dedupe mismatches...

Not sure if this closes the issue so to speak, but a workaround at least for now.

NOTE: In my case I was in a monorepo context, so this override had to be provided at the monorepo root... bit of a head scratcher at first why this didn't work at the relevant package level but this is currently an undocumented limitation of npm... just to avoid any headaches for anyone else using the setup.

@alexbjorlig
Copy link

alexbjorlig commented Jun 18, 2022

I'm also on a turborepo npm v8.5.0, but the solutions described here don't help. I still get the this.splice is not a function error 🤔

When I run npm ls undici I get:

❯ npm ls undici
<root>
└─┬ @graphql-codegen/cli@2.6.2
  └─┬ @graphql-tools/github-loader@7.2.5
    └─┬ cross-undici-fetch@0.1.33
      └── undici@5.5.1

With the following in overrides:

    "overrides": {
        "@graphql-codegen/cli@2.6.2": {
            "@graphql-tools/github-loader@7.2.5": {
                "cross-undici-fetch@0.1.33": {
                    "undici": "5.0.0"
                }
            }
        }
    }

@Waitak
Copy link

Waitak commented Jun 21, 2022

I've tried the override as described above, but get the following error:

npm ERR! Override for @graphql-codegen/cli@^2.6.2 conflicts with direct dependency

Any words of wisdom?

@alexbjorlig
Copy link

I managed to hack around by simply adding "undici": "5.0.0" as a dev-dependency..... It does not look nice, but keeps the boat rocking

@Waitak
Copy link

Waitak commented Jun 22, 2022

Thank you, that did it.

@charlypoly charlypoly added the core Related to codegen core/cli label Nov 3, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core Related to codegen core/cli
Projects
None yet
Development

No branches or pull requests

5 participants