-
Notifications
You must be signed in to change notification settings - Fork 0
/
codegen.ts
50 lines (48 loc) · 1.57 KB
/
codegen.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import type { CodegenConfig } from "@graphql-codegen/cli";
require("dotenv").config();
const config: CodegenConfig = {
// Where your GQL schema is located (could also be externally hosted)
schema: `${process.env.NEXT_PUBLIC_MAGENTO_BACKEND_URL}graphql`,
watch: true,
overwrite: true,
documents: "./src/**/*.gql.ts",
emitLegacyCommonJSImports: false,
generates: {
// Where the generated types and hooks file will be placed
"./src/remote/gql-generated.ts": {
plugins: [
"typescript",
"typescript-operations",
"typescript-react-query",
// Important! The "add" plugin will inject this into our generated file.
// This extends RequestInit['Headers'] to include the Next.js extended "fetch"
// options for caching. This will allow for fine grained cache control
// with our generated hooks.
{
add: {
content: `
type FetchOptions = {
cache?: RequestCache;
next?: NextFetchRequestConfig;
};
type RequestInit = {
headers: (HeadersInit & FetchOptions) | FetchOptions;
};`,
},
},
],
config: {
// Needed to support the updated React Query 5 API
reactQueryVersion: 5,
legacyMode: false,
exposeFetcher: true,
exposeQueryKeys: true,
addSuspenseQuery: true,
// Allows us to specify a custom fetcher function that will leverage
// Next.js caching fetaures within our generated query hooks.
fetcher: "./fetcher#fetcher",
},
},
},
};
export default config;