-
-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathcodegen.ts
More file actions
60 lines (55 loc) · 1.5 KB
/
Copy pathcodegen.ts
File metadata and controls
60 lines (55 loc) · 1.5 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
import fs from "node:fs";
import path from "node:path";
import type { CodegenConfig } from "@graphql-codegen/cli";
const schemaPath = "node_modules/.cache/github-graphql-schema.graphql";
if (process.env.CI || !fs.existsSync(schemaPath)) {
const result = await fetch(
"https://docs.github.com/public/fpt/schema.docs.graphql",
);
if (!result.ok) {
throw new Error(
`Failed to fetch GitHub GraphQL schema: ${result.status} ${result.statusText}`,
);
}
fs.mkdirSync(path.dirname(schemaPath), { recursive: true });
fs.writeFileSync(schemaPath, await result.text());
}
const scalars = {
Base64String: "string",
BigInt: "string",
CustomPropertyValue: "string",
Date: "string",
DateTime: "string",
GitObjectID: "string",
GitRefname: "string",
GitSSHRemote: "string",
GitTimestamp: "string",
HTML: "string",
PreciseDateTime: "string",
URI: "string",
X509Certificate: "string",
};
const config: CodegenConfig = {
schema: schemaPath,
documents: ["src/github/graphql/queries.ts"],
generates: {
"src/github/graphql/generated/types.ts": {
plugins: ["typescript"],
config: {
scalars,
strictScalars: true,
enumsAsTypes: true,
},
},
"src/github/graphql/generated/operations.ts": {
plugins: ["typescript-operations"],
config: {
scalars,
strictScalars: true,
importSchemaTypesFrom: "src/github/graphql/generated/types.ts",
importExtension: ".ts",
},
},
},
};
export default config;