Skip to content

Commit

Permalink
Merge pull request #19 from dotansimha/fix/react-query-graphql-reques…
Browse files Browse the repository at this point in the history
…t-5.1.x
  • Loading branch information
charlypoly committed Nov 24, 2022
2 parents aa1d817 + 032f598 commit 8e29022
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 6 deletions.
2 changes: 1 addition & 1 deletion .changeset/config.json
Expand Up @@ -9,7 +9,7 @@
"changelog": [
"@changesets/changelog-github",
{
"repo": "dotansimha/graphql-code-generator"
"repo": "dotansimha/graphql-code-generator-community"
}
],
"snapshot": {
Expand Down
5 changes: 5 additions & 0 deletions .changeset/shy-timers-lay.md
@@ -0,0 +1,5 @@
---
'@graphql-codegen/typescript-react-query': patch
---

Fix compatibility of graphql-request fetcher with >5.0
Expand Up @@ -14,8 +14,12 @@ export class GraphQLRequestClientFetcher implements FetcherRenderer {

generateFetcherImplementaion(): string {
return `
function fetcher<TData, TVariables>(client: GraphQLClient, query: string, variables?: TVariables, headers?: RequestInit['headers']) {
return async (): Promise<TData> => client.request<TData, TVariables>(query, variables, headers);
function fetcher<TData, TVariables extends { [key: string]: any }>(client: GraphQLClient, query: string, variables?: TVariables, requestHeaders?: RequestInit['headers']) {
return async (): Promise<TData> => client.request({
document: query,
variables,
requestHeaders
});
}`;
}

Expand Down
Expand Up @@ -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<TData, TVariables>(client: GraphQLClient, query: string, variables?: TVariables, headers?: RequestInit['headers']) {
return async (): Promise<TData> => client.request<TData, TVariables>(query, variables, headers);
}`);
.toBeSimilarStringTo(` function fetcher<TData, TVariables extends { [key: string]: any }>(client: GraphQLClient, query: string, variables?: TVariables, requestHeaders?: RequestInit['headers']) {
return async (): Promise<TData> => client.request({
document: query,
variables,
requestHeaders
`);
expect(out.content).toBeSimilarStringTo(`export const useTestQuery = <
TData = TTestQuery,
TError = unknown
Expand Down

0 comments on commit 8e29022

Please sign in to comment.