Skip to content
Merged
Show file tree
Hide file tree
Changes from 7 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.1.2",
"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,6 +1,7 @@
import { join } from 'path';
import { remove, writeFile } from 'fs-extra';
import { parse } from 'graphql';
// @ts-ignore
import { OperationTypeNode, parse } from 'graphql';
import { codegen } from '@graphql-codegen/core';
import { mockGraphQLServer } from '@graphql-codegen/testing';
import * as TypeScriptPlugin from '@graphql-codegen/typescript';
Expand All @@ -10,6 +11,16 @@ import * as GraphQLRequestPlugin from '../src/index.js';

describe('GraphQL Request Integration', () => {
it('should send requests correctly', async () => {
// @ts-ignore
if (!OperationTypeNode) {
// `OperationTypeNode` is a type in `graphql@15`, but it is a native TS enum in `graphql@16`.
// `graphql-request@7` uses `OperationTypeNode` enum to analyse document.
// So, `graphql-request@7` does not work with `graphql@15`.
//
// This block is a hacky way to skip running this test for `graphql@15`.
return;
}
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Hi @dotansimha , @jasonkuhrt,

For [email protected]:
I observe [email protected] doesn't work with graphql@15 because of the way it uses OperationTypeNode:

Screenshot 2025-05-25 at 12 33 20 am

I'm thinking we could update graphql-request@7 package to drop graphql@15 as peerDep, but looks like graffle is under development, so don't know what the effort to release v7.1.3 is ? Or whther it's possible? 🤔


For this plugin:
This hack is a bit gross but I couldn't find a quick way to stop testing graphql@15 just for this plugin. One way I could think of is to split the test command to have control over which packages to test, and split graphql-request CLI into another CI step.

Keen to hear if you have preferences or ideas!

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Hey @eddeee888 I could make a release to do what you are suggesting by easily. We have a branch called legacy for just this kind of reason.

Do you want to make a PR to it and we can discuss further?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Ah good to know about the legacy branch! I think I can make a PR to that branch tonight

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Yay, new graphql-request version works. Hack removed. I can live with my conscience 😆

Thank you!

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Happy it worked out!


const sdkFileName = 'graphql-request-sdk.ts';
const sdkFilePath = join(__dirname, './test-files', sdkFileName);
const typeDefs = parse(/* GraphQL */ `
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.1.2"
resolved "https://registry.yarnpkg.com/graphql-request/-/graphql-request-7.1.2.tgz#52d7fd6d8d08c9f0b00c84a091376ce9fbdfa945"
integrity sha512-+XE3iuC55C2di5ZUrB4pjgwe+nIQBuXVIK9J98wrVwojzDW3GMdSBZfxUk8l4j9TieIpjpggclxhNEU9ebGF8w==
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
Loading