Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/thin-clowns-punch.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@graphql-codegen/typescript-graphql-request': patch
---

Make graphql-request@v7 peerDep
6 changes: 5 additions & 1 deletion jest.project.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,11 @@ module.exports = ({ dirname, projectMode = true }) => {

return {
...(CI || !projectMode ? {} : { displayName: pkg.name.replace('@graphql-codegen/', '') }),
transform: { '^.+\\.tsx?$': 'babel-jest' },
transform: {
'^.+\\.tsx?$': 'babel-jest',
'/node_modules/graphql-request/.+\\.js$': 'babel-jest',
},
transformIgnorePatterns: ['/node_modules/(?!(graphql-request)/)'],
Copy link
Copy Markdown
Collaborator Author

@eddeee888 eddeee888 May 22, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is required because we use [email protected] in dev to run jest, which uses ESM. Jest can only run CJS by default.

Since graphql-request is ESM, we need to run it through babel-jest:

  • transformIgnorePatterns is used to tell Jest to transform graphql-request in node_modules (node_modules are ignored by default)
  • transform tells Jest to run babel-jest on .js files in graphql-request to turn ESM to CJS

testEnvironment: 'node',
rootDir: dirname,
restoreMocks: true,
Expand Down
5 changes: 3 additions & 2 deletions packages/plugins/typescript/graphql-request/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
},
"peerDependencies": {
"graphql": "^0.8.0 || ^0.9.0 || ^0.10.0 || ^0.11.0 || ^0.12.0 || ^0.13.0 || ^14.0.0 || ^15.0.0 || ^16.0.0",
"graphql-request": "^6.0.0",
"graphql-request": "^6.0.0 || ^7.0.0",
"graphql-tag": "^2.0.0"
},
"dependencies": {
Expand All @@ -50,7 +50,8 @@
"devDependencies": {
"@graphql-codegen/testing": "1.18.3",
"@graphql-tools/schema": "10.0.23",
"graphql-request": "6.0.0"
"graphql-request": "7.2.0",
"node-fetch": "2.7.0"
Copy link
Copy Markdown
Collaborator Author

@eddeee888 eddeee888 May 22, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

graphql-request@6 uses cross-fetch, whilst graphql-request@7 uses native fetch (undici)
undici is built in a way that nock@14 and below does not support (support is coming in nock v15)

So, for tests to work, we need to pass a fetch function that nock supports, because mockGraphQLServer from @graphql-codegen/testing is using [email protected]

},
"publishConfig": {
"directory": "dist",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { GraphQLClient } from 'graphql-request';
import fetch from 'node-fetch'; // FIXME: using `node-fetch` temporarily because `graphql-request@7` uses native fetch, which `[email protected]` from `@graphql-codegen/testing` does not support
import { getSdk } from './graphql-request-sdk.js';

export function runExampleQuery(x: number, y: number) {
const client = new GraphQLClient('http://localhost:4000/graphql');
const client = new GraphQLClient('http://localhost:4000/graphql', { fetch });
const sdk = getSdk(client);
return sdk.Add({ x, y });
}
11 changes: 9 additions & 2 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4593,7 +4593,14 @@ graphql-language-service-utils@^2.7.1:
graphql-language-service-types "^1.8.7"
nullthrows "^1.0.0"

[email protected], "graphql-request@^4.0.0 || ^5.0.0 || ^6.0.0", graphql-request@^6.0.0:
[email protected]:
version "7.2.0"
resolved "https://registry.yarnpkg.com/graphql-request/-/graphql-request-7.2.0.tgz#af4aa25f27a087dd4fc93a4ff54a0f59c4487269"
integrity sha512-0GR7eQHBFYz372u9lxS16cOtEekFlZYB2qOyq8wDvzRmdRSJ0mgUVX1tzNcIzk3G+4NY+mGtSz411wZdeDF/+A==
dependencies:
"@graphql-typed-document-node/core" "^3.2.0"

"graphql-request@^4.0.0 || ^5.0.0 || ^6.0.0", graphql-request@^6.0.0:
version "6.0.0"
resolved "https://registry.yarnpkg.com/graphql-request/-/graphql-request-6.0.0.tgz#9c8b6a0c341f289e049936d03cc9205300faae1c"
integrity sha512-2BmHTuglonjZvmNVw6ZzCfFlW/qkIPds0f+Qdi/Lvjsl3whJg2uvHmSvHnLWhUTEw6zcxPYAHiZoPvSVKOZ7Jw==
Expand Down Expand Up @@ -6052,7 +6059,7 @@ [email protected]:
lodash "^4.17.21"
propagate "^2.0.0"

node-fetch@^2.5.0, node-fetch@^2.6.1, node-fetch@^2.7.0:
node-fetch@2.7.0, node-fetch@^2.5.0, node-fetch@^2.6.1, node-fetch@^2.7.0:
version "2.7.0"
resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-2.7.0.tgz#d0f0fa6e3e2dc1d27efcd8ad99d550bda94d187d"
integrity sha512-c4FRfUm/dbcWZ7U+1Wq0AwCyFL+3nt2bEw05wfxSz+DWpWsitgmSgYmy2dQdWyKC1694ELPqMs/YzUSNozLt8A==
Expand Down