Skip to content

fix(react-query): [email protected] compat #19

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Nov 24, 2022
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
2 changes: 1 addition & 1 deletion .changeset/config.json
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@graphql-codegen/typescript-react-query': patch
---

Fix compatibility of graphql-request fetcher with >5.0
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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