-
Notifications
You must be signed in to change notification settings - Fork 113
/
codegen.ts
49 lines (45 loc) · 1.26 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
import { CodegenConfig } from "@graphql-codegen/cli";
import { readFile, writeFile } from "fs/promises";
import { format } from "prettier";
const formatFile = async (path: string) => {
const content = await readFile(path, "utf-8");
const formatted = await format(content, { parser: "typescript" });
await writeFile(path, formatted, "utf-8");
};
const endpoint =
process.env.YTF_GRAPHQL_SCHEMA_ENDPOINT ??
"https://staging.yestheory.family/_yesbot-schema";
const config: CodegenConfig = {
overwrite: true,
schema: endpoint,
documents: "./**/*.graphql",
hooks: {
afterAllFileWrite: async (...filePaths: string[]) => {
await Promise.all(filePaths.map(formatFile));
},
},
emitLegacyCommonJSImports: false,
generates: {
"src/__generated__/types.ts": {
plugins: ["@atmina/only-enum-types"],
config: {
scalars: { DateTime: "string" },
},
},
"./": {
preset: "near-operation-file",
presetConfig: {
baseTypesPath: "./src/__generated__/types.ts",
},
plugins: [
"@atmina/local-typescript-operations",
"typescript-graphql-request",
],
config: {
preResolveTypes: true,
gqlImport: "graphql-request#gql",
},
},
},
};
export default config;