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": { 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..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,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, requestHeaders?: RequestInit['headers']) { + return async (): Promise => client.request({ + document: query, + variables, + 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 ee1fae93d..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,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, requestHeaders?: RequestInit['headers']) { + return async (): Promise => client.request({ + document: query, + variables, + requestHeaders + `); expect(out.content).toBeSimilarStringTo(`export const useTestQuery = < TData = TTestQuery, TError = unknown