-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcodegen.ts
More file actions
57 lines (54 loc) · 1.6 KB
/
codegen.ts
File metadata and controls
57 lines (54 loc) · 1.6 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
import type { CodegenConfig } from "@graphql-codegen/cli";
const scalarModule = "GraphqlBase__Scalars"
const config: CodegenConfig = {
schema: "src/graphql/schema.graphql",
generates: {
"src/graphql/GraphqlBase__Types.res": {
plugins: ["@rescript-graphql-codegen/base-types"],
config: {
scalarModule,
includeEnumAllValuesArray: true,
appendToEnums: `
external toString: t => string = "%identity"
let fromString = {
let base: array<t> => string => option<t> =
%raw(\`allValues => string => allValues.includes(string) ? string : undefined\`)
base(allValues)
}`
},
},
"src/": {
documents: "src/**/*.graphql",
preset: "near-operation-file",
presetConfig: {
extension: ".res",
baseTypesPath: ".",
folder: "__generated__"
},
plugins: ["@rescript-graphql-codegen/operations"],
config: {
baseTypesModule: "GraphqlBase__Types",
scalarModule,
globalNamespace: true,
appendToQueries: `
let use = {
open Apollo.UseQuery
let res: config<variables, t> => return<'variables, 'result> = useQuery(document, ...)
res
}
let useLazy = {
open Apollo.UseLazyQuery
let res: config<variables, t> => (config<variables, t> => promise<return<variables, t>>, return<variables, t>) = useLazyQuery(document, ...)
res
}`,
appendToMutations:`
let use = {
open Apollo.UseMutation
let res: config<variables, t> => (config<variables, t> => promise<fetchResult<t>>, return<variables, t>)= useMutation(document, ...)
res
}`
},
},
},
};
export default config;