deno.land / x / pothos@release-1713397530 / packages / core / fieldUtils / builder.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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
// @ts-nocheckimport { CompatibleTypes, ExposeNullability, FieldKind, FieldNullability, FieldOptionsFromKind, NormalizeArgs, SchemaTypes, TypeParam, } from '../types/index.ts';import RootFieldBuilder from './root.ts';export default class FieldBuilder<Types extends SchemaTypes, ParentShape, Kind extends FieldKind = FieldKind> extends RootFieldBuilder<Types, ParentShape, Kind> { /** * Create a Boolean field from a boolean property on the parent object * @param {string} name - the name of the property on the source object (does not need to match the field name). * @param {object} [options={}] - Options for this field */ exposeBoolean<Name extends CompatibleTypes<Types, ParentShape, "Boolean", true>, ResolveReturnShape, Nullable extends FieldNullability<"Boolean"> = Types["DefaultFieldNullability"]>(name: Name, ...args: NormalizeArgs<[ options: ExposeNullability<Types, "Boolean", ParentShape, Name, Nullable> & Omit<FieldOptionsFromKind<Types, ParentShape, "Boolean", Nullable, {}, Kind, ParentShape, ResolveReturnShape>, "nullable" | "resolve" | "type"> ]>) { const [options = {} as never] = args; return this.exposeField<"Boolean", Nullable, Name>(name, { ...options, type: "Boolean" }); } /** * Create a Float field from a numeric property on the parent object * @param {string} name - the name of the property on the source object (does not need to match the field name). * @param {object} [options={}] - Options for this field */ exposeFloat<Name extends CompatibleTypes<Types, ParentShape, "Float", true>, ResolveReturnShape, Nullable extends FieldNullability<"Float"> = Types["DefaultFieldNullability"]>(name: Name, ...args: NormalizeArgs<[ options: ExposeNullability<Types, "Float", ParentShape, Name, Nullable> & Omit<FieldOptionsFromKind<Types, ParentShape, "Float", Nullable, {}, Kind, ParentShape, ResolveReturnShape>, "nullable" | "resolve" | "type"> ]>) { const [options = {} as never] = args; return this.exposeField<"Float", Nullable, Name>(name, { ...options, type: "Float" }); } /** * Create an ID field from a property on the parent object * @param {string} name - the name of the property on the source object (does not need to match the field name). * @param {object} [options={}] - Options for this field */ exposeID<Name extends CompatibleTypes<Types, ParentShape, "ID", true>, ResolveReturnShape, Nullable extends FieldNullability<"ID"> = Types["DefaultFieldNullability"]>(name: Name, ...args: NormalizeArgs<[ options: ExposeNullability<Types, "ID", ParentShape, Name, Nullable> & Omit<FieldOptionsFromKind<Types, ParentShape, "ID", Nullable, {}, Kind, ParentShape, ResolveReturnShape>, "nullable" | "resolve" | "type"> ]>) { const [options = {} as never] = args; return this.exposeField<"ID", Nullable, Name>(name, { ...options, type: "ID" }); } /** * Create an Int field from a numeric property on the parent object * @param {string} name - the name of the property on the source object (does not need to match the field name). * @param {object} [options={}] - Options for this field */ exposeInt<Name extends CompatibleTypes<Types, ParentShape, "Int", true>, ResolveReturnShape, Nullable extends FieldNullability<"Int"> = Types["DefaultFieldNullability"]>(name: Name, ...args: NormalizeArgs<[ options: ExposeNullability<Types, "Int", ParentShape, Name, Nullable> & Omit<FieldOptionsFromKind<Types, ParentShape, "Int", Nullable, {}, Kind, ParentShape, ResolveReturnShape>, "nullable" | "resolve" | "type"> ]>) { const [options = {} as never] = args; return this.exposeField<"Int", Nullable, Name>(name, { ...options, type: "Int" }); } /** * Create a String field from a string property on the parent object * @param {string} name - the name of the property on the source object (does not need to match the field name). * @param {object} [options={}] - Options for this field */ exposeString<Name extends CompatibleTypes<Types, ParentShape, "String", true>, ResolveReturnShape, Nullable extends FieldNullability<"String"> = Types["DefaultFieldNullability"]>(name: Name, ...args: NormalizeArgs<[ options: ExposeNullability<Types, "String", ParentShape, Name, Nullable> & Omit<FieldOptionsFromKind<Types, ParentShape, "String", Nullable, {}, Kind, ParentShape, ResolveReturnShape>, "nullable" | "resolve" | "type"> ]>) { const [options = {} as never] = args; return this.exposeField<"String", Nullable, Name>(name, { ...options, type: "String" }); } /** * Create a Boolean list field from a boolean[] property on the parent object * @param {string} name - the name of the property on the source object (does not need to match the field name). * @param {object} [options={}] - Options for this field */ exposeBooleanList<Name extends CompatibleTypes<Types, ParentShape, [ "Boolean" ], { list: true; items: true; }>, ResolveReturnShape, Nullable extends FieldNullability<[ "Boolean" ]> = Types["DefaultFieldNullability"]>(name: Name, ...args: NormalizeArgs<[ options: ExposeNullability<Types, [ "Boolean" ], ParentShape, Name, Nullable> & Omit<FieldOptionsFromKind<Types, ParentShape, [ "Boolean" ], Nullable, {}, Kind, ParentShape, ResolveReturnShape>, "nullable" | "resolve" | "type"> ]>) { const [options = {} as never] = args; return this.exposeField<[ "Boolean" ], Nullable, Name>(name, { ...options, type: ["Boolean"] }); } /** * Create a Float list field from a number[] property on the parent object * @param {string} name - the name of the property on the source object (does not need to match the field name). * @param {object} [options={}] - Options for this field */ exposeFloatList<Name extends CompatibleTypes<Types, ParentShape, [ "Float" ], { list: true; items: true; }>, ResolveReturnShape, Nullable extends FieldNullability<[ "Float" ]> = Types["DefaultFieldNullability"]>(name: Name, ...args: NormalizeArgs<[ options: ExposeNullability<Types, [ "Float" ], ParentShape, Name, Nullable> & Omit<FieldOptionsFromKind<Types, ParentShape, [ "Float" ], Nullable, {}, Kind, ParentShape, ResolveReturnShape>, "nullable" | "resolve" | "type"> ]>) { const [options = {} as never] = args; return this.exposeField<[ "Float" ], Nullable, Name>(name, { ...options, type: ["Float"] }); } /** * Create an ID list field from an id[] property on the parent object * @param {string} name - the name of the property on the source object (does not need to match the field name). * @param {object} [options={}] - Options for this field */ exposeIDList<Name extends CompatibleTypes<Types, ParentShape, [ "ID" ], { list: true; items: true; }>, ResolveReturnShape, Nullable extends FieldNullability<[ "ID" ]> = Types["DefaultFieldNullability"]>(name: Name, ...args: NormalizeArgs<[ options: ExposeNullability<Types, [ "ID" ], ParentShape, Name, Nullable> & Omit<FieldOptionsFromKind<Types, ParentShape, [ "ID" ], Nullable, {}, Kind, ParentShape, ResolveReturnShape>, "nullable" | "resolve" | "type"> ]>) { const [options = {} as never] = args; return this.exposeField<[ "ID" ], Nullable, Name>(name, { ...options, type: ["ID"] }); } /** * Create a Int list field from a number[] property on the parent object * @param {string} name - the name of the property on the source object (does not need to match the field name). * @param {object} [options={}] - Options for this field */ exposeIntList<Name extends CompatibleTypes<Types, ParentShape, [ "Int" ], { list: true; items: true; }>, ResolveReturnShape, Nullable extends FieldNullability<[ "Int" ]> = Types["DefaultFieldNullability"]>(name: Name, ...args: NormalizeArgs<[ options: ExposeNullability<Types, [ "Int" ], ParentShape, Name, Nullable> & Omit<FieldOptionsFromKind<Types, ParentShape, [ "Int" ], Nullable, {}, Kind, ParentShape, ResolveReturnShape>, "nullable" | "resolve" | "type"> ]>) { const [options = {} as never] = args; return this.exposeField<[ "Int" ], Nullable, Name>(name, { ...options, type: ["Int"] }); } /** * Create a String list field from a string[] property on the parent object * @param {string} name - the name of the property on the source object (does not need to match the field name). * @param {object} [options={}] - Options for this field */ exposeStringList<Name extends CompatibleTypes<Types, ParentShape, [ "String" ], { list: true; items: true; }>, ResolveReturnShape, Nullable extends FieldNullability<[ "String" ]> = Types["DefaultFieldNullability"]>(name: Name, ...args: NormalizeArgs<[ options: ExposeNullability<Types, [ "String" ], ParentShape, Name, Nullable> & Omit<FieldOptionsFromKind<Types, ParentShape, [ "String" ], Nullable, {}, Kind, ParentShape, ResolveReturnShape>, "nullable" | "resolve" | "type"> ]>) { const [options = {} as never] = args; return this.exposeField<[ "String" ], Nullable, Name>(name, { ...options, type: ["String"] }); } /** * Create a field that resolves to a property of the corresponding type on the parent object * @param {string} name - the name of the property on the source object (does not need to match the field name). * @param {object} [options={}] - Options for this field */ expose<Type extends TypeParam<Types>, Nullable extends FieldNullability<Type>, ResolveReturnShape, Name extends CompatibleTypes<Types, ParentShape, Type, Type extends [ unknown ] ? { list: true; items: true; } : true>>(name: Name extends keyof ParentShape ? Name : keyof ParentShape, ...args: NormalizeArgs<[ options: ExposeNullability<Types, Type, ParentShape, Name, Nullable> & Omit<FieldOptionsFromKind<Types, ParentShape, Type, Nullable, {}, Kind, ParentShape, ResolveReturnShape>, "nullable" | "resolve"> ]>) { const [options = {} as never] = args; return this.exposeField(name as never as CompatibleTypes<Types, ParentShape, Type, Type extends [ unknown ] ? { list: true; items: true; } : true>, options); }}
pothos

Version Info

Tagged at
a year ago