forked from zeta-chain/docs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcodegen.ts
More file actions
61 lines (54 loc) · 1.67 KB
/
codegen.ts
File metadata and controls
61 lines (54 loc) · 1.67 KB
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
/* eslint-disable import/no-extraneous-dependencies */
/* eslint-disable import/no-default-export */
import { CodegenConfig } from "@graphql-codegen/cli";
import { join } from "path";
require("dotenv").config({ path: join(__dirname, ".env") });
export const CONTENTFUL_CONFIG = {
contentfulGraphqlUrl: process.env.CONTENTFUL_GRAPHQL_URL || "",
contentfulAccessToken: process.env.CONTENTFUL_ACCESS_TOKEN || "",
contentfulRedisUrl: process.env.REDIS_URL || "",
};
export const validateContentfulConfig = () => {
if (!CONTENTFUL_CONFIG.contentfulGraphqlUrl) {
throw new Error("CONTENTFUL_GRAPHQL_URL environment variable is required");
}
if (!CONTENTFUL_CONFIG.contentfulAccessToken) {
throw new Error("CONTENTFUL_ACCESS_TOKEN environment variable is required");
}
};
validateContentfulConfig();
const eslintDisablePlugin = {
add: {
content: "/* eslint-disable */",
},
};
const config: CodegenConfig = {
config: {
skipTypename: false,
namingConvention: {
transformUnderscore: true,
enumValues: "keep",
},
},
overwrite: true,
generates: {
[`src/generated/contentful.graphql.types.ts`]: {
schema: {
[CONTENTFUL_CONFIG.contentfulGraphqlUrl]: {
headers: {
"content-type": "application/json",
Authorization: `Bearer ${CONTENTFUL_CONFIG.contentfulAccessToken}`,
},
},
},
config: {
namingConvention: {
transformUnderscore: false,
},
},
documents: [`**/**/*.graphql.contentful.ts`],
plugins: [eslintDisablePlugin, "typescript", "typescript-operations", "typescript-graphql-request"],
},
},
};
export default config;