From d98ca30cd6b0fe20356c3a4049b17873b397851b Mon Sep 17 00:00:00 2001 From: Charly POLY Date: Tue, 22 Nov 2022 14:03:54 +0100 Subject: [PATCH 1/3] fix(react-query): `graphql-request@5.1.x` compat --- .changeset/shy-timers-lay.md | 5 +++++ .../react-query/src/fetcher-graphql-request.ts | 8 ++++++-- .../typescript/react-query/tests/react-query.spec.ts | 9 ++++++--- 3 files changed, 17 insertions(+), 5 deletions(-) create mode 100644 .changeset/shy-timers-lay.md diff --git a/.changeset/shy-timers-lay.md b/.changeset/shy-timers-lay.md new file mode 100644 index 000000000..4de1fd917 --- /dev/null +++ b/.changeset/shy-timers-lay.md @@ -0,0 +1,5 @@ +--- +'@graphql-codegen/typescript-react-query': patch +--- + +Fix compatibility of graphql-request fetcher with >5.0 diff --git a/packages/plugins/typescript/react-query/src/fetcher-graphql-request.ts b/packages/plugins/typescript/react-query/src/fetcher-graphql-request.ts index c7482903d..ae067f762 100644 --- a/packages/plugins/typescript/react-query/src/fetcher-graphql-request.ts +++ b/packages/plugins/typescript/react-query/src/fetcher-graphql-request.ts @@ -14,8 +14,12 @@ export class GraphQLRequestClientFetcher implements FetcherRenderer { generateFetcherImplementaion(): string { return ` -function fetcher(client: GraphQLClient, query: string, variables?: TVariables, headers?: RequestInit['headers']) { - return async (): Promise => client.request(query, variables, headers); +function fetcher(client: GraphQLClient, query: string, variables?: TVariables, headers?: RequestInit['headers']) { + return async (): Promise => client.request({ + document: query, + variables, + headers + }); }`; } diff --git a/packages/plugins/typescript/react-query/tests/react-query.spec.ts b/packages/plugins/typescript/react-query/tests/react-query.spec.ts index ee1fae93d..cf609897b 100644 --- a/packages/plugins/typescript/react-query/tests/react-query.spec.ts +++ b/packages/plugins/typescript/react-query/tests/react-query.spec.ts @@ -584,9 +584,12 @@ export const useTestMutation = < expect(out.prepend).toContain(`import { GraphQLClient } from 'graphql-request';`); expect(out.prepend).toContain(`import { RequestInit } from 'graphql-request/dist/types.dom';`); expect(out.prepend[3]) - .toBeSimilarStringTo(` function fetcher(client: GraphQLClient, query: string, variables?: TVariables, headers?: RequestInit['headers']) { - return async (): Promise => client.request(query, variables, headers); - }`); + .toBeSimilarStringTo(` function fetcher(client: GraphQLClient, query: string, variables?: TVariables, headers?: RequestInit['headers']) { + return async (): Promise => client.request({ + document: query, + variables, + headers + `); expect(out.content).toBeSimilarStringTo(`export const useTestQuery = < TData = TTestQuery, TError = unknown From d0b17de9b70416e303f2ccf62f6407427a219bd9 Mon Sep 17 00:00:00 2001 From: Charly POLY Date: Wed, 23 Nov 2022 11:03:37 +0100 Subject: [PATCH 2/3] chore(ci): fix changesets config --- .changeset/config.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.changeset/config.json b/.changeset/config.json index 8afd59abd..18e9accaf 100644 --- a/.changeset/config.json +++ b/.changeset/config.json @@ -9,7 +9,7 @@ "changelog": [ "@changesets/changelog-github", { - "repo": "dotansimha/graphql-code-generator" + "repo": "dotansimha/graphql-code-generator-community" } ], "snapshot": { From 032f5989566e895e47322eb1511bad9d07ff6d7e Mon Sep 17 00:00:00 2001 From: Charly POLY Date: Wed, 23 Nov 2022 11:28:56 +0100 Subject: [PATCH 3/3] fix(react-query): fix typo --- .../typescript/react-query/src/fetcher-graphql-request.ts | 4 ++-- .../plugins/typescript/react-query/tests/react-query.spec.ts | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/plugins/typescript/react-query/src/fetcher-graphql-request.ts b/packages/plugins/typescript/react-query/src/fetcher-graphql-request.ts index ae067f762..d0c056ba9 100644 --- a/packages/plugins/typescript/react-query/src/fetcher-graphql-request.ts +++ b/packages/plugins/typescript/react-query/src/fetcher-graphql-request.ts @@ -14,11 +14,11 @@ export class GraphQLRequestClientFetcher implements FetcherRenderer { generateFetcherImplementaion(): string { return ` -function fetcher(client: GraphQLClient, query: string, variables?: TVariables, headers?: RequestInit['headers']) { +function fetcher(client: GraphQLClient, query: string, variables?: TVariables, requestHeaders?: RequestInit['headers']) { return async (): Promise => client.request({ document: query, variables, - headers + requestHeaders }); }`; } diff --git a/packages/plugins/typescript/react-query/tests/react-query.spec.ts b/packages/plugins/typescript/react-query/tests/react-query.spec.ts index cf609897b..2d42d586d 100644 --- a/packages/plugins/typescript/react-query/tests/react-query.spec.ts +++ b/packages/plugins/typescript/react-query/tests/react-query.spec.ts @@ -584,11 +584,11 @@ export const useTestMutation = < expect(out.prepend).toContain(`import { GraphQLClient } from 'graphql-request';`); expect(out.prepend).toContain(`import { RequestInit } from 'graphql-request/dist/types.dom';`); expect(out.prepend[3]) - .toBeSimilarStringTo(` function fetcher(client: GraphQLClient, query: string, variables?: TVariables, headers?: RequestInit['headers']) { + .toBeSimilarStringTo(` function fetcher(client: GraphQLClient, query: string, variables?: TVariables, requestHeaders?: RequestInit['headers']) { return async (): Promise => client.request({ document: query, variables, - headers + requestHeaders `); expect(out.content).toBeSimilarStringTo(`export const useTestQuery = < TData = TTestQuery,