Last active
August 15, 2022 02:08
-
-
Save feliperodriguess/befb67e023b6003c2523d6fa0aa232aa to your computer and use it in GitHub Desktop.
GraphQL CodeGen + React Query + TypeScript
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
schema: http://localhost:3000/graphql | |
documents: "./src/**/*.graphql" | |
generates: | |
./src/graphql/generated.ts: | |
plugins: | |
- typescript | |
- typescript-operations | |
- typescript-react-query | |
config: | |
fetcher: "./utils#fetcher" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"scripts": { | |
"generate": "yarn add @graphql-codegen/cli @graphql-codegen/typescript @graphql-codegen/typescript-operations @graphql-codegen/typescript-react-query -D && graphql-codegen && yarn remove @graphql-codegen/cli @graphql-codegen/typescript @graphql-codegen/typescript-operations @graphql-codegen/typescript-react-query" | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { GraphQLClient } from "graphql-request"; | |
export const client = new GraphQLClient("http://localhost:3000/graphql"); | |
export const fetcher = <TData, TVariables>( | |
query: string, | |
variables?: TVariables, | |
headers?: RequestInit["headers"] | |
) => { | |
return async (): Promise<TData> => | |
client.request<TData, TVariables>(query, variables, headers); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment