-
Notifications
You must be signed in to change notification settings - Fork 36
/
types.ts
120 lines (103 loc) · 3.61 KB
/
types.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
109
110
111
112
113
114
115
116
117
118
119
120
export interface GenerateTypescriptOptions {
/**
* A map from custom gql scalar type to its corresponding typescript type
*/
customScalarType?: {
[scalarName: string]: string;
};
/** Tab format, default to 2 */
tabSpaces?: number;
/** A prefix to every generated types. Default to GQL */
typePrefix?: string;
/** Generate types as global */
global?: boolean;
/** Add types under a namespace */
namespace?: string;
/**
* By default, GQL types that implement interfaces will copy all interface field
* E.g:
* interface A { keyA: String! }
* type B implements interface A { keyA: String! keyB: Int! }
* The generated TypeScript of type B will have both keyA and keyB
* Set this option to true to ignore the copy of keyA
*/
minimizeInterfaceImplementation?: boolean;
/** Name of your graphql context type. Default to `any` if not specified */
contextType?: string;
/** Name of your graphql rootValue type, Default to `undefined` if not specified */
rootValueType?: string;
/**
* Import statements at the top of the generated file
* that import your custom scalar type and context type
*/
importStatements?: string[];
/**
* Set optional properties as nullable instead of undefined
* E.g:
* withoutStrict?: string
* withStrict: string|null;
*/
strictNulls?: boolean;
/**
* This option is for resolvers
* If true, the lib will try to guest the most appropriate
* default TResult type of resolvers (instead of default to 'any')
*
* e.g:
* schema { query: Query }
* type Query { users: [Users!] }
* type User { username: String! }
*
* => interface QueryToUsersResolver<TParent = any, TResult = User[] | null> { ... }
* interface UserToUsernameResolver<TParent = any, TResult = string> { ... }
*/
smartTResult?: boolean;
/**
* This option is for resolvers
* If true, the lib will try to guest the most appropriate
* default TParent type of resolvers (instead of default to 'any')
*
* e.g:
* schema { query: Query }
* type Query { users: [Users!] }
* type User { username: String! }
*
* => interface QueryToUsersResolver<TParent = rootValueType, TResult = any> { ... }
* interface UserToUsernameResolver<TParent = User, TResullt = any> { ... }
*/
smartTParent?: boolean;
/**
* This option is for resolvers
* If true, set return type of resolver to `TResult | Promise<TResult>`
* If 'awalys', set return type of resolver to `Promise<TResult>`
*
* e.g: interface QueryToUsersResolver<TParent = any, TResult = any> {
* (parent: TParent, args: {}, context: any, info): TResult extends Promise ? TResult : TResult | Promise<TResult>
* }
*/
asyncResult?: boolean | 'always';
/**
* If true, field resolver of each type will be required, instead of optional
* Useful if you want to ensure all fields are resolved
*/
requireResolverTypes?: boolean;
/**
* If true, generate enum type as string union instead of TypeScript's string enum
*/
noStringEnum?: boolean;
/**
* If true resolver info arguments will be marked as optional
*/
optionalResolverInfo?: boolean;
/**
* If true, enum values are converted to PascalCase.
*/
enumsAsPascalCase?: boolean;
}
export const defaultOptions: GenerateTypescriptOptions = {
tabSpaces: 2,
typePrefix: 'GQL',
contextType: 'any',
rootValueType: 'undefined',
strictNulls: false,
};