@kiwano/core 2.2.0-beta.2 → 3.0.0-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/dist/index.cjs +2250 -0
- package/dist/index.js +2118 -35
- package/dist/{Builder.d.ts → types/Builder.d.ts} +5 -5
- package/dist/{argument.d.ts → types/argument.d.ts} +3 -3
- package/dist/{common.d.ts → types/common.d.ts} +2 -2
- package/dist/{entity → types/entity}/createInputObjectType.d.ts +3 -3
- package/dist/{entity → types/entity}/entitySchema.d.ts +4 -4
- package/dist/{entity → types/entity}/updateInputObjectType.d.ts +3 -3
- package/dist/{enumType.d.ts → types/enumType.d.ts} +3 -3
- package/dist/{enumValue.d.ts → types/enumValue.d.ts} +3 -3
- package/dist/{field.d.ts → types/field.d.ts} +7 -7
- package/dist/{inputField.d.ts → types/inputField.d.ts} +3 -3
- package/dist/{inputObjectType.d.ts → types/inputObjectType.d.ts} +5 -5
- package/dist/{naming → types/naming}/common.d.ts +1 -2
- package/dist/{naming → types/naming}/compact.d.ts +1 -1
- package/dist/{naming → types/naming}/descriptive.d.ts +1 -1
- package/dist/{objectType.d.ts → types/objectType.d.ts} +4 -4
- package/dist/{plugin → types/plugin}/MultiPlugin.d.ts +14 -14
- package/dist/{plugin → types/plugin}/acl/acl.d.ts +5 -5
- package/dist/{plugin → types/plugin}/acl/middleware.d.ts +4 -4
- package/dist/{plugin → types/plugin}/common.d.ts +13 -13
- package/dist/{plugin → types/plugin}/filter/equals.d.ts +5 -5
- package/dist/{plugin → types/plugin}/filter/search.d.ts +3 -3
- package/dist/{plugin → types/plugin}/pagination/connection.d.ts +3 -3
- package/dist/{plugin → types/plugin}/pagination/firstAfter.d.ts +3 -3
- package/dist/{plugin → types/plugin}/pagination/items.d.ts +3 -3
- package/dist/{plugin → types/plugin}/pagination/offsetLimit.d.ts +3 -3
- package/dist/{plugin → types/plugin}/pagination/simple.d.ts +1 -1
- package/dist/{plugin → types/plugin}/sort/sort.d.ts +5 -5
- package/dist/{schema.d.ts → types/schema.d.ts} +9 -9
- package/dist/{unionType.d.ts → types/unionType.d.ts} +3 -3
- package/dist/{util.d.ts → types/util.d.ts} +4 -4
- package/package.json +43 -34
- package/dist/Builder.js +0 -113
- package/dist/argument.js +0 -100
- package/dist/common.js +0 -2
- package/dist/entity/createInputObjectType.js +0 -55
- package/dist/entity/entitySchema.js +0 -212
- package/dist/entity/index.js +0 -24
- package/dist/entity/updateInputObjectType.js +0 -55
- package/dist/enumType.js +0 -126
- package/dist/enumValue.js +0 -60
- package/dist/error/FrameworkError.js +0 -12
- package/dist/error/index.js +0 -18
- package/dist/error/resolver/DataError.js +0 -11
- package/dist/error/resolver/ForbiddenError.js +0 -11
- package/dist/error/resolver/InvalidInputError.js +0 -11
- package/dist/error/resolver/NotFoundError.js +0 -11
- package/dist/error/resolver/ResolverError.js +0 -11
- package/dist/error/resolver/index.js +0 -21
- package/dist/field.js +0 -193
- package/dist/inputField.js +0 -100
- package/dist/inputObjectType.js +0 -119
- package/dist/naming/common.js +0 -2
- package/dist/naming/compact.js +0 -54
- package/dist/naming/descriptive.js +0 -54
- package/dist/naming/index.js +0 -20
- package/dist/naming/util.js +0 -22
- package/dist/objectType.js +0 -140
- package/dist/plugin/MultiPlugin.js +0 -147
- package/dist/plugin/PluginError.js +0 -11
- package/dist/plugin/acl/acl.js +0 -205
- package/dist/plugin/acl/index.js +0 -18
- package/dist/plugin/acl/middleware.js +0 -48
- package/dist/plugin/common.js +0 -2
- package/dist/plugin/filter/equals.js +0 -124
- package/dist/plugin/filter/index.js +0 -18
- package/dist/plugin/filter/search.js +0 -24
- package/dist/plugin/index.js +0 -23
- package/dist/plugin/pagination/connection.js +0 -115
- package/dist/plugin/pagination/firstAfter.js +0 -19
- package/dist/plugin/pagination/index.js +0 -22
- package/dist/plugin/pagination/items.js +0 -78
- package/dist/plugin/pagination/offsetLimit.js +0 -19
- package/dist/plugin/pagination/relay.js +0 -26
- package/dist/plugin/pagination/simple.js +0 -20
- package/dist/plugin/sort/index.js +0 -22
- package/dist/plugin/sort/sort.js +0 -151
- package/dist/schema.js +0 -380
- package/dist/unionType.js +0 -75
- package/dist/util.js +0 -142
- /package/dist/{entity → types/entity}/index.d.ts +0 -0
- /package/dist/{error → types/error}/FrameworkError.d.ts +0 -0
- /package/dist/{error → types/error}/index.d.ts +0 -0
- /package/dist/{error → types/error}/resolver/DataError.d.ts +0 -0
- /package/dist/{error → types/error}/resolver/ForbiddenError.d.ts +0 -0
- /package/dist/{error → types/error}/resolver/InvalidInputError.d.ts +0 -0
- /package/dist/{error → types/error}/resolver/NotFoundError.d.ts +0 -0
- /package/dist/{error → types/error}/resolver/ResolverError.d.ts +0 -0
- /package/dist/{error → types/error}/resolver/index.d.ts +0 -0
- /package/dist/{index.d.ts → types/index.d.ts} +0 -0
- /package/dist/{naming → types/naming}/index.d.ts +0 -0
- /package/dist/{naming → types/naming}/util.d.ts +0 -0
- /package/dist/{plugin → types/plugin}/PluginError.d.ts +0 -0
- /package/dist/{plugin → types/plugin}/acl/index.d.ts +0 -0
- /package/dist/{plugin → types/plugin}/filter/index.d.ts +0 -0
- /package/dist/{plugin → types/plugin}/index.d.ts +0 -0
- /package/dist/{plugin → types/plugin}/pagination/index.d.ts +0 -0
- /package/dist/{plugin → types/plugin}/pagination/relay.d.ts +0 -0
- /package/dist/{plugin → types/plugin}/sort/index.d.ts +0 -0
package/dist/index.js
CHANGED
|
@@ -1,37 +1,2120 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
|
|
1
|
+
import * as __WEBPACK_EXTERNAL_MODULE_es_toolkit_compat_a17790f0__ from "es-toolkit/compat";
|
|
2
|
+
import * as __WEBPACK_EXTERNAL_MODULE__graphql_tools_schema_52352f0c__ from "@graphql-tools/schema";
|
|
3
|
+
import * as __WEBPACK_EXTERNAL_MODULE_graphql_middleware_09574d05__ from "graphql-middleware";
|
|
4
|
+
import * as __WEBPACK_EXTERNAL_MODULE_graphql__ from "graphql";
|
|
5
|
+
import * as __WEBPACK_EXTERNAL_MODULE_graphql_type_definition_0b55c731__ from "graphql/type/definition";
|
|
6
|
+
import * as __WEBPACK_EXTERNAL_MODULE_pluralize__ from "pluralize";
|
|
7
|
+
class FrameworkError extends Error {
|
|
8
|
+
constructor(message, developerInfo){
|
|
9
|
+
super(message);
|
|
10
|
+
this.name = this.constructor.name;
|
|
11
|
+
this.developerInfo = developerInfo;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
const error_FrameworkError = FrameworkError;
|
|
15
|
+
class BuilderError extends error_FrameworkError {
|
|
16
|
+
}
|
|
17
|
+
class Builder {
|
|
18
|
+
use(...plugins) {
|
|
19
|
+
plugins.forEach((plugin)=>this._plugins.push(plugin));
|
|
20
|
+
return this;
|
|
21
|
+
}
|
|
22
|
+
async _executePlugins(methodName, fn) {
|
|
23
|
+
for (const plugin of this._plugins)if (plugin[methodName]) await fn(plugin);
|
|
24
|
+
}
|
|
25
|
+
_executePluginsSync(methodName, fn) {
|
|
26
|
+
for (const plugin of this._plugins)if (plugin[methodName]) fn(plugin);
|
|
27
|
+
}
|
|
28
|
+
get name() {
|
|
29
|
+
return resolveName(this._name);
|
|
30
|
+
}
|
|
31
|
+
async finalize(context) {
|
|
32
|
+
if (this._finalized) return;
|
|
33
|
+
await this.finalizeBuilder(context);
|
|
34
|
+
this._finalized = true;
|
|
35
|
+
}
|
|
36
|
+
constructor(name = null){
|
|
37
|
+
this._plugins = [];
|
|
38
|
+
this._finalized = false;
|
|
39
|
+
this._name = name;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
class BuildContext {
|
|
43
|
+
getType(name) {
|
|
44
|
+
if (this.resolvedTypes.has(name)) return this.resolvedTypes.get(name);
|
|
45
|
+
const typeResult = this.schema.locateType(name, false) ?? this.rootSchema.locateType(name, true);
|
|
46
|
+
if (!typeResult) return null;
|
|
47
|
+
const { type, schema } = typeResult;
|
|
48
|
+
let resolvedType = null;
|
|
49
|
+
if (type instanceof Builder) {
|
|
50
|
+
let context = this;
|
|
51
|
+
if (schema != this.schema) context = new BuildContext(schema, this.rootSchema, this.resolvedTypes);
|
|
52
|
+
resolvedType = type.build(context);
|
|
53
|
+
} else if (type instanceof __WEBPACK_EXTERNAL_MODULE_graphql__.GraphQLScalarType) resolvedType = type;
|
|
54
|
+
if (!resolvedType) throw new BuilderError(`Type ${name} not found`);
|
|
55
|
+
this.resolvedTypes.set(name, resolvedType);
|
|
56
|
+
return resolvedType;
|
|
57
|
+
}
|
|
58
|
+
getResolver(typeName, fieldName) {
|
|
59
|
+
return this.schema.findResolver(typeName, fieldName);
|
|
60
|
+
}
|
|
61
|
+
constructor(schema, rootSchema, resolvedTypes){
|
|
62
|
+
this.schema = schema;
|
|
63
|
+
this.rootSchema = rootSchema;
|
|
64
|
+
this.resolvedTypes = resolvedTypes;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
class FinalizeContext {
|
|
68
|
+
async getType(name) {
|
|
69
|
+
const typeResult = this.schema.locateType(name, false) ?? this.rootSchema.locateType(name, true);
|
|
70
|
+
if (!typeResult) return null;
|
|
71
|
+
const { type, schema } = typeResult;
|
|
72
|
+
if (type instanceof Builder) {
|
|
73
|
+
let context = this;
|
|
74
|
+
if (schema != this.schema) context = new FinalizeContext(schema, this.rootSchema);
|
|
75
|
+
await type.finalize(context);
|
|
76
|
+
}
|
|
77
|
+
return type;
|
|
78
|
+
}
|
|
79
|
+
constructor(schema, rootSchema){
|
|
80
|
+
this.schema = schema;
|
|
81
|
+
this.rootSchema = rootSchema;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
function resolveName(name) {
|
|
85
|
+
return (0, __WEBPACK_EXTERNAL_MODULE_es_toolkit_compat_a17790f0__.isFunction)(name) ? name() : name;
|
|
86
|
+
}
|
|
87
|
+
class EnumValueBuilder extends Builder {
|
|
88
|
+
value(value) {
|
|
89
|
+
this._value = value;
|
|
90
|
+
return this;
|
|
91
|
+
}
|
|
92
|
+
description(description) {
|
|
93
|
+
this._description = description;
|
|
94
|
+
return this;
|
|
95
|
+
}
|
|
96
|
+
extension(name, value) {
|
|
97
|
+
this._extensions.set(name, value);
|
|
98
|
+
return this;
|
|
99
|
+
}
|
|
100
|
+
async finalizeBuilder(context) {
|
|
101
|
+
const info = this.info();
|
|
102
|
+
await this._executePlugins('beforeFinalizeEnumValue', (plugin)=>plugin.beforeFinalizeEnumValue(this, context, info));
|
|
103
|
+
await this.finalizeEnumValue(context, info);
|
|
104
|
+
await this._executePlugins('afterFinalizeEnumValue', (plugin)=>plugin.afterFinalizeEnumValue(this, context, info));
|
|
105
|
+
}
|
|
106
|
+
async finalizeEnumValue(context, info) {}
|
|
107
|
+
build(context) {
|
|
108
|
+
const info = this.info();
|
|
109
|
+
this._executePluginsSync('beforeBuildEnumValue', (plugin)=>plugin.beforeBuildEnumValue(this, context, info));
|
|
110
|
+
const enumValue = {
|
|
111
|
+
value: this._value,
|
|
112
|
+
description: this._description,
|
|
113
|
+
extensions: {
|
|
114
|
+
...Object.fromEntries(this._extensions)
|
|
115
|
+
}
|
|
116
|
+
};
|
|
117
|
+
this._executePluginsSync('afterBuildEnumValue', (plugin)=>plugin.afterBuildEnumValue(this, context, info, enumValue));
|
|
118
|
+
return enumValue;
|
|
119
|
+
}
|
|
120
|
+
info() {
|
|
121
|
+
return {
|
|
122
|
+
name: this.name,
|
|
123
|
+
value: this._value,
|
|
124
|
+
description: this._description,
|
|
125
|
+
extensions: new Map(this._extensions),
|
|
126
|
+
plugins: (0, __WEBPACK_EXTERNAL_MODULE_es_toolkit_compat_a17790f0__.clone)(this._plugins)
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
constructor(name, value = null){
|
|
130
|
+
super(name), this._extensions = new Map();
|
|
131
|
+
this._value = value;
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
function enumValue_enumValue(name, value = null) {
|
|
135
|
+
return new EnumValueBuilder(name, value);
|
|
136
|
+
}
|
|
137
|
+
class EnumTypeBuilder extends Builder {
|
|
138
|
+
description(description) {
|
|
139
|
+
this._description = description;
|
|
140
|
+
return this;
|
|
141
|
+
}
|
|
142
|
+
extension(name, value) {
|
|
143
|
+
this._extensions.set(name, value);
|
|
144
|
+
return this;
|
|
145
|
+
}
|
|
146
|
+
value(builderOrName, value = null, configurator = null) {
|
|
147
|
+
let valueBuilder = null;
|
|
148
|
+
if (builderOrName instanceof EnumValueBuilder) valueBuilder = builderOrName;
|
|
149
|
+
else if ((0, __WEBPACK_EXTERNAL_MODULE_es_toolkit_compat_a17790f0__.isString)(builderOrName)) {
|
|
150
|
+
valueBuilder = new EnumValueBuilder(builderOrName, value);
|
|
151
|
+
if (configurator) configurator(valueBuilder);
|
|
152
|
+
} else throw new BuilderError('Invalid value provided', builderOrName);
|
|
153
|
+
this._values.push(valueBuilder);
|
|
154
|
+
return this;
|
|
155
|
+
}
|
|
156
|
+
valuesObject(object) {
|
|
157
|
+
const keys = Object.keys(object).filter((key)=>isNaN(Number.parseInt(key)));
|
|
158
|
+
for (const key of keys)this.value(key, object[key]);
|
|
159
|
+
}
|
|
160
|
+
async finalizeBuilder(context) {
|
|
161
|
+
const info = this.info();
|
|
162
|
+
await this._executePlugins('beforeFinalizeEnumType', (plugin)=>plugin.beforeFinalizeEnumType(this, context, info));
|
|
163
|
+
await this.finalizeEnumType(context, info);
|
|
164
|
+
await this._executePlugins('afterFinalizeEnumType', (plugin)=>plugin.afterFinalizeEnumType(this, context, info));
|
|
165
|
+
for (const value of this._values)this._plugins.forEach((plugin)=>value.use(plugin));
|
|
166
|
+
for (const value of this._values)await value.finalize(context);
|
|
167
|
+
}
|
|
168
|
+
async finalizeEnumType(context, info) {}
|
|
169
|
+
build(context) {
|
|
170
|
+
const info = this.info();
|
|
171
|
+
this._executePluginsSync('beforeBuildEnumType', (plugin)=>plugin.beforeBuildEnumType(this, context, info));
|
|
172
|
+
const builtValues = {};
|
|
173
|
+
for (const value of this._values)builtValues[value.name] = value.build(context);
|
|
174
|
+
const enumType = new __WEBPACK_EXTERNAL_MODULE_graphql_type_definition_0b55c731__.GraphQLEnumType({
|
|
175
|
+
name: this.name,
|
|
176
|
+
description: this._description,
|
|
177
|
+
values: builtValues,
|
|
178
|
+
extensions: {
|
|
179
|
+
...Object.fromEntries(this._extensions)
|
|
180
|
+
}
|
|
181
|
+
});
|
|
182
|
+
this._executePluginsSync('afterBuildEnumType', (plugin)=>plugin.afterBuildEnumType(this, context, info, enumType));
|
|
183
|
+
return enumType;
|
|
184
|
+
}
|
|
185
|
+
info() {
|
|
186
|
+
return {
|
|
187
|
+
name: this.name,
|
|
188
|
+
description: this._description,
|
|
189
|
+
values: (0, __WEBPACK_EXTERNAL_MODULE_es_toolkit_compat_a17790f0__.clone)(this._values),
|
|
190
|
+
extensions: new Map(this._extensions),
|
|
191
|
+
plugins: (0, __WEBPACK_EXTERNAL_MODULE_es_toolkit_compat_a17790f0__.clone)(this._plugins)
|
|
192
|
+
};
|
|
193
|
+
}
|
|
194
|
+
constructor(name, valuesObject = null){
|
|
195
|
+
super(name), this._values = [], this._extensions = new Map();
|
|
196
|
+
if (valuesObject) this.valuesObject(valuesObject);
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
function enumType_enumType(name, valuesObject = null) {
|
|
200
|
+
return new EnumTypeBuilder(name, valuesObject);
|
|
201
|
+
}
|
|
202
|
+
const ts_enumType = enumType_enumType;
|
|
203
|
+
class InputFieldBuilder extends Builder {
|
|
204
|
+
type(type) {
|
|
205
|
+
const resolvedType = resolveType(type);
|
|
206
|
+
this._type = resolvedType.type;
|
|
207
|
+
if (resolvedType.nonNull) this.nonNull();
|
|
208
|
+
if (resolvedType.list) this.list();
|
|
209
|
+
if (resolvedType.nonNullList) this.nonNullList();
|
|
210
|
+
return this;
|
|
211
|
+
}
|
|
212
|
+
description(description) {
|
|
213
|
+
this._description = description;
|
|
214
|
+
return this;
|
|
215
|
+
}
|
|
216
|
+
extension(name, value) {
|
|
217
|
+
this._extensions.set(name, value);
|
|
218
|
+
return this;
|
|
219
|
+
}
|
|
220
|
+
nonNull(nonNull = true) {
|
|
221
|
+
this._nonNull = nonNull;
|
|
222
|
+
return this;
|
|
223
|
+
}
|
|
224
|
+
list(list = true) {
|
|
225
|
+
this._list = list;
|
|
226
|
+
return this;
|
|
227
|
+
}
|
|
228
|
+
nonNullList(nonNullList = true) {
|
|
229
|
+
if (nonNullList) this.list();
|
|
230
|
+
this._nonNullList = nonNullList;
|
|
231
|
+
return this;
|
|
232
|
+
}
|
|
233
|
+
async finalizeBuilder(context) {
|
|
234
|
+
const info = this.info();
|
|
235
|
+
await this._executePlugins('beforeFinalizeInputField', (plugin)=>plugin.beforeFinalizeInputField(this, context, info));
|
|
236
|
+
await this.finalizeInputField(context, info);
|
|
237
|
+
await this._executePlugins('afterFinalizeInputField', (plugin)=>plugin.afterFinalizeInputField(this, context, info));
|
|
238
|
+
}
|
|
239
|
+
async finalizeInputField(context, info) {}
|
|
240
|
+
build(context) {
|
|
241
|
+
const info = this.info();
|
|
242
|
+
this._executePluginsSync('beforeBuildInputField', (plugin)=>plugin.beforeBuildInputField(this, context, info));
|
|
243
|
+
let type = (0, __WEBPACK_EXTERNAL_MODULE_es_toolkit_compat_a17790f0__.isString)(this._type) ? context.getType(this._type) : this._type;
|
|
244
|
+
if (this._list) {
|
|
245
|
+
if (this._nonNullList) type = new __WEBPACK_EXTERNAL_MODULE_graphql__.GraphQLNonNull(type);
|
|
246
|
+
type = new __WEBPACK_EXTERNAL_MODULE_graphql__.GraphQLList(type);
|
|
247
|
+
}
|
|
248
|
+
if (this._nonNull) type = new __WEBPACK_EXTERNAL_MODULE_graphql__.GraphQLNonNull(type);
|
|
249
|
+
const inputField = {
|
|
250
|
+
type,
|
|
251
|
+
description: this._description,
|
|
252
|
+
extensions: {
|
|
253
|
+
...Object.fromEntries(this._extensions)
|
|
254
|
+
}
|
|
255
|
+
};
|
|
256
|
+
this._executePluginsSync('afterBuildInputField', (plugin)=>plugin.afterBuildInputField(this, context, info, inputField));
|
|
257
|
+
return inputField;
|
|
258
|
+
}
|
|
259
|
+
info() {
|
|
260
|
+
return {
|
|
261
|
+
name: this.name,
|
|
262
|
+
type: this._type,
|
|
263
|
+
description: this._description,
|
|
264
|
+
extensions: new Map(this._extensions),
|
|
265
|
+
nonNull: this._nonNull,
|
|
266
|
+
nonNullList: this._nonNullList,
|
|
267
|
+
list: this._list,
|
|
268
|
+
plugins: (0, __WEBPACK_EXTERNAL_MODULE_es_toolkit_compat_a17790f0__.clone)(this._plugins)
|
|
269
|
+
};
|
|
270
|
+
}
|
|
271
|
+
constructor(name, type){
|
|
272
|
+
super(name), this._extensions = new Map(), this._nonNull = false, this._nonNullList = false, this._list = false;
|
|
273
|
+
this.type(type);
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
function inputField_inputField(name, type) {
|
|
277
|
+
return new InputFieldBuilder(name, type);
|
|
278
|
+
}
|
|
279
|
+
class InputObjectTypeBuilder extends Builder {
|
|
280
|
+
description(description) {
|
|
281
|
+
this._description = description;
|
|
282
|
+
return this;
|
|
283
|
+
}
|
|
284
|
+
extension(name, value) {
|
|
285
|
+
this._extensions.set(name, value);
|
|
286
|
+
return this;
|
|
287
|
+
}
|
|
288
|
+
field(fieldOrName, type = null, configurator = null) {
|
|
289
|
+
let field = null;
|
|
290
|
+
if (fieldOrName instanceof InputFieldBuilder) field = fieldOrName;
|
|
291
|
+
else if ((0, __WEBPACK_EXTERNAL_MODULE_es_toolkit_compat_a17790f0__.isString)(fieldOrName) && type) {
|
|
292
|
+
field = new InputFieldBuilder(fieldOrName, type);
|
|
293
|
+
if (configurator) configurator(field);
|
|
294
|
+
} else throw new BuilderError('Invalid input field provided', fieldOrName);
|
|
295
|
+
this._fields.push(field);
|
|
296
|
+
return this;
|
|
297
|
+
}
|
|
298
|
+
async finalizeBuilder(context) {
|
|
299
|
+
const info = this.info();
|
|
300
|
+
await this._executePlugins('beforeFinalizeInputObjectType', (plugin)=>plugin.beforeFinalizeInputObjectType(this, context, info));
|
|
301
|
+
await this.finalizeInputObjectType(context, info);
|
|
302
|
+
await this._executePlugins('afterFinalizeInputObjectType', (plugin)=>plugin.afterFinalizeInputObjectType(this, context, info));
|
|
303
|
+
for (const field of this._fields)this._plugins.forEach((plugin)=>field.use(plugin));
|
|
304
|
+
for (const field of this._fields)await field.finalize(context);
|
|
305
|
+
}
|
|
306
|
+
async finalizeInputObjectType(context, info) {}
|
|
307
|
+
build(context) {
|
|
308
|
+
const info = this.info();
|
|
309
|
+
this._executePluginsSync('beforeBuildInputObjectType', (plugin)=>plugin.beforeBuildInputObjectType(this, context, info));
|
|
310
|
+
const inputObjectType = new __WEBPACK_EXTERNAL_MODULE_graphql__.GraphQLInputObjectType({
|
|
311
|
+
name: this.name,
|
|
312
|
+
description: this._description,
|
|
313
|
+
extensions: {
|
|
314
|
+
...Object.fromEntries(this._extensions)
|
|
315
|
+
},
|
|
316
|
+
fields: ()=>{
|
|
317
|
+
const builtFields = {};
|
|
318
|
+
for (const field of this._fields)builtFields[field.name] = field.build(context);
|
|
319
|
+
return builtFields;
|
|
320
|
+
}
|
|
321
|
+
});
|
|
322
|
+
this._executePluginsSync('afterBuildInputObjectType', (plugin)=>plugin.afterBuildInputObjectType(this, context, info, inputObjectType));
|
|
323
|
+
return inputObjectType;
|
|
324
|
+
}
|
|
325
|
+
info() {
|
|
326
|
+
return {
|
|
327
|
+
name: this.name,
|
|
328
|
+
description: this._description,
|
|
329
|
+
fields: (0, __WEBPACK_EXTERNAL_MODULE_es_toolkit_compat_a17790f0__.clone)(this._fields),
|
|
330
|
+
extensions: new Map(this._extensions),
|
|
331
|
+
plugins: (0, __WEBPACK_EXTERNAL_MODULE_es_toolkit_compat_a17790f0__.clone)(this._plugins)
|
|
332
|
+
};
|
|
333
|
+
}
|
|
334
|
+
constructor(...args){
|
|
335
|
+
super(...args), this._fields = [], this._extensions = new Map();
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
function inputObjectType_inputObjectType(name) {
|
|
339
|
+
return new InputObjectTypeBuilder(name);
|
|
340
|
+
}
|
|
341
|
+
const ts_inputObjectType = inputObjectType_inputObjectType;
|
|
342
|
+
const defaultScalarNames = [
|
|
343
|
+
'Int',
|
|
344
|
+
'Float',
|
|
345
|
+
'String',
|
|
346
|
+
'Boolean',
|
|
347
|
+
'ID'
|
|
348
|
+
];
|
|
349
|
+
function resolveAutoBuilderArgs(builderOrConfiguratorOrName, configuratorArg, builderType) {
|
|
350
|
+
let builder = null;
|
|
351
|
+
let name = null;
|
|
352
|
+
let configurator = null;
|
|
353
|
+
if (builderOrConfiguratorOrName instanceof builderType) {
|
|
354
|
+
builder = builderOrConfiguratorOrName;
|
|
355
|
+
configurator = configuratorArg;
|
|
356
|
+
} else if ((0, __WEBPACK_EXTERNAL_MODULE_es_toolkit_compat_a17790f0__.isString)(builderOrConfiguratorOrName)) {
|
|
357
|
+
name = builderOrConfiguratorOrName;
|
|
358
|
+
configurator = configuratorArg;
|
|
359
|
+
} else configurator = builderOrConfiguratorOrName;
|
|
360
|
+
return {
|
|
361
|
+
builder,
|
|
362
|
+
name,
|
|
363
|
+
configurator
|
|
364
|
+
};
|
|
365
|
+
}
|
|
366
|
+
function resolveBuilderArgs(builderOrName, configuratorArg, builderType) {
|
|
367
|
+
let builder = null;
|
|
368
|
+
let name = null;
|
|
369
|
+
let configurator = null;
|
|
370
|
+
if (builderOrName instanceof builderType) {
|
|
371
|
+
builder = builderOrName;
|
|
372
|
+
configurator = configuratorArg;
|
|
373
|
+
} else if ((0, __WEBPACK_EXTERNAL_MODULE_es_toolkit_compat_a17790f0__.isString)(builderOrName)) {
|
|
374
|
+
name = builderOrName;
|
|
375
|
+
configurator = configuratorArg;
|
|
376
|
+
}
|
|
377
|
+
return {
|
|
378
|
+
builder,
|
|
379
|
+
name,
|
|
380
|
+
configurator
|
|
381
|
+
};
|
|
382
|
+
}
|
|
383
|
+
function resolveBuilder(args, defaultBuilderGenerator) {
|
|
384
|
+
let resolvedBuilder = args.builder;
|
|
385
|
+
if (!resolvedBuilder) resolvedBuilder = defaultBuilderGenerator(args.name);
|
|
386
|
+
if (args.configurator) args.configurator(resolvedBuilder);
|
|
387
|
+
return resolvedBuilder;
|
|
388
|
+
}
|
|
389
|
+
const nonNullTypePattern = /(.+)!$/;
|
|
390
|
+
const nonNullListTypePattern = /\[(.+)!]/;
|
|
391
|
+
const listTypePattern = /\[(.+)]/;
|
|
392
|
+
const baseTypePattern = /\[?(\w+)]?!?/;
|
|
393
|
+
function resolveType(type) {
|
|
394
|
+
if (!(0, __WEBPACK_EXTERNAL_MODULE_es_toolkit_compat_a17790f0__.isString)(type)) return {
|
|
395
|
+
type,
|
|
396
|
+
nonNull: false,
|
|
397
|
+
nonNullList: false,
|
|
398
|
+
list: false
|
|
399
|
+
};
|
|
400
|
+
const nonNull = nonNullTypePattern.test(type);
|
|
401
|
+
const nonNullList = nonNullListTypePattern.test(type);
|
|
402
|
+
const list = listTypePattern.test(type);
|
|
403
|
+
const baseMatches = baseTypePattern.exec(type);
|
|
404
|
+
return {
|
|
405
|
+
nonNull,
|
|
406
|
+
list,
|
|
407
|
+
nonNullList,
|
|
408
|
+
type: baseMatches[1]
|
|
409
|
+
};
|
|
410
|
+
}
|
|
411
|
+
function isTypeInput(type, schema) {
|
|
412
|
+
if ((0, __WEBPACK_EXTERNAL_MODULE_es_toolkit_compat_a17790f0__.isString)(type)) {
|
|
413
|
+
const typeName = type;
|
|
414
|
+
if (defaultScalarNames.indexOf(typeName) >= 0) return true;
|
|
415
|
+
{
|
|
416
|
+
const builderType = schema.findType(typeName, true);
|
|
417
|
+
if (builderType && (builderType instanceof EnumTypeBuilder || builderType instanceof __WEBPACK_EXTERNAL_MODULE_graphql__.GraphQLScalarType || builderType instanceof InputObjectTypeBuilder)) return true;
|
|
418
|
+
}
|
|
419
|
+
} else if (type instanceof __WEBPACK_EXTERNAL_MODULE_graphql__.GraphQLScalarType || type instanceof __WEBPACK_EXTERNAL_MODULE_graphql_type_definition_0b55c731__.GraphQLEnumType) return true;
|
|
420
|
+
return false;
|
|
421
|
+
}
|
|
422
|
+
function isTypeScalar(type, schema) {
|
|
423
|
+
if ((0, __WEBPACK_EXTERNAL_MODULE_es_toolkit_compat_a17790f0__.isString)(type)) {
|
|
424
|
+
const typeName = type;
|
|
425
|
+
if (defaultScalarNames.indexOf(typeName) >= 0) return true;
|
|
426
|
+
{
|
|
427
|
+
const builderType = schema.findType(typeName, true);
|
|
428
|
+
if (builderType && builderType instanceof __WEBPACK_EXTERNAL_MODULE_graphql__.GraphQLScalarType) return true;
|
|
429
|
+
}
|
|
430
|
+
} else if (type instanceof __WEBPACK_EXTERNAL_MODULE_graphql__.GraphQLScalarType) return true;
|
|
431
|
+
return false;
|
|
432
|
+
}
|
|
433
|
+
function isFieldId(info) {
|
|
434
|
+
return 'ID' === info.type && 'id' === info.name;
|
|
435
|
+
}
|
|
436
|
+
function ensureInstantiated(input, ...args) {
|
|
437
|
+
if ((0, __WEBPACK_EXTERNAL_MODULE_es_toolkit_compat_a17790f0__.isFunction)(input)) try {
|
|
438
|
+
const inputClass = input;
|
|
439
|
+
return new inputClass(...args);
|
|
440
|
+
} catch {}
|
|
441
|
+
return input;
|
|
442
|
+
}
|
|
443
|
+
function getAclExtension(allowed, denied) {
|
|
444
|
+
return {
|
|
445
|
+
allowedRoles: Array.from(allowed).join(','),
|
|
446
|
+
deniedRoles: Array.from(denied).join(',')
|
|
447
|
+
};
|
|
448
|
+
}
|
|
449
|
+
function camelize(text) {
|
|
450
|
+
return text.replace(/^([A-Z])|[\s-_]+(\w)/g, (match, p1, p2)=>{
|
|
451
|
+
if (p2) return p2.toUpperCase();
|
|
452
|
+
return p1.toLowerCase();
|
|
453
|
+
});
|
|
454
|
+
}
|
|
455
|
+
class ArgumentBuilder extends Builder {
|
|
456
|
+
type(type) {
|
|
457
|
+
const resolvedType = resolveType(type);
|
|
458
|
+
this._type = resolvedType.type;
|
|
459
|
+
if (resolvedType.nonNull) this.nonNull();
|
|
460
|
+
if (resolvedType.list) this.list();
|
|
461
|
+
if (resolvedType.nonNullList) this.nonNullList();
|
|
462
|
+
return this;
|
|
463
|
+
}
|
|
464
|
+
description(description) {
|
|
465
|
+
this._description = description;
|
|
466
|
+
return this;
|
|
467
|
+
}
|
|
468
|
+
extension(name, value) {
|
|
469
|
+
this._extensions.set(name, value);
|
|
470
|
+
return this;
|
|
471
|
+
}
|
|
472
|
+
nonNull(nonNull = true) {
|
|
473
|
+
this._nonNull = nonNull;
|
|
474
|
+
return this;
|
|
475
|
+
}
|
|
476
|
+
list(list = true) {
|
|
477
|
+
this._list = list;
|
|
478
|
+
return this;
|
|
479
|
+
}
|
|
480
|
+
nonNullList(nonNullList = true) {
|
|
481
|
+
if (nonNullList) this.list();
|
|
482
|
+
this._nonNullList = nonNullList;
|
|
483
|
+
return this;
|
|
484
|
+
}
|
|
485
|
+
async finalizeBuilder(context) {
|
|
486
|
+
const info = this.info();
|
|
487
|
+
await this._executePlugins('beforeFinalizeArgument', (plugin)=>plugin.beforeFinalizeArgument(this, context, info));
|
|
488
|
+
await this.finalizeArgument(context, info);
|
|
489
|
+
await this._executePlugins('afterFinalizeArgument', (plugin)=>plugin.afterFinalizeArgument(this, context, info));
|
|
490
|
+
}
|
|
491
|
+
async finalizeArgument(context, info) {}
|
|
492
|
+
build(context) {
|
|
493
|
+
const info = this.info();
|
|
494
|
+
this._executePluginsSync('beforeBuildArgument', (plugin)=>plugin.beforeBuildArgument(this, context, info));
|
|
495
|
+
let type = (0, __WEBPACK_EXTERNAL_MODULE_es_toolkit_compat_a17790f0__.isString)(this._type) ? context.getType(this._type) : this._type;
|
|
496
|
+
if (this._list) {
|
|
497
|
+
if (this._nonNullList) type = new __WEBPACK_EXTERNAL_MODULE_graphql__.GraphQLNonNull(type);
|
|
498
|
+
type = new __WEBPACK_EXTERNAL_MODULE_graphql__.GraphQLList(type);
|
|
499
|
+
}
|
|
500
|
+
if (this._nonNull) type = new __WEBPACK_EXTERNAL_MODULE_graphql__.GraphQLNonNull(type);
|
|
501
|
+
const argument = {
|
|
502
|
+
type,
|
|
503
|
+
description: this._description,
|
|
504
|
+
extensions: {
|
|
505
|
+
...Object.fromEntries(this._extensions)
|
|
506
|
+
}
|
|
507
|
+
};
|
|
508
|
+
this._executePluginsSync('afterBuildArgument', (plugin)=>plugin.afterBuildArgument(this, context, info, argument));
|
|
509
|
+
return argument;
|
|
510
|
+
}
|
|
511
|
+
info() {
|
|
512
|
+
return {
|
|
513
|
+
name: this.name,
|
|
514
|
+
type: this._type,
|
|
515
|
+
description: this._description,
|
|
516
|
+
extensions: new Map(this._extensions),
|
|
517
|
+
nonNull: this._nonNull,
|
|
518
|
+
nonNullList: this._nonNullList,
|
|
519
|
+
list: this._list,
|
|
520
|
+
plugins: (0, __WEBPACK_EXTERNAL_MODULE_es_toolkit_compat_a17790f0__.clone)(this._plugins)
|
|
521
|
+
};
|
|
522
|
+
}
|
|
523
|
+
constructor(name, type){
|
|
524
|
+
super(name), this._extensions = new Map(), this._nonNull = false, this._nonNullList = false, this._list = false;
|
|
525
|
+
this.type(type);
|
|
526
|
+
}
|
|
527
|
+
}
|
|
528
|
+
function argument_argument(name, type) {
|
|
529
|
+
return new ArgumentBuilder(name, type);
|
|
530
|
+
}
|
|
531
|
+
class FieldBuilder extends Builder {
|
|
532
|
+
type(type) {
|
|
533
|
+
const resolvedType = resolveType(type);
|
|
534
|
+
this._type = resolvedType.type;
|
|
535
|
+
if (resolvedType.nonNull) this.nonNull();
|
|
536
|
+
if (resolvedType.list) this.list();
|
|
537
|
+
if (resolvedType.nonNullList) this.nonNullList();
|
|
538
|
+
return this;
|
|
539
|
+
}
|
|
540
|
+
description(description) {
|
|
541
|
+
this._description = description;
|
|
542
|
+
return this;
|
|
543
|
+
}
|
|
544
|
+
extension(name, value) {
|
|
545
|
+
this._extensions.set(name, value);
|
|
546
|
+
return this;
|
|
547
|
+
}
|
|
548
|
+
arg(argOrName, type = null, configurator = null) {
|
|
549
|
+
let argument = null;
|
|
550
|
+
if (argOrName instanceof ArgumentBuilder) argument = argOrName;
|
|
551
|
+
else if ((0, __WEBPACK_EXTERNAL_MODULE_es_toolkit_compat_a17790f0__.isString)(argOrName) && type) {
|
|
552
|
+
argument = new ArgumentBuilder(argOrName, type);
|
|
553
|
+
if (configurator) configurator(argument);
|
|
554
|
+
} else throw new BuilderError('Invalid argument provided', argOrName);
|
|
555
|
+
this._arguments.push(argument);
|
|
556
|
+
return this;
|
|
557
|
+
}
|
|
558
|
+
nonNull(nonNull = true) {
|
|
559
|
+
this._nonNull = nonNull;
|
|
560
|
+
return this;
|
|
561
|
+
}
|
|
562
|
+
list(list = true) {
|
|
563
|
+
this._list = list;
|
|
564
|
+
return this;
|
|
565
|
+
}
|
|
566
|
+
nonNullList(nonNullList = true) {
|
|
567
|
+
if (nonNullList) this.list();
|
|
568
|
+
this._nonNullList = nonNullList;
|
|
569
|
+
return this;
|
|
570
|
+
}
|
|
571
|
+
resolver(resolver) {
|
|
572
|
+
this._resolver = resolver;
|
|
573
|
+
return this;
|
|
574
|
+
}
|
|
575
|
+
allow(...roles) {
|
|
576
|
+
roles.forEach((role)=>this._allowedRoles.add(role));
|
|
577
|
+
return this;
|
|
578
|
+
}
|
|
579
|
+
deny(...roles) {
|
|
580
|
+
roles.forEach((role)=>this._deniedRoles.add(role));
|
|
581
|
+
return this;
|
|
582
|
+
}
|
|
583
|
+
includeDeleted(includeDeleted = true) {
|
|
584
|
+
this._includeDeleted = includeDeleted;
|
|
585
|
+
return this;
|
|
586
|
+
}
|
|
587
|
+
async finalizeBuilder(context) {
|
|
588
|
+
const info = this.info();
|
|
589
|
+
await this._executePlugins('beforeFinalizeField', (plugin)=>plugin.beforeFinalizeField(this, context, info));
|
|
590
|
+
await this.finalizeField(context, info);
|
|
591
|
+
await this._executePlugins('afterFinalizeField', (plugin)=>plugin.afterFinalizeField(this, context, info));
|
|
592
|
+
for (const arg of this._arguments)this._plugins.forEach((plugin)=>arg.use(plugin));
|
|
593
|
+
for (const argument of this._arguments)await argument.finalize(context);
|
|
594
|
+
}
|
|
595
|
+
async finalizeField(context, info) {}
|
|
596
|
+
build(context, parentBuilder) {
|
|
597
|
+
if (!parentBuilder) throw new BuilderError('Build: Field needs parent builder argument to be present');
|
|
598
|
+
const info = this.info();
|
|
599
|
+
this._executePluginsSync('beforeBuildField', (plugin)=>plugin.beforeBuildField(this, context, info));
|
|
600
|
+
const builtArgs = {};
|
|
601
|
+
for (const arg of this._arguments)builtArgs[arg.name] = arg.build(context);
|
|
602
|
+
let type = (0, __WEBPACK_EXTERNAL_MODULE_es_toolkit_compat_a17790f0__.isString)(this._type) ? context.getType(this._type) : this._type;
|
|
603
|
+
if (null === type) throw new BuilderError(`Type "${this._type}" of field "${this.name}" not found`);
|
|
604
|
+
if (this._list) {
|
|
605
|
+
if (this._nonNullList) type = new __WEBPACK_EXTERNAL_MODULE_graphql__.GraphQLNonNull(type);
|
|
606
|
+
type = new __WEBPACK_EXTERNAL_MODULE_graphql__.GraphQLList(type);
|
|
607
|
+
}
|
|
608
|
+
if (this._nonNull) type = new __WEBPACK_EXTERNAL_MODULE_graphql__.GraphQLNonNull(type);
|
|
609
|
+
const resolver = this._resolver || context.getResolver(parentBuilder.name, this.name);
|
|
610
|
+
const field = {
|
|
611
|
+
type,
|
|
612
|
+
description: this._description,
|
|
613
|
+
args: builtArgs,
|
|
614
|
+
extensions: {
|
|
615
|
+
...getAclExtension(this._allowedRoles, this._deniedRoles),
|
|
616
|
+
...Object.fromEntries(this._extensions)
|
|
617
|
+
},
|
|
618
|
+
resolve: resolver
|
|
619
|
+
};
|
|
620
|
+
this._executePluginsSync('afterBuildField', (plugin)=>plugin.afterBuildField(this, context, info, field));
|
|
621
|
+
return field;
|
|
622
|
+
}
|
|
623
|
+
info() {
|
|
624
|
+
return {
|
|
625
|
+
name: this.name,
|
|
626
|
+
type: this._type,
|
|
627
|
+
description: this._description,
|
|
628
|
+
arguments: (0, __WEBPACK_EXTERNAL_MODULE_es_toolkit_compat_a17790f0__.clone)(this._arguments),
|
|
629
|
+
extensions: new Map(this._extensions),
|
|
630
|
+
nonNull: this._nonNull,
|
|
631
|
+
nonNullList: this._nonNullList,
|
|
632
|
+
list: this._list,
|
|
633
|
+
includeDeleted: this._includeDeleted,
|
|
634
|
+
allowedRoles: new Set(this._allowedRoles),
|
|
635
|
+
deniedRoles: new Set(this._deniedRoles),
|
|
636
|
+
resolver: this._resolver,
|
|
637
|
+
plugins: (0, __WEBPACK_EXTERNAL_MODULE_es_toolkit_compat_a17790f0__.clone)(this._plugins)
|
|
638
|
+
};
|
|
639
|
+
}
|
|
640
|
+
constructor(name, type = null){
|
|
641
|
+
super(name), this._arguments = [], this._extensions = new Map(), this._nonNull = false, this._nonNullList = false, this._list = false, this._includeDeleted = false, this._allowedRoles = new Set(), this._deniedRoles = new Set();
|
|
642
|
+
this.type(type);
|
|
643
|
+
}
|
|
644
|
+
}
|
|
645
|
+
function field_field(name, type = null) {
|
|
646
|
+
return new FieldBuilder(name, type);
|
|
647
|
+
}
|
|
648
|
+
class ObjectTypeBuilder extends Builder {
|
|
649
|
+
description(description) {
|
|
650
|
+
this._description = description;
|
|
651
|
+
return this;
|
|
652
|
+
}
|
|
653
|
+
extension(name, value) {
|
|
654
|
+
this._extensions.set(name, value);
|
|
655
|
+
return this;
|
|
656
|
+
}
|
|
657
|
+
resolvers(resolvers) {
|
|
658
|
+
this._resolvers = resolvers;
|
|
659
|
+
return this;
|
|
660
|
+
}
|
|
661
|
+
getResolvers() {
|
|
662
|
+
return this._resolvers;
|
|
663
|
+
}
|
|
664
|
+
field(fieldOrName, type = null, configurator = null) {
|
|
665
|
+
let field = null;
|
|
666
|
+
if (fieldOrName instanceof FieldBuilder) field = fieldOrName;
|
|
667
|
+
else if ((0, __WEBPACK_EXTERNAL_MODULE_es_toolkit_compat_a17790f0__.isString)(fieldOrName) && type) {
|
|
668
|
+
field = new FieldBuilder(fieldOrName, type);
|
|
669
|
+
if (configurator) configurator(field);
|
|
670
|
+
} else throw new BuilderError('Invalid field provided', fieldOrName);
|
|
671
|
+
this._fields.push(field);
|
|
672
|
+
return this;
|
|
673
|
+
}
|
|
674
|
+
allow(...roles) {
|
|
675
|
+
roles.forEach((role)=>this._allowedRoles.add(role));
|
|
676
|
+
return this;
|
|
677
|
+
}
|
|
678
|
+
deny(...roles) {
|
|
679
|
+
roles.forEach((role)=>this._deniedRoles.add(role));
|
|
680
|
+
return this;
|
|
681
|
+
}
|
|
682
|
+
async finalizeBuilder(context) {
|
|
683
|
+
const info = this.info();
|
|
684
|
+
await this._executePlugins('beforeFinalizeObjectType', (plugin)=>plugin.beforeFinalizeObjectType(this, context, info));
|
|
685
|
+
await this.finalizeObjectType(context, info);
|
|
686
|
+
await this._executePlugins('afterFinalizeObjectType', (plugin)=>plugin.afterFinalizeObjectType(this, context, info));
|
|
687
|
+
for (const field of this._fields)this._plugins.forEach((plugin)=>field.use(plugin));
|
|
688
|
+
for (const field of this._fields)await field.finalize(context);
|
|
689
|
+
}
|
|
690
|
+
async finalizeObjectType(context, info) {}
|
|
691
|
+
build(context) {
|
|
692
|
+
const info = this.info();
|
|
693
|
+
this._executePluginsSync('beforeBuildObjectType', (plugin)=>plugin.beforeBuildObjectType(this, context, info));
|
|
694
|
+
const objectType = new __WEBPACK_EXTERNAL_MODULE_graphql__.GraphQLObjectType({
|
|
695
|
+
name: this.name,
|
|
696
|
+
description: this._description,
|
|
697
|
+
extensions: {
|
|
698
|
+
...getAclExtension(this._allowedRoles, this._deniedRoles),
|
|
699
|
+
...Object.fromEntries(this._extensions)
|
|
700
|
+
},
|
|
701
|
+
fields: ()=>{
|
|
702
|
+
const builtFields = {};
|
|
703
|
+
for (const field of this._fields)builtFields[field.name] = field.build(context, this);
|
|
704
|
+
return builtFields;
|
|
705
|
+
}
|
|
706
|
+
});
|
|
707
|
+
this._executePluginsSync('afterBuildObjectType', (plugin)=>plugin.afterBuildObjectType(this, context, info, objectType));
|
|
708
|
+
return objectType;
|
|
709
|
+
}
|
|
710
|
+
info() {
|
|
711
|
+
return {
|
|
712
|
+
name: this.name,
|
|
713
|
+
description: this._description,
|
|
714
|
+
fields: (0, __WEBPACK_EXTERNAL_MODULE_es_toolkit_compat_a17790f0__.clone)(this._fields),
|
|
715
|
+
extensions: new Map(this._extensions),
|
|
716
|
+
allowedRoles: new Set(this._allowedRoles),
|
|
717
|
+
deniedRoles: new Set(this._deniedRoles),
|
|
718
|
+
resolvers: this._resolvers,
|
|
719
|
+
plugins: (0, __WEBPACK_EXTERNAL_MODULE_es_toolkit_compat_a17790f0__.clone)(this._plugins)
|
|
720
|
+
};
|
|
721
|
+
}
|
|
722
|
+
constructor(...args){
|
|
723
|
+
super(...args), this._fields = [], this._extensions = new Map(), this._allowedRoles = new Set(), this._deniedRoles = new Set();
|
|
724
|
+
}
|
|
725
|
+
}
|
|
726
|
+
function objectType_objectType(name) {
|
|
727
|
+
return new ObjectTypeBuilder(name);
|
|
728
|
+
}
|
|
729
|
+
const ts_objectType = objectType_objectType;
|
|
730
|
+
class UnionTypeBuilder extends Builder {
|
|
731
|
+
type(...types) {
|
|
732
|
+
types.forEach((role)=>this._types.add(role));
|
|
733
|
+
return this;
|
|
734
|
+
}
|
|
735
|
+
description(description) {
|
|
736
|
+
this._description = description;
|
|
737
|
+
return this;
|
|
738
|
+
}
|
|
739
|
+
extension(name, value) {
|
|
740
|
+
this._extensions.set(name, value);
|
|
741
|
+
return this;
|
|
742
|
+
}
|
|
743
|
+
async finalizeBuilder(context) {
|
|
744
|
+
const info = this.info();
|
|
745
|
+
await this._executePlugins('beforeFinalizeUnionType', (plugin)=>plugin.beforeFinalizeUnionType(this, context, info));
|
|
746
|
+
await this.finalizeUnionType(context, info);
|
|
747
|
+
await this._executePlugins('afterFinalizeUnionType', (plugin)=>plugin.afterFinalizeUnionType(this, context, info));
|
|
748
|
+
}
|
|
749
|
+
async finalizeUnionType(context, info) {}
|
|
750
|
+
build(context) {
|
|
751
|
+
const info = this.info();
|
|
752
|
+
this._executePluginsSync('beforeBuildUnionType', (plugin)=>plugin.beforeBuildUnionType(this, context, info));
|
|
753
|
+
const unionType = new __WEBPACK_EXTERNAL_MODULE_graphql_type_definition_0b55c731__.GraphQLUnionType({
|
|
754
|
+
name: this.name,
|
|
755
|
+
description: this._description,
|
|
756
|
+
types: ()=>{
|
|
757
|
+
const resolvedTypes = [];
|
|
758
|
+
for (const type of this._types)if ((0, __WEBPACK_EXTERNAL_MODULE_es_toolkit_compat_a17790f0__.isString)(type)) {
|
|
759
|
+
const resolved = context.getType(type);
|
|
760
|
+
resolvedTypes.push(resolved);
|
|
761
|
+
} else resolvedTypes.push(type);
|
|
762
|
+
return resolvedTypes;
|
|
763
|
+
},
|
|
764
|
+
extensions: {
|
|
765
|
+
...Object.fromEntries(this._extensions)
|
|
766
|
+
}
|
|
767
|
+
});
|
|
768
|
+
this._executePluginsSync('afterBuildUnionType', (plugin)=>plugin.afterBuildUnionType(this, context, info, unionType));
|
|
769
|
+
return unionType;
|
|
770
|
+
}
|
|
771
|
+
info() {
|
|
772
|
+
return {
|
|
773
|
+
name: this.name,
|
|
774
|
+
types: new Set(this._types),
|
|
775
|
+
description: this._description,
|
|
776
|
+
extensions: new Map(this._extensions),
|
|
777
|
+
plugins: (0, __WEBPACK_EXTERNAL_MODULE_es_toolkit_compat_a17790f0__.clone)(this._plugins)
|
|
778
|
+
};
|
|
779
|
+
}
|
|
780
|
+
constructor(name, types = null){
|
|
781
|
+
super(name), this._extensions = new Map();
|
|
782
|
+
this._types = new Set(types || []);
|
|
783
|
+
}
|
|
784
|
+
}
|
|
785
|
+
function unionType_unionType(name, types = null) {
|
|
786
|
+
return new UnionTypeBuilder(name, types);
|
|
787
|
+
}
|
|
788
|
+
const DefaultScalars = [
|
|
789
|
+
__WEBPACK_EXTERNAL_MODULE_graphql__.GraphQLInt,
|
|
790
|
+
__WEBPACK_EXTERNAL_MODULE_graphql__.GraphQLFloat,
|
|
791
|
+
__WEBPACK_EXTERNAL_MODULE_graphql__.GraphQLString,
|
|
792
|
+
__WEBPACK_EXTERNAL_MODULE_graphql__.GraphQLBoolean,
|
|
793
|
+
__WEBPACK_EXTERNAL_MODULE_graphql__.GraphQLID
|
|
794
|
+
];
|
|
795
|
+
class AbstractSchemaBuilder {
|
|
796
|
+
naming(strategy) {
|
|
797
|
+
this._namingStrategy = strategy;
|
|
798
|
+
return this;
|
|
799
|
+
}
|
|
800
|
+
setDefaultNamingStrategy(strategy) {
|
|
801
|
+
this._defaultNamingStrategy = strategy;
|
|
802
|
+
}
|
|
803
|
+
get namingStrategy() {
|
|
804
|
+
return this._namingStrategy || this._defaultNamingStrategy;
|
|
805
|
+
}
|
|
806
|
+
customConfig(config) {
|
|
807
|
+
this._customConfig = config;
|
|
808
|
+
return this;
|
|
809
|
+
}
|
|
810
|
+
object(objectOrName, configurator = null) {
|
|
811
|
+
const resolvedArgs = resolveBuilderArgs(objectOrName, configurator, ObjectTypeBuilder);
|
|
812
|
+
const resolvedBuilder = resolveBuilder(resolvedArgs, (name)=>new ObjectTypeBuilder(name));
|
|
813
|
+
this._objectTypes.set(resolvedBuilder.name, resolvedBuilder);
|
|
814
|
+
return this;
|
|
815
|
+
}
|
|
816
|
+
getObjectTypes() {
|
|
817
|
+
return (0, __WEBPACK_EXTERNAL_MODULE_es_toolkit_compat_a17790f0__.compact)([
|
|
818
|
+
this._queryObject,
|
|
819
|
+
this._mutationObject,
|
|
820
|
+
...Array.from(this._objectTypes.values())
|
|
821
|
+
]);
|
|
822
|
+
}
|
|
823
|
+
inputObject(objectOrName, configurator = null) {
|
|
824
|
+
const resolvedArgs = resolveBuilderArgs(objectOrName, configurator, InputObjectTypeBuilder);
|
|
825
|
+
const resolvedBuilder = resolveBuilder(resolvedArgs, (name)=>new InputObjectTypeBuilder(name));
|
|
826
|
+
this._inputObjectTypes.set(resolvedBuilder.name, resolvedBuilder);
|
|
827
|
+
return this;
|
|
828
|
+
}
|
|
829
|
+
getInputObjectTypes() {
|
|
830
|
+
return Array.from(this._inputObjectTypes.values());
|
|
831
|
+
}
|
|
832
|
+
enum(enumOrName, configuratorOrValuesObject = null) {
|
|
833
|
+
let builder = null;
|
|
834
|
+
let name = null;
|
|
835
|
+
let configurator = null;
|
|
836
|
+
let valuesObject = null;
|
|
837
|
+
if (enumOrName instanceof EnumTypeBuilder) {
|
|
838
|
+
builder = enumOrName;
|
|
839
|
+
if ((0, __WEBPACK_EXTERNAL_MODULE_es_toolkit_compat_a17790f0__.isFunction)(configuratorOrValuesObject)) configurator = configuratorOrValuesObject;
|
|
840
|
+
} else if ((0, __WEBPACK_EXTERNAL_MODULE_es_toolkit_compat_a17790f0__.isString)(enumOrName)) {
|
|
841
|
+
name = enumOrName;
|
|
842
|
+
if ((0, __WEBPACK_EXTERNAL_MODULE_es_toolkit_compat_a17790f0__.isFunction)(configuratorOrValuesObject)) configurator = configuratorOrValuesObject;
|
|
843
|
+
else valuesObject = configuratorOrValuesObject;
|
|
844
|
+
}
|
|
845
|
+
const resolvedArgs = {
|
|
846
|
+
builder,
|
|
847
|
+
name,
|
|
848
|
+
configurator
|
|
849
|
+
};
|
|
850
|
+
const resolvedBuilder = resolveBuilder(resolvedArgs, (name)=>new EnumTypeBuilder(name, valuesObject));
|
|
851
|
+
this._enumTypes.set(resolvedBuilder.name, resolvedBuilder);
|
|
852
|
+
return this;
|
|
853
|
+
}
|
|
854
|
+
getEnumTypes() {
|
|
855
|
+
return Array.from(this._enumTypes.values());
|
|
856
|
+
}
|
|
857
|
+
union(objectOrName, configuratorOrTypes = null) {
|
|
858
|
+
let builder = null;
|
|
859
|
+
let name = null;
|
|
860
|
+
let configurator = null;
|
|
861
|
+
let resolvedTypes = null;
|
|
862
|
+
if (objectOrName instanceof UnionTypeBuilder) {
|
|
863
|
+
builder = objectOrName;
|
|
864
|
+
if ((0, __WEBPACK_EXTERNAL_MODULE_es_toolkit_compat_a17790f0__.isFunction)(configuratorOrTypes)) configurator = configuratorOrTypes;
|
|
865
|
+
} else if ((0, __WEBPACK_EXTERNAL_MODULE_es_toolkit_compat_a17790f0__.isString)(objectOrName)) {
|
|
866
|
+
name = objectOrName;
|
|
867
|
+
if ((0, __WEBPACK_EXTERNAL_MODULE_es_toolkit_compat_a17790f0__.isFunction)(configuratorOrTypes)) configurator = configuratorOrTypes;
|
|
868
|
+
else if ((0, __WEBPACK_EXTERNAL_MODULE_es_toolkit_compat_a17790f0__.isArray)(configuratorOrTypes)) resolvedTypes = configuratorOrTypes;
|
|
869
|
+
}
|
|
870
|
+
const resolvedArgs = {
|
|
871
|
+
builder,
|
|
872
|
+
name,
|
|
873
|
+
configurator
|
|
874
|
+
};
|
|
875
|
+
const resolvedBuilder = resolveBuilder(resolvedArgs, (name)=>new UnionTypeBuilder(name, resolvedTypes));
|
|
876
|
+
this._unionTypes.set(resolvedBuilder.name, resolvedBuilder);
|
|
877
|
+
return this;
|
|
878
|
+
}
|
|
879
|
+
getUnionTypes() {
|
|
880
|
+
return Array.from(this._unionTypes.values());
|
|
881
|
+
}
|
|
882
|
+
scalar(scalar) {
|
|
883
|
+
this._scalarTypes.set(scalar.name, scalar);
|
|
884
|
+
return this;
|
|
885
|
+
}
|
|
886
|
+
query(fieldOrName, type = null, configurator = null) {
|
|
887
|
+
this._queryObject.field(fieldOrName, type, configurator);
|
|
888
|
+
return this;
|
|
889
|
+
}
|
|
890
|
+
mutation(fieldOrName, type = null, configurator = null) {
|
|
891
|
+
if (!this._mutationObject) this._mutationObject = new ObjectTypeBuilder('Mutation');
|
|
892
|
+
this._mutationObject.field(fieldOrName, type, configurator);
|
|
893
|
+
return this;
|
|
894
|
+
}
|
|
895
|
+
resolvers(resolvers) {
|
|
896
|
+
this._resolvers = resolvers;
|
|
897
|
+
return this;
|
|
898
|
+
}
|
|
899
|
+
queryResolvers(resolvers) {
|
|
900
|
+
this._queryResolvers = resolvers;
|
|
901
|
+
return this;
|
|
902
|
+
}
|
|
903
|
+
mutationResolvers(resolvers) {
|
|
904
|
+
this._mutationResolvers = resolvers;
|
|
905
|
+
return this;
|
|
906
|
+
}
|
|
907
|
+
allow(...roles) {
|
|
908
|
+
roles.forEach((role)=>this._allowedRoles.add(role));
|
|
909
|
+
return this;
|
|
910
|
+
}
|
|
911
|
+
deny(...roles) {
|
|
912
|
+
roles.forEach((role)=>this._deniedRoles.add(role));
|
|
913
|
+
return this;
|
|
914
|
+
}
|
|
915
|
+
allowQuery(...roles) {
|
|
916
|
+
roles.forEach((role)=>this._allowedQueryRoles.add(role));
|
|
917
|
+
return this;
|
|
918
|
+
}
|
|
919
|
+
denyQuery(...roles) {
|
|
920
|
+
roles.forEach((role)=>this._deniedQueryRoles.add(role));
|
|
921
|
+
return this;
|
|
922
|
+
}
|
|
923
|
+
allowMutation(...roles) {
|
|
924
|
+
roles.forEach((role)=>this._allowedMutationRoles.add(role));
|
|
925
|
+
return this;
|
|
926
|
+
}
|
|
927
|
+
denyMutation(...roles) {
|
|
928
|
+
roles.forEach((role)=>this._deniedMutationRoles.add(role));
|
|
929
|
+
return this;
|
|
930
|
+
}
|
|
931
|
+
merge(schema) {
|
|
932
|
+
this._subSchemas.push(schema);
|
|
933
|
+
return this;
|
|
934
|
+
}
|
|
935
|
+
use(...middlewareOrPlugins) {
|
|
936
|
+
for (const item of middlewareOrPlugins)if ((0, __WEBPACK_EXTERNAL_MODULE_es_toolkit_compat_a17790f0__.isObjectLike)(item)) this._plugins.push(item);
|
|
937
|
+
else if ((0, __WEBPACK_EXTERNAL_MODULE_es_toolkit_compat_a17790f0__.isFunction)(item)) this._middleware.push(item);
|
|
938
|
+
return this;
|
|
939
|
+
}
|
|
940
|
+
findType(name, deep = false) {
|
|
941
|
+
var _this_locateType;
|
|
942
|
+
return null === (_this_locateType = this.locateType(name, deep)) || void 0 === _this_locateType ? void 0 : _this_locateType.type;
|
|
943
|
+
}
|
|
944
|
+
locateType(name, deep = false) {
|
|
945
|
+
var _this__mutationObject;
|
|
946
|
+
let type = null;
|
|
947
|
+
type = name === this._queryObject.name ? this._queryObject : name === (null === (_this__mutationObject = this._mutationObject) || void 0 === _this__mutationObject ? void 0 : _this__mutationObject.name) ? this._mutationObject : this._objectTypes.get(name) ?? this._inputObjectTypes.get(name) ?? this._enumTypes.get(name) ?? this._unionTypes.get(name) ?? this._scalarTypes.get(name) ?? null;
|
|
948
|
+
if (!type && deep) for (const sub of this._subSchemas){
|
|
949
|
+
const result = sub.locateType(name, true);
|
|
950
|
+
if (result) return result;
|
|
951
|
+
}
|
|
952
|
+
return type ? {
|
|
953
|
+
schema: this,
|
|
954
|
+
type
|
|
955
|
+
} : null;
|
|
956
|
+
}
|
|
957
|
+
hasType(name, deep = false) {
|
|
958
|
+
return !!this.findType(name, deep);
|
|
959
|
+
}
|
|
960
|
+
findResolver(typeName, fieldName) {
|
|
961
|
+
const resolvers = this.compiledResolvers;
|
|
962
|
+
let resolver = null;
|
|
963
|
+
const typeResolvers = resolvers[typeName];
|
|
964
|
+
if (typeResolvers && typeResolvers[fieldName]) resolver = typeResolvers[fieldName].bind(typeResolvers);
|
|
965
|
+
return resolver;
|
|
966
|
+
}
|
|
967
|
+
get name() {
|
|
968
|
+
return resolveName(this._name);
|
|
969
|
+
}
|
|
970
|
+
get tag() {
|
|
971
|
+
return this._tag;
|
|
972
|
+
}
|
|
973
|
+
async finalize(rootSchema) {
|
|
974
|
+
const resolvedRootSchema = rootSchema || this;
|
|
975
|
+
if (this._namingStrategy) for (const subSchema of this._subSchemas)subSchema.setDefaultNamingStrategy(this._namingStrategy);
|
|
976
|
+
for (const subSchema of this._subSchemas){
|
|
977
|
+
this._plugins.forEach((plugin)=>subSchema.use(plugin));
|
|
978
|
+
this._middleware.forEach((middleware)=>subSchema.use(middleware));
|
|
979
|
+
subSchema.allow(...Array.from(this._allowedRoles));
|
|
980
|
+
subSchema.deny(...Array.from(this._deniedRoles));
|
|
981
|
+
subSchema.allowQuery(...Array.from(this._allowedQueryRoles));
|
|
982
|
+
subSchema.denyQuery(...Array.from(this._deniedQueryRoles));
|
|
983
|
+
subSchema.allowMutation(...Array.from(this._allowedMutationRoles));
|
|
984
|
+
subSchema.denyMutation(...Array.from(this._deniedMutationRoles));
|
|
985
|
+
}
|
|
986
|
+
await this._executePlugins('beforeFinalizeSchema', (plugin)=>plugin.beforeFinalizeSchema(this));
|
|
987
|
+
await this.finalizeSchema();
|
|
988
|
+
await this._executePlugins('afterFinalizeSchema', (plugin)=>plugin.afterFinalizeSchema(this));
|
|
989
|
+
for (const objectType of this.getObjectTypes())this._plugins.forEach((plugin)=>objectType.use(plugin));
|
|
990
|
+
for (const inputObject of this._inputObjectTypes.values())this._plugins.forEach((plugin)=>inputObject.use(plugin));
|
|
991
|
+
for (const unionType of this._unionTypes.values())this._plugins.forEach((plugin)=>unionType.use(plugin));
|
|
992
|
+
for (const enumType of this._enumTypes.values())this._plugins.forEach((plugin)=>enumType.use(plugin));
|
|
993
|
+
for (const objectType of Array.from(this._objectTypes.values()))objectType.allow(...Array.from(this._allowedRoles)).deny(...Array.from(this._deniedRoles));
|
|
994
|
+
const fullAllowedQueryRoles = [
|
|
995
|
+
...Array.from(this._allowedRoles),
|
|
996
|
+
...Array.from(this._allowedQueryRoles)
|
|
997
|
+
];
|
|
998
|
+
const fullDeniedQueryRoles = [
|
|
999
|
+
...Array.from(this._deniedRoles),
|
|
1000
|
+
...Array.from(this._deniedQueryRoles)
|
|
1001
|
+
];
|
|
1002
|
+
for (const queryField of this._queryObject.info().fields)queryField.allow(...fullAllowedQueryRoles).deny(...fullDeniedQueryRoles);
|
|
1003
|
+
if (this._mutationObject) {
|
|
1004
|
+
const fullAllowedMutationRoles = [
|
|
1005
|
+
...Array.from(this._allowedRoles),
|
|
1006
|
+
...Array.from(this._allowedMutationRoles)
|
|
1007
|
+
];
|
|
1008
|
+
const fullDeniedMutationRoles = [
|
|
1009
|
+
...Array.from(this._deniedRoles),
|
|
1010
|
+
...Array.from(this._deniedMutationRoles)
|
|
1011
|
+
];
|
|
1012
|
+
for (const mutationField of this._mutationObject.info().fields)mutationField.allow(...fullAllowedMutationRoles).deny(...fullDeniedMutationRoles);
|
|
1013
|
+
}
|
|
1014
|
+
const finalizeContext = new FinalizeContext(this, resolvedRootSchema);
|
|
1015
|
+
for (const objectType of this.getObjectTypes())await objectType.finalize(finalizeContext);
|
|
1016
|
+
for (const inputObjectType of this._inputObjectTypes.values())await inputObjectType.finalize(finalizeContext);
|
|
1017
|
+
for (const unionType of this._unionTypes.values())await unionType.finalize(finalizeContext);
|
|
1018
|
+
for (const enumType of this._enumTypes.values())await enumType.finalize(finalizeContext);
|
|
1019
|
+
for (const subSchema of this._subSchemas)await subSchema.finalize(resolvedRootSchema);
|
|
1020
|
+
}
|
|
1021
|
+
async finalizeSchema() {}
|
|
1022
|
+
async build() {
|
|
1023
|
+
await this.finalize();
|
|
1024
|
+
this._executePluginsSync('beforeBuild', (plugin)=>plugin.beforeBuild(this));
|
|
1025
|
+
const resolvedTypes = new Map();
|
|
1026
|
+
const schema = await this.buildSchema(resolvedTypes);
|
|
1027
|
+
this._executePluginsSync('afterBuild', (plugin)=>plugin.afterBuild(this, schema));
|
|
1028
|
+
return schema;
|
|
1029
|
+
}
|
|
1030
|
+
async buildSchema(resolvedTypes, rootSchema) {
|
|
1031
|
+
const resolvedRootSchema = rootSchema || this;
|
|
1032
|
+
this._executePluginsSync('beforeBuildSchema', (plugin)=>plugin.beforeBuildSchema(this, resolvedRootSchema));
|
|
1033
|
+
const context = new BuildContext(this, resolvedRootSchema, resolvedTypes);
|
|
1034
|
+
const schemaConfig = {
|
|
1035
|
+
...this._customConfig || {},
|
|
1036
|
+
query: this._queryObject.build(context)
|
|
1037
|
+
};
|
|
1038
|
+
if (this._mutationObject) schemaConfig['mutation'] = this._mutationObject.build(context);
|
|
1039
|
+
const schema = new __WEBPACK_EXTERNAL_MODULE_graphql__.GraphQLSchema(schemaConfig);
|
|
1040
|
+
const fullSchema = (0, __WEBPACK_EXTERNAL_MODULE_graphql_middleware_09574d05__.applyMiddleware)(schema, ...this._middleware);
|
|
1041
|
+
const builtSubSchemas = [];
|
|
1042
|
+
for (const subSchema of this._subSchemas){
|
|
1043
|
+
const builtSchema = await subSchema.buildSchema(resolvedTypes, resolvedRootSchema);
|
|
1044
|
+
builtSubSchemas.push(builtSchema);
|
|
1045
|
+
}
|
|
1046
|
+
const mergedSchema = (0, __WEBPACK_EXTERNAL_MODULE__graphql_tools_schema_52352f0c__.mergeSchemas)({
|
|
1047
|
+
schemas: [
|
|
1048
|
+
fullSchema,
|
|
1049
|
+
...builtSubSchemas
|
|
1050
|
+
]
|
|
1051
|
+
});
|
|
1052
|
+
this._executePluginsSync('afterBuildSchema', (plugin)=>plugin.afterBuildSchema(this, mergedSchema, resolvedRootSchema));
|
|
1053
|
+
return mergedSchema;
|
|
1054
|
+
}
|
|
1055
|
+
get compiledResolvers() {
|
|
1056
|
+
const resolvers = this._resolvers ? (0, __WEBPACK_EXTERNAL_MODULE_es_toolkit_compat_a17790f0__.clone)(this._resolvers) : {};
|
|
1057
|
+
if (this._queryResolvers) resolvers['Query'] = ensureInstantiated(this._queryResolvers);
|
|
1058
|
+
if (this._mutationResolvers && this._mutationObject) resolvers['Mutation'] = ensureInstantiated(this._mutationResolvers);
|
|
1059
|
+
for (const objectType of this._objectTypes.values()){
|
|
1060
|
+
const objectResolvers = objectType.getResolvers();
|
|
1061
|
+
if (objectResolvers) resolvers[objectType.name] = objectResolvers;
|
|
1062
|
+
}
|
|
1063
|
+
return resolvers;
|
|
1064
|
+
}
|
|
1065
|
+
async _executePlugins(methodName, fn) {
|
|
1066
|
+
for (const plugin of this._plugins)if (plugin[methodName]) await fn(plugin);
|
|
1067
|
+
}
|
|
1068
|
+
_executePluginsSync(methodName, fn) {
|
|
1069
|
+
for (const plugin of this._plugins)if (plugin[methodName]) fn(plugin);
|
|
1070
|
+
}
|
|
1071
|
+
_addDefaultScalars() {
|
|
1072
|
+
DefaultScalars.forEach((scalar)=>this.scalar(scalar));
|
|
1073
|
+
}
|
|
1074
|
+
constructor(name = null){
|
|
1075
|
+
this._plugins = [];
|
|
1076
|
+
this._middleware = [];
|
|
1077
|
+
this._subSchemas = [];
|
|
1078
|
+
this._objectTypes = new Map();
|
|
1079
|
+
this._inputObjectTypes = new Map();
|
|
1080
|
+
this._enumTypes = new Map();
|
|
1081
|
+
this._unionTypes = new Map();
|
|
1082
|
+
this._scalarTypes = new Map();
|
|
1083
|
+
this._allowedRoles = new Set();
|
|
1084
|
+
this._deniedRoles = new Set();
|
|
1085
|
+
this._allowedQueryRoles = new Set();
|
|
1086
|
+
this._deniedQueryRoles = new Set();
|
|
1087
|
+
this._allowedMutationRoles = new Set();
|
|
1088
|
+
this._deniedMutationRoles = new Set();
|
|
1089
|
+
this._queryObject = new ObjectTypeBuilder('Query');
|
|
1090
|
+
this._name = name;
|
|
1091
|
+
this._tag = Math.round(1000000 * Math.random());
|
|
1092
|
+
this._addDefaultScalars();
|
|
1093
|
+
}
|
|
1094
|
+
}
|
|
1095
|
+
class SchemaBuilder extends AbstractSchemaBuilder {
|
|
1096
|
+
}
|
|
1097
|
+
function schema_schema(name = null) {
|
|
1098
|
+
return new SchemaBuilder(name);
|
|
1099
|
+
}
|
|
1100
|
+
const ts_schema = schema_schema;
|
|
1101
|
+
class CreateInputObjectTypeBuilder extends InputObjectTypeBuilder {
|
|
1102
|
+
exclude(...fieldNames) {
|
|
1103
|
+
fieldNames.forEach((name)=>this._exclude.add(name));
|
|
1104
|
+
return this;
|
|
1105
|
+
}
|
|
1106
|
+
include(...fieldNames) {
|
|
1107
|
+
fieldNames.forEach((name)=>this._include.add(name));
|
|
1108
|
+
return this;
|
|
1109
|
+
}
|
|
1110
|
+
async finalizeInputObjectType(context, info) {
|
|
1111
|
+
await super.finalizeInputObjectType(context, info);
|
|
1112
|
+
const entity = this._entityObjectType instanceof ObjectTypeBuilder ? this._entityObjectType : this._entityObjectType();
|
|
1113
|
+
const entityInfo = entity.info();
|
|
1114
|
+
const existingFieldNames = info.fields.map((field)=>field.name);
|
|
1115
|
+
for (const field of entityInfo.fields){
|
|
1116
|
+
const fieldInfo = field.info();
|
|
1117
|
+
if (!isTypeInput(fieldInfo.type, context.rootSchema) || isFieldId(fieldInfo) || existingFieldNames.indexOf(fieldInfo.name) >= 0) continue;
|
|
1118
|
+
if (this._exclude.has(fieldInfo.name) || this._include.size > 0 && !this._include.has(fieldInfo.name)) continue;
|
|
1119
|
+
const inputField = new InputFieldBuilder(fieldInfo.name, fieldInfo.type);
|
|
1120
|
+
if (fieldInfo.nonNull) inputField.nonNull();
|
|
1121
|
+
if (fieldInfo.list) inputField.list();
|
|
1122
|
+
if (fieldInfo.nonNullList) inputField.nonNullList();
|
|
1123
|
+
this.field(inputField);
|
|
1124
|
+
}
|
|
1125
|
+
}
|
|
1126
|
+
constructor(name, entityType){
|
|
1127
|
+
super(name), this._exclude = new Set(), this._include = new Set();
|
|
1128
|
+
this._entityObjectType = entityType;
|
|
1129
|
+
}
|
|
1130
|
+
}
|
|
1131
|
+
function createInputObjectType(name, entityType) {
|
|
1132
|
+
return new CreateInputObjectTypeBuilder(name, entityType);
|
|
1133
|
+
}
|
|
1134
|
+
function ucFirst(input) {
|
|
1135
|
+
if (null === input || 0 === input.length) return null;
|
|
1136
|
+
return input.charAt(0).toUpperCase() + input.slice(1);
|
|
1137
|
+
}
|
|
1138
|
+
function lcFirst(input) {
|
|
1139
|
+
if (null === input || 0 === input.length) return null;
|
|
1140
|
+
return input.charAt(0).toLowerCase() + input.slice(1);
|
|
1141
|
+
}
|
|
1142
|
+
class CompactNamingStrategy {
|
|
1143
|
+
entityObject(schemaName) {
|
|
1144
|
+
return ucFirst(schemaName);
|
|
1145
|
+
}
|
|
1146
|
+
allField(schemaName) {
|
|
1147
|
+
return (0, __WEBPACK_EXTERNAL_MODULE_pluralize__["default"])(lcFirst(schemaName));
|
|
1148
|
+
}
|
|
1149
|
+
findField(schemaName) {
|
|
1150
|
+
return lcFirst(schemaName);
|
|
1151
|
+
}
|
|
1152
|
+
createField(schemaName) {
|
|
1153
|
+
return `create${ucFirst(schemaName)}`;
|
|
1154
|
+
}
|
|
1155
|
+
updateField(schemaName) {
|
|
1156
|
+
return `update${ucFirst(schemaName)}`;
|
|
1157
|
+
}
|
|
1158
|
+
deleteField(schemaName) {
|
|
1159
|
+
return `delete${ucFirst(schemaName)}`;
|
|
1160
|
+
}
|
|
1161
|
+
restoreField(schemaName) {
|
|
1162
|
+
return `restore${ucFirst(schemaName)}`;
|
|
1163
|
+
}
|
|
1164
|
+
findFieldIdArgument(schemaName) {
|
|
1165
|
+
return 'id';
|
|
1166
|
+
}
|
|
1167
|
+
deleteFieldIdArgument(schemaName) {
|
|
1168
|
+
return 'id';
|
|
1169
|
+
}
|
|
1170
|
+
restoreFieldIdArgument(schemaName) {
|
|
1171
|
+
return 'id';
|
|
1172
|
+
}
|
|
1173
|
+
createInputObject(schemaName) {
|
|
1174
|
+
return `Create${ucFirst(schemaName)}Input`;
|
|
1175
|
+
}
|
|
1176
|
+
createFieldInputArgument(schemaName) {
|
|
1177
|
+
return 'input';
|
|
1178
|
+
}
|
|
1179
|
+
updateInputObject(schemaName) {
|
|
1180
|
+
return `Update${ucFirst(schemaName)}Input`;
|
|
1181
|
+
}
|
|
1182
|
+
updateFieldInputArgument(schemaName) {
|
|
1183
|
+
return 'input';
|
|
1184
|
+
}
|
|
1185
|
+
}
|
|
1186
|
+
function compactNamingStrategy() {
|
|
1187
|
+
return new CompactNamingStrategy();
|
|
1188
|
+
}
|
|
1189
|
+
class UpdateInputObjectTypeBuilder extends InputObjectTypeBuilder {
|
|
1190
|
+
exclude(...fieldNames) {
|
|
1191
|
+
fieldNames.forEach((name)=>this._exclude.add(name));
|
|
1192
|
+
return this;
|
|
1193
|
+
}
|
|
1194
|
+
include(...fieldNames) {
|
|
1195
|
+
fieldNames.forEach((name)=>this._include.add(name));
|
|
1196
|
+
return this;
|
|
1197
|
+
}
|
|
1198
|
+
async finalizeInputObjectType(context, info) {
|
|
1199
|
+
await super.finalizeInputObjectType(context, info);
|
|
1200
|
+
const entity = this._entityObjectType instanceof ObjectTypeBuilder ? this._entityObjectType : this._entityObjectType();
|
|
1201
|
+
const entityInfo = entity.info();
|
|
1202
|
+
const existingFieldNames = info.fields.map((field)=>field.name);
|
|
1203
|
+
for (const field of entityInfo.fields){
|
|
1204
|
+
const fieldInfo = field.info();
|
|
1205
|
+
if (!isTypeInput(fieldInfo.type, context.rootSchema) || existingFieldNames.indexOf(fieldInfo.name) >= 0) continue;
|
|
1206
|
+
if (this._exclude.has(fieldInfo.name) || this._include.size > 0 && !this._include.has(fieldInfo.name)) continue;
|
|
1207
|
+
const inputField = new InputFieldBuilder(fieldInfo.name, fieldInfo.type);
|
|
1208
|
+
if (isFieldId(fieldInfo)) inputField.nonNull();
|
|
1209
|
+
if (fieldInfo.list) inputField.list();
|
|
1210
|
+
if (fieldInfo.nonNullList) inputField.nonNullList();
|
|
1211
|
+
this.field(inputField);
|
|
1212
|
+
}
|
|
1213
|
+
}
|
|
1214
|
+
constructor(name, entityType){
|
|
1215
|
+
super(name), this._exclude = new Set(), this._include = new Set();
|
|
1216
|
+
this._entityObjectType = entityType;
|
|
1217
|
+
}
|
|
1218
|
+
}
|
|
1219
|
+
function updateInputObjectType_updateInputObjectType(name, entityType) {
|
|
1220
|
+
return new UpdateInputObjectTypeBuilder(name, entityType);
|
|
1221
|
+
}
|
|
1222
|
+
var entitySchema_EntityFieldType = /*#__PURE__*/ function(EntityFieldType) {
|
|
1223
|
+
EntityFieldType["ALL"] = "ALL";
|
|
1224
|
+
EntityFieldType["FIND"] = "FIND";
|
|
1225
|
+
EntityFieldType["CREATE"] = "CREATE";
|
|
1226
|
+
EntityFieldType["UPDATE"] = "UPDATE";
|
|
1227
|
+
EntityFieldType["DELETE"] = "DELETE";
|
|
1228
|
+
EntityFieldType["RESTORE"] = "RESTORE";
|
|
1229
|
+
EntityFieldType["RELATION"] = "RELATION";
|
|
1230
|
+
return EntityFieldType;
|
|
1231
|
+
}({});
|
|
1232
|
+
const entityFieldTypeExtensionName = "$entityFieldType";
|
|
1233
|
+
class AbstractEntitySchemaBuilderBase extends AbstractSchemaBuilder {
|
|
1234
|
+
entity(builderOrConfiguratorOrName, configurator = null) {
|
|
1235
|
+
const resolvedArgs = resolveAutoBuilderArgs(builderOrConfiguratorOrName, configurator, ObjectTypeBuilder);
|
|
1236
|
+
const defaultName = ()=>this.namingStrategy.entityObject(this.name);
|
|
1237
|
+
this._entityObjectType = resolveBuilder(resolvedArgs, (name)=>this.createEntityObjectType(name || defaultName));
|
|
1238
|
+
return this;
|
|
1239
|
+
}
|
|
1240
|
+
all(builderOrConfiguratorOrName = null, configurator = null) {
|
|
1241
|
+
const resolvedArgs = resolveAutoBuilderArgs(builderOrConfiguratorOrName, configurator, FieldBuilder);
|
|
1242
|
+
const defaultName = ()=>this.namingStrategy.allField(this.name);
|
|
1243
|
+
this._allField = resolveBuilder(resolvedArgs, (name)=>this.createAllField(name || defaultName));
|
|
1244
|
+
return this;
|
|
1245
|
+
}
|
|
1246
|
+
find(builderOrConfiguratorOrName = null, configurator = null) {
|
|
1247
|
+
const resolvedArgs = resolveAutoBuilderArgs(builderOrConfiguratorOrName, configurator, FieldBuilder);
|
|
1248
|
+
const defaultName = ()=>this.namingStrategy.findField(this.name);
|
|
1249
|
+
this._findField = resolveBuilder(resolvedArgs, (name)=>this.createFindField(name || defaultName));
|
|
1250
|
+
return this;
|
|
1251
|
+
}
|
|
1252
|
+
create(builderOrConfiguratorOrName = null, configurator = null) {
|
|
1253
|
+
const resolvedArgs = resolveAutoBuilderArgs(builderOrConfiguratorOrName, configurator, FieldBuilder);
|
|
1254
|
+
const defaultName = ()=>this.namingStrategy.createField(this.name);
|
|
1255
|
+
this._createField = resolveBuilder(resolvedArgs, (name)=>this.createCreateField(name || defaultName));
|
|
1256
|
+
return this;
|
|
1257
|
+
}
|
|
1258
|
+
update(builderOrConfiguratorOrName = null, configurator = null) {
|
|
1259
|
+
const resolvedArgs = resolveAutoBuilderArgs(builderOrConfiguratorOrName, configurator, FieldBuilder);
|
|
1260
|
+
const defaultName = ()=>this.namingStrategy.updateField(this.name);
|
|
1261
|
+
this._updateField = resolveBuilder(resolvedArgs, (name)=>this.createUpdateField(name || defaultName));
|
|
1262
|
+
return this;
|
|
1263
|
+
}
|
|
1264
|
+
delete(builderOrConfiguratorOrName = null, configurator = null) {
|
|
1265
|
+
const resolvedArgs = resolveAutoBuilderArgs(builderOrConfiguratorOrName, configurator, FieldBuilder);
|
|
1266
|
+
const defaultName = ()=>this.namingStrategy.deleteField(this.name);
|
|
1267
|
+
this._deleteField = resolveBuilder(resolvedArgs, (name)=>this.createDeleteField(name || defaultName));
|
|
1268
|
+
return this;
|
|
1269
|
+
}
|
|
1270
|
+
restore(builderOrConfiguratorOrName = null, configurator = null) {
|
|
1271
|
+
const resolvedArgs = resolveAutoBuilderArgs(builderOrConfiguratorOrName, configurator, FieldBuilder);
|
|
1272
|
+
const defaultName = ()=>this.namingStrategy.restoreField(this.name);
|
|
1273
|
+
this._restoreField = resolveBuilder(resolvedArgs, (name)=>this.createRestoreField(name || defaultName));
|
|
1274
|
+
return this;
|
|
1275
|
+
}
|
|
1276
|
+
allowEntity(...roles) {
|
|
1277
|
+
roles.forEach((role)=>this._allowedEntityRoles.add(role));
|
|
1278
|
+
return this;
|
|
1279
|
+
}
|
|
1280
|
+
denyEntity(...roles) {
|
|
1281
|
+
roles.forEach((role)=>this._deniedEntityRoles.add(role));
|
|
1282
|
+
return this;
|
|
1283
|
+
}
|
|
1284
|
+
entityResolvers(resolvers) {
|
|
1285
|
+
this._entityResolvers = resolvers;
|
|
1286
|
+
return this;
|
|
1287
|
+
}
|
|
1288
|
+
async finalizeSchema() {
|
|
1289
|
+
await super.finalizeSchema();
|
|
1290
|
+
if (!this._entityObjectType) this._entityObjectType = this.createEntityObjectType(this.namingStrategy.entityObject(this.name));
|
|
1291
|
+
this._entityObjectType.allow(...Array.from(this._allowedEntityRoles)).deny(...Array.from(this._deniedEntityRoles));
|
|
1292
|
+
this.object(this._entityObjectType);
|
|
1293
|
+
if (this._allField) {
|
|
1294
|
+
this._allField.type(this._entityObjectType.name);
|
|
1295
|
+
this._allField.extension(entityFieldTypeExtensionName, "ALL");
|
|
1296
|
+
this.query(this._allField);
|
|
1297
|
+
}
|
|
1298
|
+
if (this._findField) {
|
|
1299
|
+
this._findField.type(this._entityObjectType.name);
|
|
1300
|
+
this._findField.extension(entityFieldTypeExtensionName, "FIND");
|
|
1301
|
+
this.query(this._findField);
|
|
1302
|
+
}
|
|
1303
|
+
if (this._createField) {
|
|
1304
|
+
this._createField.type(this._entityObjectType.name);
|
|
1305
|
+
this._createField.extension(entityFieldTypeExtensionName, "CREATE");
|
|
1306
|
+
this.mutation(this._createField);
|
|
1307
|
+
}
|
|
1308
|
+
if (this._updateField) {
|
|
1309
|
+
this._updateField.type(this._entityObjectType.name);
|
|
1310
|
+
this._updateField.extension(entityFieldTypeExtensionName, "UPDATE");
|
|
1311
|
+
this.mutation(this._updateField);
|
|
1312
|
+
}
|
|
1313
|
+
if (this._deleteField) {
|
|
1314
|
+
this._deleteField.extension(entityFieldTypeExtensionName, "DELETE");
|
|
1315
|
+
this.mutation(this._deleteField);
|
|
1316
|
+
}
|
|
1317
|
+
if (this._restoreField) {
|
|
1318
|
+
this._restoreField.type(this._entityObjectType.name);
|
|
1319
|
+
this._restoreField.extension(entityFieldTypeExtensionName, "RESTORE");
|
|
1320
|
+
this.mutation(this._restoreField);
|
|
1321
|
+
}
|
|
1322
|
+
if (this._entityResolvers) this._resolvers = {
|
|
1323
|
+
[this._entityObjectType.name]: ensureInstantiated(this._entityResolvers),
|
|
1324
|
+
...this._resolvers
|
|
1325
|
+
};
|
|
1326
|
+
}
|
|
1327
|
+
constructor(...args){
|
|
1328
|
+
super(...args), this._allowedEntityRoles = new Set(), this._deniedEntityRoles = new Set();
|
|
1329
|
+
}
|
|
1330
|
+
}
|
|
1331
|
+
class AbstractEntitySchemaBuilder extends AbstractEntitySchemaBuilderBase {
|
|
1332
|
+
createInput(builderOrConfiguratorOrName = null, configurator = null) {
|
|
1333
|
+
const resolvedArgs = resolveAutoBuilderArgs(builderOrConfiguratorOrName, configurator, FieldBuilder);
|
|
1334
|
+
const defaultName = ()=>this.namingStrategy.createInputObject(this.name);
|
|
1335
|
+
this._createInputObject = resolveBuilder(resolvedArgs, (name)=>this.createCreateInputObject(name || defaultName));
|
|
1336
|
+
return this;
|
|
1337
|
+
}
|
|
1338
|
+
updateInput(builderOrConfiguratorOrName = null, configurator = null) {
|
|
1339
|
+
const resolvedArgs = resolveAutoBuilderArgs(builderOrConfiguratorOrName, configurator, FieldBuilder);
|
|
1340
|
+
const defaultName = ()=>this.namingStrategy.updateInputObject(this.name);
|
|
1341
|
+
this._updateInputObject = resolveBuilder(resolvedArgs, (name)=>this.createUpdateInputObject(name || defaultName));
|
|
1342
|
+
return this;
|
|
1343
|
+
}
|
|
1344
|
+
async finalizeSchema() {
|
|
1345
|
+
await super.finalizeSchema();
|
|
1346
|
+
if (this._findField) this._findField.arg(this.namingStrategy.findFieldIdArgument(this.name), 'ID', (_)=>_.nonNull());
|
|
1347
|
+
if (this._deleteField) this._deleteField.arg(this.namingStrategy.deleteFieldIdArgument(this.name), 'ID', (_)=>_.nonNull());
|
|
1348
|
+
if (this._restoreField) this._restoreField.arg(this.namingStrategy.restoreFieldIdArgument(this.name), 'ID', (_)=>_.nonNull());
|
|
1349
|
+
if (this._createField) {
|
|
1350
|
+
if (!this._createInputObject) this._createInputObject = this.createCreateInputObject(this.namingStrategy.createInputObject(this.name));
|
|
1351
|
+
this._createField.arg(this.namingStrategy.createFieldInputArgument(this.name), this._createInputObject.name, (_)=>_.nonNull());
|
|
1352
|
+
}
|
|
1353
|
+
if (this._createInputObject) this.inputObject(this._createInputObject);
|
|
1354
|
+
if (this._updateField) {
|
|
1355
|
+
if (!this._updateInputObject) this._updateInputObject = this.createUpdateInputObject(this.namingStrategy.updateInputObject(this.name));
|
|
1356
|
+
this._updateField.arg(this.namingStrategy.updateFieldInputArgument(this.name), this._updateInputObject.name, (_)=>_.nonNull());
|
|
1357
|
+
}
|
|
1358
|
+
if (this._updateInputObject) this.inputObject(this._updateInputObject);
|
|
1359
|
+
}
|
|
1360
|
+
}
|
|
1361
|
+
class EntitySchemaBuilder extends AbstractEntitySchemaBuilder {
|
|
1362
|
+
createEntityObjectType(name) {
|
|
1363
|
+
return new ObjectTypeBuilder(name);
|
|
1364
|
+
}
|
|
1365
|
+
createAllField(name) {
|
|
1366
|
+
return new FieldBuilder(name).list();
|
|
1367
|
+
}
|
|
1368
|
+
createFindField(name) {
|
|
1369
|
+
return new FieldBuilder(name);
|
|
1370
|
+
}
|
|
1371
|
+
createCreateField(name) {
|
|
1372
|
+
return new FieldBuilder(name);
|
|
1373
|
+
}
|
|
1374
|
+
createUpdateField(name) {
|
|
1375
|
+
return new FieldBuilder(name);
|
|
1376
|
+
}
|
|
1377
|
+
createDeleteField(name) {
|
|
1378
|
+
return new FieldBuilder(name, 'Boolean');
|
|
1379
|
+
}
|
|
1380
|
+
createRestoreField(name) {
|
|
1381
|
+
return new FieldBuilder(name);
|
|
1382
|
+
}
|
|
1383
|
+
createCreateInputObject(name) {
|
|
1384
|
+
return new CreateInputObjectTypeBuilder(name, ()=>this._entityObjectType);
|
|
1385
|
+
}
|
|
1386
|
+
createUpdateInputObject(name) {
|
|
1387
|
+
return new UpdateInputObjectTypeBuilder(name, ()=>this._entityObjectType);
|
|
1388
|
+
}
|
|
1389
|
+
constructor(name = null){
|
|
1390
|
+
super(name);
|
|
1391
|
+
this._defaultNamingStrategy = EntitySchemaBuilder.defaultNamingStrategy;
|
|
1392
|
+
}
|
|
1393
|
+
}
|
|
1394
|
+
EntitySchemaBuilder.defaultNamingStrategy = compactNamingStrategy();
|
|
1395
|
+
function entitySchema_entitySchema(name) {
|
|
1396
|
+
return new EntitySchemaBuilder(name);
|
|
1397
|
+
}
|
|
1398
|
+
class ResolverError extends error_FrameworkError {
|
|
1399
|
+
}
|
|
1400
|
+
const resolver_ResolverError = ResolverError;
|
|
1401
|
+
class ForbiddenError_ForbiddenError extends resolver_ResolverError {
|
|
1402
|
+
}
|
|
1403
|
+
class InvalidInputError extends resolver_ResolverError {
|
|
1404
|
+
}
|
|
1405
|
+
class NotFoundError extends resolver_ResolverError {
|
|
1406
|
+
}
|
|
1407
|
+
class DataError_DataError extends resolver_ResolverError {
|
|
1408
|
+
}
|
|
1409
|
+
class DescriptiveNamingStrategy {
|
|
1410
|
+
entityObject(schemaName) {
|
|
1411
|
+
return ucFirst(schemaName);
|
|
1412
|
+
}
|
|
1413
|
+
allField(schemaName) {
|
|
1414
|
+
return `all${(0, __WEBPACK_EXTERNAL_MODULE_pluralize__["default"])(ucFirst(schemaName))}`;
|
|
1415
|
+
}
|
|
1416
|
+
findField(schemaName) {
|
|
1417
|
+
return `find${ucFirst(schemaName)}`;
|
|
1418
|
+
}
|
|
1419
|
+
createField(schemaName) {
|
|
1420
|
+
return `create${ucFirst(schemaName)}`;
|
|
1421
|
+
}
|
|
1422
|
+
updateField(schemaName) {
|
|
1423
|
+
return `update${ucFirst(schemaName)}`;
|
|
1424
|
+
}
|
|
1425
|
+
deleteField(schemaName) {
|
|
1426
|
+
return `delete${ucFirst(schemaName)}`;
|
|
1427
|
+
}
|
|
1428
|
+
restoreField(schemaName) {
|
|
1429
|
+
return `restore${ucFirst(schemaName)}`;
|
|
1430
|
+
}
|
|
1431
|
+
findFieldIdArgument(schemaName) {
|
|
1432
|
+
return 'id';
|
|
1433
|
+
}
|
|
1434
|
+
deleteFieldIdArgument(schemaName) {
|
|
1435
|
+
return 'id';
|
|
1436
|
+
}
|
|
1437
|
+
restoreFieldIdArgument(schemaName) {
|
|
1438
|
+
return 'id';
|
|
1439
|
+
}
|
|
1440
|
+
createInputObject(schemaName) {
|
|
1441
|
+
return `Create${ucFirst(schemaName)}Input`;
|
|
1442
|
+
}
|
|
1443
|
+
createFieldInputArgument(schemaName) {
|
|
1444
|
+
return 'input';
|
|
1445
|
+
}
|
|
1446
|
+
updateInputObject(schemaName) {
|
|
1447
|
+
return `Update${ucFirst(schemaName)}Input`;
|
|
1448
|
+
}
|
|
1449
|
+
updateFieldInputArgument(schemaName) {
|
|
1450
|
+
return 'input';
|
|
1451
|
+
}
|
|
1452
|
+
}
|
|
1453
|
+
function descriptiveNamingStrategy() {
|
|
1454
|
+
return new DescriptiveNamingStrategy();
|
|
1455
|
+
}
|
|
1456
|
+
const defaultAclMiddlewareOptions = {
|
|
1457
|
+
rolePath: "role",
|
|
1458
|
+
onForbidden: (resource)=>{
|
|
1459
|
+
throw new ForbiddenError_ForbiddenError(`No access to ${resource}`);
|
|
1460
|
+
}
|
|
15
1461
|
};
|
|
16
|
-
|
|
17
|
-
|
|
1462
|
+
function honoAclMiddleware(acl, config = null, options = null) {
|
|
1463
|
+
const fullOptions = getOptions(options);
|
|
1464
|
+
return async (c, next)=>{
|
|
1465
|
+
const fullPath = c.req.path;
|
|
1466
|
+
if (!config) config = {
|
|
1467
|
+
resource: fullPath
|
|
1468
|
+
};
|
|
1469
|
+
const role = c.get(fullOptions.rolePath) ?? null;
|
|
1470
|
+
const allowed = acl.validate(config, role);
|
|
1471
|
+
if (!allowed) fullOptions.onForbidden(fullPath);
|
|
1472
|
+
return await next();
|
|
1473
|
+
};
|
|
1474
|
+
}
|
|
1475
|
+
function graphQLAclMiddleware(acl, schemaName, options = null) {
|
|
1476
|
+
const fullOptions = getOptions(options);
|
|
1477
|
+
return (resolve, root, args, context, info)=>{
|
|
1478
|
+
const pathResource = getPathResource(info.path);
|
|
1479
|
+
const parsedConfig = {
|
|
1480
|
+
resource: `${schemaName}:${pathResource}`
|
|
1481
|
+
};
|
|
1482
|
+
const role = context.get(fullOptions.rolePath) ?? null;
|
|
1483
|
+
const allowed = acl.validate(parsedConfig, role);
|
|
1484
|
+
if (!allowed) fullOptions.onForbidden(pathResource);
|
|
1485
|
+
return resolve(root, args, context, info);
|
|
1486
|
+
};
|
|
1487
|
+
}
|
|
1488
|
+
function getPathResource(path) {
|
|
1489
|
+
return [
|
|
1490
|
+
path.typename,
|
|
1491
|
+
path.key
|
|
1492
|
+
].join('.');
|
|
1493
|
+
}
|
|
1494
|
+
function getOptions(options) {
|
|
1495
|
+
return (0, __WEBPACK_EXTERNAL_MODULE_es_toolkit_compat_a17790f0__.defaults)({}, options || {}, defaultAclMiddlewareOptions);
|
|
1496
|
+
}
|
|
1497
|
+
var acl_AclAction = /*#__PURE__*/ function(AclAction) {
|
|
1498
|
+
AclAction[AclAction["DENY"] = 0] = "DENY";
|
|
1499
|
+
AclAction[AclAction["ALLOW"] = 1] = "ALLOW";
|
|
1500
|
+
return AclAction;
|
|
1501
|
+
}({});
|
|
1502
|
+
const defaultAclOptions = {
|
|
1503
|
+
defaultAction: 0,
|
|
1504
|
+
learn: true
|
|
18
1505
|
};
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
1506
|
+
class AclPlugin {
|
|
1507
|
+
defaultAction(action) {
|
|
1508
|
+
this._options.defaultAction = action;
|
|
1509
|
+
return this;
|
|
1510
|
+
}
|
|
1511
|
+
learn(learn = true) {
|
|
1512
|
+
this._options.learn = learn;
|
|
1513
|
+
return this;
|
|
1514
|
+
}
|
|
1515
|
+
role(identifier, parent = null) {
|
|
1516
|
+
this._roles.set(identifier, {
|
|
1517
|
+
identifier,
|
|
1518
|
+
parent
|
|
1519
|
+
});
|
|
1520
|
+
return this;
|
|
1521
|
+
}
|
|
1522
|
+
allow(resource, roles) {
|
|
1523
|
+
const parsedRoles = new Set((0, __WEBPACK_EXTERNAL_MODULE_es_toolkit_compat_a17790f0__.isArray)(roles) ? roles : [
|
|
1524
|
+
roles
|
|
1525
|
+
]);
|
|
1526
|
+
if (this._options.learn) this._learnRoles(parsedRoles);
|
|
1527
|
+
if (this._allowRules.has(resource)) {
|
|
1528
|
+
const config = this._allowRules.get(resource);
|
|
1529
|
+
parsedRoles.forEach((role)=>config.roles.add(role));
|
|
1530
|
+
} else this._allowRules.set(resource, this._getRuleConfig(resource, parsedRoles));
|
|
1531
|
+
return this;
|
|
1532
|
+
}
|
|
1533
|
+
deny(resource, roles) {
|
|
1534
|
+
const parsedRoles = new Set((0, __WEBPACK_EXTERNAL_MODULE_es_toolkit_compat_a17790f0__.isArray)(roles) ? roles : [
|
|
1535
|
+
roles
|
|
1536
|
+
]);
|
|
1537
|
+
if (this._options.learn) this._learnRoles(parsedRoles);
|
|
1538
|
+
if (this._denyRules.has(resource)) {
|
|
1539
|
+
const config = this._denyRules.get(resource);
|
|
1540
|
+
parsedRoles.forEach((role)=>config.roles.add(role));
|
|
1541
|
+
} else this._denyRules.set(resource, this._getRuleConfig(resource, parsedRoles));
|
|
1542
|
+
return this;
|
|
1543
|
+
}
|
|
1544
|
+
isAllowed(role, resource) {
|
|
1545
|
+
let determinedAction = this._options.defaultAction;
|
|
1546
|
+
const allowRules = this._findRules(resource, this._allowRules);
|
|
1547
|
+
const denyRules = this._findRules(resource, this._denyRules);
|
|
1548
|
+
const rules = (0, __WEBPACK_EXTERNAL_MODULE_es_toolkit_compat_a17790f0__.sortBy)([
|
|
1549
|
+
...allowRules.map((rule)=>({
|
|
1550
|
+
rule,
|
|
1551
|
+
action: 1
|
|
1552
|
+
})),
|
|
1553
|
+
...denyRules.map((rule)=>({
|
|
1554
|
+
rule,
|
|
1555
|
+
action: 0
|
|
1556
|
+
}))
|
|
1557
|
+
], (rule)=>rule.rule.name.length);
|
|
1558
|
+
for (const { rule, action } of rules)if (this.isRoleIncluded(role, rule.roles)) determinedAction = action;
|
|
1559
|
+
return 1 === determinedAction;
|
|
1560
|
+
}
|
|
1561
|
+
isRoleIncluded(role, compareRoles) {
|
|
1562
|
+
const roleConfig = this._roles.get(role);
|
|
1563
|
+
if (!roleConfig) throw new error_FrameworkError(`Role "${role}" not registered`);
|
|
1564
|
+
if (compareRoles.has(role)) return true;
|
|
1565
|
+
const roleList = this._getRoleList(roleConfig);
|
|
1566
|
+
for (const candidate of compareRoles)if (roleList.indexOf(candidate) >= 0) return true;
|
|
1567
|
+
return false;
|
|
1568
|
+
}
|
|
1569
|
+
validate(config, role = null) {
|
|
1570
|
+
let parsedConfig;
|
|
1571
|
+
if ((0, __WEBPACK_EXTERNAL_MODULE_es_toolkit_compat_a17790f0__.isArray)(config)) parsedConfig = {
|
|
1572
|
+
allowedRoles: config
|
|
1573
|
+
};
|
|
1574
|
+
else if ((0, __WEBPACK_EXTERNAL_MODULE_es_toolkit_compat_a17790f0__.isString)(config) || (0, __WEBPACK_EXTERNAL_MODULE_es_toolkit_compat_a17790f0__.isNumber)(config)) parsedConfig = {
|
|
1575
|
+
allowedRoles: [
|
|
1576
|
+
config
|
|
1577
|
+
]
|
|
1578
|
+
};
|
|
1579
|
+
else if (config) parsedConfig = config;
|
|
1580
|
+
let allowed = 1 === this._options.defaultAction;
|
|
1581
|
+
if (role) {
|
|
1582
|
+
if (parsedConfig.allowedRoles) allowed = this.isRoleIncluded(role, new Set(parsedConfig.allowedRoles));
|
|
1583
|
+
else if (parsedConfig.resource) allowed = this.isAllowed(role, parsedConfig.resource);
|
|
1584
|
+
}
|
|
1585
|
+
return allowed;
|
|
1586
|
+
}
|
|
1587
|
+
middleware(config = null) {
|
|
1588
|
+
return honoAclMiddleware(this, config, this._options);
|
|
1589
|
+
}
|
|
1590
|
+
rolePath(path) {
|
|
1591
|
+
this._options.rolePath = path;
|
|
1592
|
+
return this;
|
|
1593
|
+
}
|
|
1594
|
+
onForbidden(handler) {
|
|
1595
|
+
this._options.onForbidden = handler;
|
|
1596
|
+
return this;
|
|
1597
|
+
}
|
|
1598
|
+
beforeBuildSchema(builder, rootBuilder) {
|
|
1599
|
+
builder.use(graphQLAclMiddleware(this, rootBuilder.name || rootBuilder.tag.toString(), this._options));
|
|
1600
|
+
}
|
|
1601
|
+
afterBuildSchema(builder, schema, rootBuilder) {
|
|
1602
|
+
const schemaId = rootBuilder.name || rootBuilder.tag.toString();
|
|
1603
|
+
for (const type of builder.getObjectTypes()){
|
|
1604
|
+
const typeInfo = type.info();
|
|
1605
|
+
this.addRules(`${schemaId}:${type.name}.*`, typeInfo.allowedRoles, typeInfo.deniedRoles);
|
|
1606
|
+
for (const field of type.info().fields){
|
|
1607
|
+
const fieldInfo = field.info();
|
|
1608
|
+
this.addRules(`${schemaId}:${type.name}.${field.name}`, fieldInfo.allowedRoles, fieldInfo.deniedRoles);
|
|
1609
|
+
}
|
|
1610
|
+
}
|
|
1611
|
+
}
|
|
1612
|
+
addRules(resource, allowed, denied) {
|
|
1613
|
+
if (allowed.size > 0) this.allow(resource, Array.from(allowed));
|
|
1614
|
+
if (denied.size > 0) this.deny(resource, Array.from(denied));
|
|
1615
|
+
}
|
|
1616
|
+
_findRules(resource, collection) {
|
|
1617
|
+
const allRules = Array.from(collection.values());
|
|
1618
|
+
return allRules.filter((rule)=>{
|
|
1619
|
+
if ((0, __WEBPACK_EXTERNAL_MODULE_es_toolkit_compat_a17790f0__.isString)(rule.resource)) return rule.resource === resource;
|
|
1620
|
+
if (rule.resource instanceof RegExp) return rule.resource.test(resource);
|
|
1621
|
+
return false;
|
|
1622
|
+
});
|
|
1623
|
+
}
|
|
1624
|
+
_learnRoles(roles) {
|
|
1625
|
+
for (const role of roles)if (!this._roles.has(role)) this.role(role);
|
|
1626
|
+
}
|
|
1627
|
+
_getRoleList(roleConfig) {
|
|
1628
|
+
if (!roleConfig) return [];
|
|
1629
|
+
if (!roleConfig.parent) return [
|
|
1630
|
+
roleConfig.identifier
|
|
1631
|
+
];
|
|
1632
|
+
return [
|
|
1633
|
+
roleConfig.identifier,
|
|
1634
|
+
...this._getRoleList(this._roles.get(roleConfig.parent))
|
|
1635
|
+
];
|
|
1636
|
+
}
|
|
1637
|
+
_getRuleConfig(name, roles) {
|
|
1638
|
+
let resource = name;
|
|
1639
|
+
if (name.indexOf('*') >= 0) {
|
|
1640
|
+
const pattern = (0, __WEBPACK_EXTERNAL_MODULE_es_toolkit_compat_a17790f0__.escapeRegExp)(name).replace('\\*', '(.*)');
|
|
1641
|
+
resource = new RegExp(`^${pattern}$`);
|
|
1642
|
+
}
|
|
1643
|
+
return {
|
|
1644
|
+
name,
|
|
1645
|
+
resource,
|
|
1646
|
+
roles
|
|
1647
|
+
};
|
|
1648
|
+
}
|
|
1649
|
+
constructor(options){
|
|
1650
|
+
this._roles = new Map();
|
|
1651
|
+
this._allowRules = new Map();
|
|
1652
|
+
this._denyRules = new Map();
|
|
1653
|
+
this._options = (0, __WEBPACK_EXTERNAL_MODULE_es_toolkit_compat_a17790f0__.defaults)(options || {}, defaultAclMiddlewareOptions, defaultAclOptions);
|
|
1654
|
+
}
|
|
1655
|
+
}
|
|
1656
|
+
function aclPlugin(options) {
|
|
1657
|
+
return new AclPlugin(options);
|
|
1658
|
+
}
|
|
1659
|
+
class PluginError_PluginError extends error_FrameworkError {
|
|
1660
|
+
}
|
|
1661
|
+
const PluginError = PluginError_PluginError;
|
|
1662
|
+
const defaultEqualsFilterPluginOptions = {
|
|
1663
|
+
multi: false,
|
|
1664
|
+
manual: false,
|
|
1665
|
+
argumentName: 'filter',
|
|
1666
|
+
inputName: (typeName)=>`${typeName}EqualsFilter`
|
|
1667
|
+
};
|
|
1668
|
+
class EqualsFilterPlugin {
|
|
1669
|
+
multi(multi = true) {
|
|
1670
|
+
this._options.multi = multi;
|
|
1671
|
+
return this;
|
|
1672
|
+
}
|
|
1673
|
+
manual(manual = true) {
|
|
1674
|
+
this._options.manual = manual;
|
|
1675
|
+
return this;
|
|
1676
|
+
}
|
|
1677
|
+
field(name, type) {
|
|
1678
|
+
if (!this._options.fields) this._options.fields = [];
|
|
1679
|
+
this._options.fields.push({
|
|
1680
|
+
name,
|
|
1681
|
+
type
|
|
1682
|
+
});
|
|
1683
|
+
return this;
|
|
1684
|
+
}
|
|
1685
|
+
exclude(...fieldNames) {
|
|
1686
|
+
fieldNames.forEach((name)=>this._options.exclude.push(name));
|
|
1687
|
+
return this;
|
|
1688
|
+
}
|
|
1689
|
+
include(...fieldNames) {
|
|
1690
|
+
fieldNames.forEach((name)=>this._options.include.push(name));
|
|
1691
|
+
return this;
|
|
1692
|
+
}
|
|
1693
|
+
argumentName(name) {
|
|
1694
|
+
this._options.argumentName = name;
|
|
1695
|
+
return this;
|
|
1696
|
+
}
|
|
1697
|
+
inputName(nameFactory) {
|
|
1698
|
+
this._options.inputName = nameFactory;
|
|
1699
|
+
return this;
|
|
1700
|
+
}
|
|
1701
|
+
beforeBuildField(builder, context, info) {
|
|
1702
|
+
if (!info.list) return;
|
|
1703
|
+
const typeName = info.type.toString();
|
|
1704
|
+
const inputTypeName = this._options.inputName(typeName);
|
|
1705
|
+
let targetObjectType;
|
|
1706
|
+
if (!this._options.manual) {
|
|
1707
|
+
targetObjectType = context.rootSchema.findType(typeName, true);
|
|
1708
|
+
if (!targetObjectType) throw new PluginError(`Filter target object ${typeName} not found`);
|
|
1709
|
+
if (!(targetObjectType instanceof ObjectTypeBuilder)) throw new PluginError(`Filter target ${typeName} is not an object type`);
|
|
1710
|
+
}
|
|
1711
|
+
const inputType = this._createFilterInputType(context, inputTypeName, targetObjectType);
|
|
1712
|
+
context.schema.inputObject(inputType);
|
|
1713
|
+
builder.arg(this._options.argumentName, inputTypeName, (_)=>_.description("Configuration for how the nodes should be filtered"));
|
|
1714
|
+
}
|
|
1715
|
+
_createFilterInputType(context, name, targetObjectType) {
|
|
1716
|
+
const inputObjectType = ts_inputObjectType(name).description("Configuration for how the nodes should be filtered");
|
|
1717
|
+
const fields = new Set();
|
|
1718
|
+
if (targetObjectType) for (const field of targetObjectType.info().fields){
|
|
1719
|
+
var _this__options_include;
|
|
1720
|
+
const fieldInfo = field.info();
|
|
1721
|
+
if (!fieldInfo.list && !!isTypeInput(fieldInfo.type, context.rootSchema)) {
|
|
1722
|
+
if ((null === (_this__options_include = this._options.include) || void 0 === _this__options_include ? !void 0 : !_this__options_include.length) || !!this._options.include.includes(field.name)) fields.add({
|
|
1723
|
+
name: field.name,
|
|
1724
|
+
type: fieldInfo.type
|
|
1725
|
+
});
|
|
1726
|
+
}
|
|
1727
|
+
}
|
|
1728
|
+
if (this._options.fields) this._options.fields.forEach((field)=>fields.add(field));
|
|
1729
|
+
const extraFields = this._getExtraFieldConfigs(context, name, targetObjectType);
|
|
1730
|
+
if (extraFields) extraFields.forEach((extraField)=>fields.add(extraField));
|
|
1731
|
+
for (const field of fields)if (!(this._options.exclude && this._options.exclude.indexOf(field.name) >= 0)) inputObjectType.field(field.name, field.type, (_)=>{
|
|
1732
|
+
if (this._options.multi) _.list();
|
|
1733
|
+
});
|
|
1734
|
+
return inputObjectType;
|
|
1735
|
+
}
|
|
1736
|
+
_getExtraFieldConfigs(context, name, targetObjectType) {
|
|
1737
|
+
return null;
|
|
1738
|
+
}
|
|
1739
|
+
constructor(options){
|
|
1740
|
+
this._options = (0, __WEBPACK_EXTERNAL_MODULE_es_toolkit_compat_a17790f0__.defaults)(options || {}, defaultEqualsFilterPluginOptions, {
|
|
1741
|
+
exclude: [],
|
|
1742
|
+
include: []
|
|
1743
|
+
});
|
|
1744
|
+
}
|
|
1745
|
+
}
|
|
1746
|
+
function equalsFilterPlugin(options) {
|
|
1747
|
+
return new EqualsFilterPlugin(options);
|
|
1748
|
+
}
|
|
1749
|
+
const defaultSearchFilterPluginOptions = {
|
|
1750
|
+
argumentName: 'search'
|
|
1751
|
+
};
|
|
1752
|
+
class SearchFilterPlugin {
|
|
1753
|
+
beforeBuildField(builder, context, info) {
|
|
1754
|
+
if (!info.list) return;
|
|
1755
|
+
builder.arg(this._options.argumentName, 'String', (_)=>_.description('Search query'));
|
|
1756
|
+
}
|
|
1757
|
+
constructor(options){
|
|
1758
|
+
this._options = (0, __WEBPACK_EXTERNAL_MODULE_es_toolkit_compat_a17790f0__.defaults)(options || {}, defaultSearchFilterPluginOptions);
|
|
1759
|
+
}
|
|
1760
|
+
}
|
|
1761
|
+
function searchFilterPlugin() {
|
|
1762
|
+
return new SearchFilterPlugin();
|
|
1763
|
+
}
|
|
1764
|
+
const PageInfoObjectTypeName = "PageInfo";
|
|
1765
|
+
class ConnectionPaginationPlugin {
|
|
1766
|
+
totalCount(totalCount = true) {
|
|
1767
|
+
this._totalCount = totalCount;
|
|
1768
|
+
return this;
|
|
1769
|
+
}
|
|
1770
|
+
beforeBuildField(builder, context, info) {
|
|
1771
|
+
if (!info.list) return;
|
|
1772
|
+
if (!context.schema.hasType(PageInfoObjectTypeName)) context.schema.object(this._createPageInfoObjectType());
|
|
1773
|
+
const typeName = info.type.toString();
|
|
1774
|
+
const targetType = context.rootSchema.findType(typeName, true);
|
|
1775
|
+
if (!targetType) throw new PluginError(`Edges target type "${typeName}" not found`);
|
|
1776
|
+
if (!(targetType instanceof ObjectTypeBuilder)) throw new PluginError(`Edges target "${typeName}" is not an object type`);
|
|
1777
|
+
const targetObjectInfo = targetType.info();
|
|
1778
|
+
const pageInfoType = context.schema.findType(PageInfoObjectTypeName);
|
|
1779
|
+
pageInfoType.allow(...Array.from(targetObjectInfo.allowedRoles));
|
|
1780
|
+
pageInfoType.deny(...Array.from(targetObjectInfo.deniedRoles));
|
|
1781
|
+
const edgeObjectTypeName = `${typeName}Edge`;
|
|
1782
|
+
const edgeObjectType = this._createEdgeObjectType(edgeObjectTypeName, typeName);
|
|
1783
|
+
edgeObjectType.allow(...Array.from(targetObjectInfo.allowedRoles));
|
|
1784
|
+
edgeObjectType.deny(...Array.from(targetObjectInfo.deniedRoles));
|
|
1785
|
+
context.schema.object(edgeObjectType);
|
|
1786
|
+
const connectionObjectTypeName = `${typeName}Connection`;
|
|
1787
|
+
const connectionObjectType = this._createConnectionObjectType(connectionObjectTypeName, edgeObjectTypeName);
|
|
1788
|
+
connectionObjectType.allow(...Array.from(targetObjectInfo.allowedRoles));
|
|
1789
|
+
connectionObjectType.deny(...Array.from(targetObjectInfo.deniedRoles));
|
|
1790
|
+
context.schema.object(connectionObjectType);
|
|
1791
|
+
builder.type(connectionObjectTypeName).list(false);
|
|
1792
|
+
}
|
|
1793
|
+
_createPageInfoObjectType() {
|
|
1794
|
+
return ts_objectType(PageInfoObjectTypeName).description('Provides information about the paging state').field('hasNextPage', 'Boolean', (_)=>_.nonNull().description('Indicates whether there is a next page')).field('hasPreviousPage', 'Boolean', (_)=>_.nonNull().description('Indicates whether there is a previous page')).field('startCursor', 'String', (_)=>_.description('Cursor for the first node')).field('endCursor', 'String', (_)=>_.description('Cursor for the last node'));
|
|
1795
|
+
}
|
|
1796
|
+
_createConnectionObjectType(name, edgeTypeName) {
|
|
1797
|
+
const type = ts_objectType(name).description(`Connection with ${edgeTypeName}`).field('pageInfo', PageInfoObjectTypeName, (_)=>_.nonNull().description('Provides information about the paging state')).field('edges', edgeTypeName, (_)=>_.list().description('List of the queried edges'));
|
|
1798
|
+
if (this._totalCount) type.field('totalCount', 'Int', (_)=>_.nonNull().description('Total number of nodes'));
|
|
1799
|
+
return type;
|
|
1800
|
+
}
|
|
1801
|
+
_createEdgeObjectType(name, typeName) {
|
|
1802
|
+
return ts_objectType(name).description(`${typeName} edge`).field('node', typeName, (_)=>_.description('Current node')).field('cursor', 'String', (_)=>_.nonNull().description('Cursor for the current node'));
|
|
1803
|
+
}
|
|
1804
|
+
constructor(){
|
|
1805
|
+
this._totalCount = false;
|
|
1806
|
+
}
|
|
1807
|
+
}
|
|
1808
|
+
function connectionPaginationPlugin() {
|
|
1809
|
+
return new ConnectionPaginationPlugin();
|
|
1810
|
+
}
|
|
1811
|
+
class FirstAfterPaginationPlugin {
|
|
1812
|
+
beforeBuildField(builder, context, info) {
|
|
1813
|
+
if (!info.list) return;
|
|
1814
|
+
builder.arg('first', 'Int', (_)=>_.description('Number of nodes to return')).arg('after', 'String', (_)=>_.description('Cursor for item after which results are to be selected'));
|
|
1815
|
+
}
|
|
1816
|
+
}
|
|
1817
|
+
function firstAfterPaginationPlugin() {
|
|
1818
|
+
return new FirstAfterPaginationPlugin();
|
|
1819
|
+
}
|
|
1820
|
+
class ItemsPaginationPlugin {
|
|
1821
|
+
beforeBuildField(builder, context, info) {
|
|
1822
|
+
if (!info.list) return;
|
|
1823
|
+
const typeName = info.type.toString();
|
|
1824
|
+
const targetType = context.rootSchema.findType(typeName, true);
|
|
1825
|
+
if (!targetType) throw new PluginError(`Items target type "${typeName}" not found`);
|
|
1826
|
+
if (!(targetType instanceof ObjectTypeBuilder)) throw new PluginError(`Items target "${typeName}" is not an object type`);
|
|
1827
|
+
const targetObjectInfo = targetType.info();
|
|
1828
|
+
const listObjectTypeName = `${typeName}List`;
|
|
1829
|
+
const listObjectType = this._createListObjectType(listObjectTypeName, typeName);
|
|
1830
|
+
listObjectType.allow(...Array.from(targetObjectInfo.allowedRoles));
|
|
1831
|
+
listObjectType.deny(...Array.from(targetObjectInfo.deniedRoles));
|
|
1832
|
+
context.schema.object(listObjectType);
|
|
1833
|
+
builder.type(listObjectTypeName).list(false);
|
|
1834
|
+
}
|
|
1835
|
+
_createListObjectType(name, typeName) {
|
|
1836
|
+
return ts_objectType(name).description(`Collection of ${typeName} nodes`).field('items', typeName, (_)=>_.list().nonNull().description('List of the queried nodes')).field('totalCount', 'Int', (_)=>_.nonNull().description('Total number of nodes'));
|
|
1837
|
+
}
|
|
1838
|
+
}
|
|
1839
|
+
function itemsPaginationPlugin() {
|
|
1840
|
+
return new ItemsPaginationPlugin();
|
|
1841
|
+
}
|
|
1842
|
+
class OffsetLimitPaginationPlugin {
|
|
1843
|
+
beforeBuildField(builder, context, info) {
|
|
1844
|
+
if (!info.list) return;
|
|
1845
|
+
builder.arg('offset', 'Int', (_)=>_.description('Offset for the nodes to return')).arg('limit', 'Int', (_)=>_.description('Number of nodes to return'));
|
|
1846
|
+
}
|
|
1847
|
+
}
|
|
1848
|
+
function offsetLimitPaginationPlugin() {
|
|
1849
|
+
return new OffsetLimitPaginationPlugin();
|
|
1850
|
+
}
|
|
1851
|
+
class MultiPlugin {
|
|
1852
|
+
getPlugins() {
|
|
1853
|
+
return [];
|
|
1854
|
+
}
|
|
1855
|
+
async execute(methodName, fn) {
|
|
1856
|
+
const results = [];
|
|
1857
|
+
for (const plugin of this._plugins)if (plugin[methodName]) {
|
|
1858
|
+
const result = await fn(plugin);
|
|
1859
|
+
results.push(result);
|
|
1860
|
+
}
|
|
1861
|
+
return results;
|
|
1862
|
+
}
|
|
1863
|
+
executeSync(methodName, fn) {
|
|
1864
|
+
const results = [];
|
|
1865
|
+
for (const plugin of this._plugins)if (plugin[methodName]) {
|
|
1866
|
+
const result = fn(plugin);
|
|
1867
|
+
results.push(result);
|
|
1868
|
+
}
|
|
1869
|
+
return results;
|
|
1870
|
+
}
|
|
1871
|
+
async beforeFinalizeSchema(builder) {
|
|
1872
|
+
await this.execute('beforeFinalizeSchema', (plugin)=>plugin.beforeFinalizeSchema(builder));
|
|
1873
|
+
}
|
|
1874
|
+
async afterFinalizeSchema(builder) {
|
|
1875
|
+
await this.execute('afterFinalizeSchema', (plugin)=>plugin.afterFinalizeSchema(builder));
|
|
1876
|
+
}
|
|
1877
|
+
async beforeFinalizeObjectType(builder, context, info) {
|
|
1878
|
+
await this.execute('beforeFinalizeObjectType', (plugin)=>plugin.beforeFinalizeObjectType(builder, context, info));
|
|
1879
|
+
}
|
|
1880
|
+
async afterFinalizeObjectType(builder, context, info) {
|
|
1881
|
+
await this.execute('afterFinalizeObjectType', (plugin)=>plugin.afterFinalizeObjectType(builder, context, info));
|
|
1882
|
+
}
|
|
1883
|
+
async beforeFinalizeInputObjectType(builder, context, info) {
|
|
1884
|
+
await this.execute('beforeFinalizeInputObjectType', (plugin)=>plugin.beforeFinalizeInputObjectType(builder, context, info));
|
|
1885
|
+
}
|
|
1886
|
+
async afterFinalizeInputObjectType(builder, context, info) {
|
|
1887
|
+
await this.execute('afterFinalizeInputObjectType', (plugin)=>plugin.afterFinalizeInputObjectType(builder, context, info));
|
|
1888
|
+
}
|
|
1889
|
+
async beforeFinalizeEnumType(builder, context, info) {
|
|
1890
|
+
await this.execute('beforeFinalizeEnumType', (plugin)=>plugin.beforeFinalizeEnumType(builder, context, info));
|
|
1891
|
+
}
|
|
1892
|
+
async afterFinalizeEnumType(builder, context, info) {
|
|
1893
|
+
await this.execute('afterFinalizeEnumType', (plugin)=>plugin.afterFinalizeEnumType(builder, context, info));
|
|
1894
|
+
}
|
|
1895
|
+
async beforeFinalizeEnumValue(builder, context, info) {
|
|
1896
|
+
await this.execute('beforeFinalizeEnumValue', (plugin)=>plugin.beforeFinalizeEnumValue(builder, context, info));
|
|
1897
|
+
}
|
|
1898
|
+
async afterFinalizeEnumValue(builder, context, info) {
|
|
1899
|
+
await this.execute('afterFinalizeEnumValue', (plugin)=>plugin.afterFinalizeEnumValue(builder, context, info));
|
|
1900
|
+
}
|
|
1901
|
+
async beforeFinalizeUnionType(builder, context, info) {
|
|
1902
|
+
await this.execute('beforeFinalizeUnionType', (plugin)=>plugin.beforeFinalizeUnionType(builder, context, info));
|
|
1903
|
+
}
|
|
1904
|
+
async afterFinalizeUnionType(builder, context, info) {
|
|
1905
|
+
await this.execute('afterFinalizeUnionType', (plugin)=>plugin.afterFinalizeUnionType(builder, context, info));
|
|
1906
|
+
}
|
|
1907
|
+
async beforeFinalizeField(builder, context, info) {
|
|
1908
|
+
await this.execute('beforeFinalizeField', (plugin)=>plugin.beforeFinalizeField(builder, context, info));
|
|
1909
|
+
}
|
|
1910
|
+
async afterFinalizeField(builder, context, info) {
|
|
1911
|
+
await this.execute('afterFinalizeField', (plugin)=>plugin.afterFinalizeField(builder, context, info));
|
|
1912
|
+
}
|
|
1913
|
+
async beforeFinalizeInputField(builder, context, info) {
|
|
1914
|
+
await this.execute('beforeFinalizeInputField', (plugin)=>plugin.beforeFinalizeInputField(builder, context, info));
|
|
1915
|
+
}
|
|
1916
|
+
async afterFinalizeInputField(builder, context, info) {
|
|
1917
|
+
await this.execute('afterFinalizeInputField', (plugin)=>plugin.afterFinalizeInputField(builder, context, info));
|
|
1918
|
+
}
|
|
1919
|
+
async beforeFinalizeArgument(builder, context, info) {
|
|
1920
|
+
await this.execute('beforeFinalizeArgument', (plugin)=>plugin.beforeFinalizeArgument(builder, context, info));
|
|
1921
|
+
}
|
|
1922
|
+
async afterFinalizeArgument(builder, context, info) {
|
|
1923
|
+
await this.execute('afterFinalizeArgument', (plugin)=>plugin.afterFinalizeArgument(builder, context, info));
|
|
1924
|
+
}
|
|
1925
|
+
beforeBuild(rootBuilder) {
|
|
1926
|
+
this.executeSync('beforeBuild', (plugin)=>plugin.beforeBuild(rootBuilder));
|
|
1927
|
+
}
|
|
1928
|
+
afterBuild(rootBuilder, schema) {
|
|
1929
|
+
this.executeSync('afterBuild', (plugin)=>plugin.afterBuild(rootBuilder, schema));
|
|
1930
|
+
}
|
|
1931
|
+
beforeBuildSchema(builder, rootBuilder) {
|
|
1932
|
+
this.executeSync('beforeBuildSchema', (plugin)=>plugin.beforeBuildSchema(builder, rootBuilder));
|
|
1933
|
+
}
|
|
1934
|
+
afterBuildSchema(builder, schema, rootBuilder) {
|
|
1935
|
+
this.executeSync('afterBuildSchema', (plugin)=>plugin.afterBuildSchema(builder, schema, rootBuilder));
|
|
1936
|
+
}
|
|
1937
|
+
beforeBuildObjectType(builder, context, info) {
|
|
1938
|
+
this.executeSync('beforeBuildObjectType', (plugin)=>plugin.beforeBuildObjectType(builder, context, info));
|
|
1939
|
+
}
|
|
1940
|
+
afterBuildObjectType(builder, context, info, objectType) {
|
|
1941
|
+
this.executeSync('afterBuildObjectType', (plugin)=>plugin.afterBuildObjectType(builder, context, info, objectType));
|
|
1942
|
+
}
|
|
1943
|
+
beforeBuildInputObjectType(builder, context, info) {
|
|
1944
|
+
this.executeSync('beforeBuildInputObjectType', (plugin)=>plugin.beforeBuildInputObjectType(builder, context, info));
|
|
1945
|
+
}
|
|
1946
|
+
afterBuildInputObjectType(builder, context, info, inputObjectType) {
|
|
1947
|
+
this.executeSync('afterBuildInputObjectType', (plugin)=>plugin.afterBuildInputObjectType(builder, context, info, inputObjectType));
|
|
1948
|
+
}
|
|
1949
|
+
beforeBuildEnumType(builder, context, info) {
|
|
1950
|
+
this.executeSync('beforeBuildEnumType', (plugin)=>plugin.beforeBuildEnumType(builder, context, info));
|
|
1951
|
+
}
|
|
1952
|
+
afterBuildEnumType(builder, context, info, enumType) {
|
|
1953
|
+
this.executeSync('afterBuildEnumType', (plugin)=>plugin.afterBuildEnumType(builder, context, info, enumType));
|
|
1954
|
+
}
|
|
1955
|
+
beforeBuildEnumValue(builder, context, info) {
|
|
1956
|
+
this.executeSync('beforeBuildEnumValue', (plugin)=>plugin.beforeBuildEnumValue(builder, context, info));
|
|
1957
|
+
}
|
|
1958
|
+
afterBuildEnumValue(builder, context, info, enumValue) {
|
|
1959
|
+
this.executeSync('afterBuildEnumValue', (plugin)=>plugin.afterBuildEnumValue(builder, context, info, enumValue));
|
|
1960
|
+
}
|
|
1961
|
+
beforeBuildUnionType(builder, context, info) {
|
|
1962
|
+
this.executeSync('beforeBuildUnionType', (plugin)=>plugin.beforeBuildUnionType(builder, context, info));
|
|
1963
|
+
}
|
|
1964
|
+
afterBuildUnionType(builder, context, info, unionType) {
|
|
1965
|
+
this.executeSync('afterBuildUnionType', (plugin)=>plugin.afterBuildUnionType(builder, context, info, unionType));
|
|
1966
|
+
}
|
|
1967
|
+
beforeBuildField(builder, context, info) {
|
|
1968
|
+
this.executeSync('beforeBuildField', (plugin)=>plugin.beforeBuildField(builder, context, info));
|
|
1969
|
+
}
|
|
1970
|
+
afterBuildField(builder, context, info, field) {
|
|
1971
|
+
this.executeSync('afterBuildField', (plugin)=>plugin.afterBuildField(builder, context, info, field));
|
|
1972
|
+
}
|
|
1973
|
+
beforeBuildInputField(builder, context, info) {
|
|
1974
|
+
this.executeSync('beforeBuildInputField', (plugin)=>plugin.beforeBuildInputField(builder, context, info));
|
|
1975
|
+
}
|
|
1976
|
+
afterBuildInputField(builder, context, info, inputField) {
|
|
1977
|
+
this.executeSync('afterBuildInputField', (plugin)=>plugin.afterBuildInputField(builder, context, info, inputField));
|
|
1978
|
+
}
|
|
1979
|
+
beforeBuildArgument(builder, context, info) {
|
|
1980
|
+
this.executeSync('beforeBuildArgument', (plugin)=>plugin.beforeBuildArgument(builder, context, info));
|
|
1981
|
+
}
|
|
1982
|
+
afterBuildArgument(builder, context, info, argument) {
|
|
1983
|
+
this.executeSync('afterBuildArgument', (plugin)=>plugin.afterBuildArgument(builder, context, info, argument));
|
|
1984
|
+
}
|
|
1985
|
+
constructor(plugins = null){
|
|
1986
|
+
this._plugins = plugins || this.getPlugins();
|
|
1987
|
+
}
|
|
1988
|
+
}
|
|
1989
|
+
const plugin_MultiPlugin = MultiPlugin;
|
|
1990
|
+
class RelayPaginationPlugin extends plugin_MultiPlugin {
|
|
1991
|
+
getPlugins() {
|
|
1992
|
+
this._firstAfterPlugin = new FirstAfterPaginationPlugin();
|
|
1993
|
+
this._connectionPlugin = new ConnectionPaginationPlugin();
|
|
1994
|
+
return [
|
|
1995
|
+
this._firstAfterPlugin,
|
|
1996
|
+
this._connectionPlugin
|
|
1997
|
+
];
|
|
1998
|
+
}
|
|
1999
|
+
totalCount(totalCount = true) {
|
|
2000
|
+
this._connectionPlugin.totalCount(totalCount);
|
|
2001
|
+
return this;
|
|
2002
|
+
}
|
|
2003
|
+
}
|
|
2004
|
+
function relayPaginationPlugin() {
|
|
2005
|
+
return new RelayPaginationPlugin();
|
|
2006
|
+
}
|
|
2007
|
+
class SimplePaginationPlugin extends plugin_MultiPlugin {
|
|
2008
|
+
getPlugins() {
|
|
2009
|
+
return [
|
|
2010
|
+
new OffsetLimitPaginationPlugin(),
|
|
2011
|
+
new ItemsPaginationPlugin()
|
|
2012
|
+
];
|
|
2013
|
+
}
|
|
2014
|
+
}
|
|
2015
|
+
function simplePaginationPlugin() {
|
|
2016
|
+
return new SimplePaginationPlugin();
|
|
2017
|
+
}
|
|
2018
|
+
var sort_SortDirection = /*#__PURE__*/ function(SortDirection) {
|
|
2019
|
+
SortDirection["ASC"] = "ASC";
|
|
2020
|
+
SortDirection["DESC"] = "DESC";
|
|
2021
|
+
return SortDirection;
|
|
2022
|
+
}({});
|
|
2023
|
+
const defaultSortPluginOptions = {
|
|
2024
|
+
multi: false,
|
|
2025
|
+
directionEnumName: 'SortDirection',
|
|
2026
|
+
argumentName: 'sort',
|
|
2027
|
+
inputName: (typeName)=>`${typeName}SortConfiguration`,
|
|
2028
|
+
fieldEnumName: (typeName)=>`${typeName}SortField`
|
|
2029
|
+
};
|
|
2030
|
+
class SortPlugin {
|
|
2031
|
+
multi(multi = true) {
|
|
2032
|
+
this._options.multi = multi;
|
|
2033
|
+
return this;
|
|
2034
|
+
}
|
|
2035
|
+
field(...fieldNames) {
|
|
2036
|
+
if (!this._options.fields) this._options.fields = [];
|
|
2037
|
+
fieldNames.forEach((name)=>this._options.fields.push(name));
|
|
2038
|
+
return this;
|
|
2039
|
+
}
|
|
2040
|
+
exclude(...fieldNames) {
|
|
2041
|
+
fieldNames.forEach((name)=>this._options.exclude.push(name));
|
|
2042
|
+
return this;
|
|
2043
|
+
}
|
|
2044
|
+
include(...fieldNames) {
|
|
2045
|
+
fieldNames.forEach((name)=>this._options.include.push(name));
|
|
2046
|
+
return this;
|
|
2047
|
+
}
|
|
2048
|
+
directionEnumName(name) {
|
|
2049
|
+
this._options.directionEnumName = name;
|
|
2050
|
+
return this;
|
|
2051
|
+
}
|
|
2052
|
+
argumentName(name) {
|
|
2053
|
+
this._options.argumentName = name;
|
|
2054
|
+
return this;
|
|
2055
|
+
}
|
|
2056
|
+
inputName(nameFactory) {
|
|
2057
|
+
this._options.inputName = nameFactory;
|
|
2058
|
+
return this;
|
|
2059
|
+
}
|
|
2060
|
+
fieldEnumName(nameFactory) {
|
|
2061
|
+
this._options.fieldEnumName = nameFactory;
|
|
2062
|
+
return this;
|
|
2063
|
+
}
|
|
2064
|
+
beforeBuildField(builder, context, info) {
|
|
2065
|
+
if (!info.list) return;
|
|
2066
|
+
if (!context.schema.hasType(this._options.directionEnumName)) context.schema.enum(this._createSortDirectionEnum());
|
|
2067
|
+
const typeName = info.type.toString();
|
|
2068
|
+
const inputTypeName = this._options.inputName(typeName);
|
|
2069
|
+
const fieldEnumName = this._options.fieldEnumName(typeName);
|
|
2070
|
+
let targetObjectType;
|
|
2071
|
+
if (!this._options.fields) {
|
|
2072
|
+
targetObjectType = context.rootSchema.findType(typeName, true);
|
|
2073
|
+
if (!targetObjectType) throw new PluginError(`Sort target object "${typeName}" not found`);
|
|
2074
|
+
if (!(targetObjectType instanceof ObjectTypeBuilder)) throw new PluginError(`Sort target "${typeName}" is not an object type`);
|
|
2075
|
+
}
|
|
2076
|
+
const enumType = this._createSortFieldEnum(context, fieldEnumName, typeName, targetObjectType);
|
|
2077
|
+
context.schema.enum(enumType);
|
|
2078
|
+
const inputType = this._createSortInputType(inputTypeName, fieldEnumName);
|
|
2079
|
+
context.schema.inputObject(inputType);
|
|
2080
|
+
builder.arg(this._options.argumentName, inputTypeName, (_)=>{
|
|
2081
|
+
if (this._options.multi) _.list().description('Collection of sort configurations');
|
|
2082
|
+
else _.description('Sort configuration');
|
|
2083
|
+
});
|
|
2084
|
+
}
|
|
2085
|
+
_createSortInputType(name, enumName) {
|
|
2086
|
+
return ts_inputObjectType(name).description("Configuration for how the nodes should be sorted").field('field', enumName, (_)=>_.nonNull().description('Field to sort on')).field('direction', this._options.directionEnumName, (_)=>_.nonNull().description('Direction to sort'));
|
|
2087
|
+
}
|
|
2088
|
+
_createSortFieldEnum(context, name, typeName, targetObjectType) {
|
|
2089
|
+
const enumBuilder = ts_enumType(name).description(`Field to sort ${typeName} on`);
|
|
2090
|
+
const fields = new Set();
|
|
2091
|
+
if (targetObjectType) for (const field of targetObjectType.info().fields){
|
|
2092
|
+
const fieldInfo = field.info();
|
|
2093
|
+
if (!fieldInfo.list && isTypeInput(fieldInfo.type, context.rootSchema)) fields.add(field.name);
|
|
2094
|
+
}
|
|
2095
|
+
else if (this._options.fields) this._options.fields.forEach((field)=>fields.add(field));
|
|
2096
|
+
if (this._options.include) this._options.include.forEach((field)=>fields.add(field));
|
|
2097
|
+
const extraValues = this._getExtraEnumValues(context, name, typeName, targetObjectType);
|
|
2098
|
+
if (extraValues) extraValues.forEach((extraField)=>fields.add(extraField));
|
|
2099
|
+
for (const field of fields)if (!(this._options.exclude && this._options.exclude.indexOf(field) >= 0)) enumBuilder.value(field, field);
|
|
2100
|
+
return enumBuilder;
|
|
2101
|
+
}
|
|
2102
|
+
_createSortDirectionEnum() {
|
|
2103
|
+
return ts_enumType(this._options.directionEnumName).description('Direction to sort').value("ASC", "ASC", (_)=>_.description('Sort ascending')).value("DESC", "DESC", (_)=>_.description('Sort descending'));
|
|
2104
|
+
}
|
|
2105
|
+
_getExtraEnumValues(context, name, typeName, targetObjectType) {
|
|
2106
|
+
return null;
|
|
2107
|
+
}
|
|
2108
|
+
constructor(options){
|
|
2109
|
+
this._options = (0, __WEBPACK_EXTERNAL_MODULE_es_toolkit_compat_a17790f0__.defaults)(options || {}, defaultSortPluginOptions, {
|
|
2110
|
+
exclude: [],
|
|
2111
|
+
include: []
|
|
2112
|
+
});
|
|
2113
|
+
}
|
|
2114
|
+
}
|
|
2115
|
+
function sortPlugin(options) {
|
|
2116
|
+
return new SortPlugin(options);
|
|
2117
|
+
}
|
|
2118
|
+
const ts_rslib_entry_ = ts_schema;
|
|
2119
|
+
var __webpack_exports__pluralize = __WEBPACK_EXTERNAL_MODULE_pluralize__["default"];
|
|
2120
|
+
export { AbstractEntitySchemaBuilder, AbstractEntitySchemaBuilderBase, AbstractSchemaBuilder, acl_AclAction as AclAction, AclPlugin, ArgumentBuilder, BuildContext, BuilderError, CompactNamingStrategy, ConnectionPaginationPlugin, CreateInputObjectTypeBuilder, DataError_DataError as DataError, DescriptiveNamingStrategy, entitySchema_EntityFieldType as EntityFieldType, EntitySchemaBuilder, EnumTypeBuilder, EnumValueBuilder, EqualsFilterPlugin, FieldBuilder, FinalizeContext, FirstAfterPaginationPlugin, ForbiddenError_ForbiddenError as ForbiddenError, FrameworkError, InputFieldBuilder, InputObjectTypeBuilder, InvalidInputError, ItemsPaginationPlugin, MultiPlugin, NotFoundError, ObjectTypeBuilder, OffsetLimitPaginationPlugin, PluginError_PluginError as PluginError, RelayPaginationPlugin, ResolverError, SchemaBuilder, SearchFilterPlugin, SimplePaginationPlugin, sort_SortDirection as SortDirection, SortPlugin, UnionTypeBuilder, UpdateInputObjectTypeBuilder, aclPlugin, argument_argument as argument, camelize, compactNamingStrategy, connectionPaginationPlugin, createInputObjectType, ts_rslib_entry_ as default, defaultAclMiddlewareOptions, defaultAclOptions, defaultEqualsFilterPluginOptions, defaultScalarNames, defaultSearchFilterPluginOptions, defaultSortPluginOptions, descriptiveNamingStrategy, ensureInstantiated, entityFieldTypeExtensionName, entitySchema_entitySchema as entitySchema, enumType_enumType as enumType, enumValue_enumValue as enumValue, equalsFilterPlugin, field_field as field, firstAfterPaginationPlugin, getAclExtension, getPathResource, graphQLAclMiddleware, honoAclMiddleware, inputField_inputField as inputField, inputObjectType_inputObjectType as inputObjectType, isFieldId, isTypeInput, isTypeScalar, itemsPaginationPlugin, lcFirst, objectType_objectType as objectType, offsetLimitPaginationPlugin, relayPaginationPlugin, resolveAutoBuilderArgs, resolveBuilder, resolveBuilderArgs, resolveName, resolveType, schema_schema as schema, searchFilterPlugin, simplePaginationPlugin, sortPlugin, ucFirst, unionType_unionType as unionType, updateInputObjectType_updateInputObjectType as updateInputObjectType, __webpack_exports__pluralize as pluralize };
|