Skip to content

Instantly share code, notes, and snippets.

@feliperodriguess
Last active August 15, 2022 02:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save feliperodriguess/befb67e023b6003c2523d6fa0aa232aa to your computer and use it in GitHub Desktop.
Save feliperodriguess/befb67e023b6003c2523d6fa0aa232aa to your computer and use it in GitHub Desktop.
GraphQL CodeGen + React Query + TypeScript
schema: http://localhost:3000/graphql
documents: "./src/**/*.graphql"
generates:
./src/graphql/generated.ts:
plugins:
- typescript
- typescript-operations
- typescript-react-query
config:
fetcher: "./utils#fetcher"
{
"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"
}
}
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