-
Notifications
You must be signed in to change notification settings - Fork 286
/
Copy pathcodegen.ts
108 lines (103 loc) · 3.37 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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
import {CodegenConfig} from '@graphql-codegen/cli';
import {
storefrontApiCustomScalars,
customerAccountApiCustomScalars,
} from './src/codegen.helpers';
const SF_API_VERSION = '2025-01';
const CA_API_VERSION = '2025-01';
const storefrontAPISchema: CodegenConfig['schema'] = {
[`https://hydrogen-preview.myshopify.com/api/${SF_API_VERSION}/graphql.json`]:
{
headers: {
'X-Shopify-Storefront-Access-Token': '3b580e70970c4528da70c98e097c2fa0',
'content-type': 'application/json',
},
},
};
// API Key used is specific for Hydrogen App
const customerAccountAPISchema: CodegenConfig['schema'] = {
[`https://app.myshopify.com/services/graphql/introspection/customer?api_client_api_key=159a99b8a7289a72f68603f2f4de40ac&api_version=${CA_API_VERSION}`]:
{method: 'GET'},
};
const config: CodegenConfig = {
overwrite: true,
generates: {
// The generated base types
'src/storefront-api-types.d.ts': {
schema: storefrontAPISchema,
plugins: [
{
add: {
content: `
/**
* THIS FILE IS AUTO-GENERATED, DO NOT EDIT
* Based on Storefront API ${SF_API_VERSION}
* If changes need to happen to the types defined in this file, then generally the Storefront API needs to update. After it's updated, you can run \`npm run graphql-types\`.
* Except custom Scalars, which are defined in the \`codegen.ts\` file
*/
/* eslint-disable */`,
},
},
{
typescript: {
useTypeImports: true,
// If a default type for a scalar isn't set, then instead of 'any' we set to 'unknown' for better type safety.
defaultScalarType: 'unknown',
useImplementingTypes: true,
enumsAsTypes: true,
// Define how the Storefront API's custom scalars map to TypeScript types
scalars: storefrontApiCustomScalars,
},
},
],
},
// The schema file, which is the local representation of the GraphQL endpoint
'./storefront.schema.json': {
schema: storefrontAPISchema,
plugins: [
{
introspection: {
minify: true,
},
},
],
},
'src/customer-account-api-types.d.ts': {
schema: customerAccountAPISchema,
plugins: [
{
add: {
content: `
/**
* THIS FILE IS AUTO-GENERATED, DO NOT EDIT
* Based on Customer Account API ${CA_API_VERSION}
* If changes need to happen to the types defined in this file, then generally the Storefront API needs to update. After it's updated, you can run \`npm run graphql-types\`.
* Except custom Scalars, which are defined in the \`codegen.ts\` file
*/
/* eslint-disable */`,
},
},
{
typescript: {
useTypeImports: true,
defaultScalarType: 'unknown',
useImplementingTypes: true,
enumsAsTypes: true,
scalars: customerAccountApiCustomScalars,
},
},
],
},
'./customer-account.schema.json': {
schema: customerAccountAPISchema,
plugins: [
{
introspection: {
minify: true,
},
},
],
},
},
};
export default config;