@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.
Files changed (101) hide show
  1. package/LICENSE +21 -0
  2. package/dist/index.cjs +2250 -0
  3. package/dist/index.js +2118 -35
  4. package/dist/{Builder.d.ts → types/Builder.d.ts} +5 -5
  5. package/dist/{argument.d.ts → types/argument.d.ts} +3 -3
  6. package/dist/{common.d.ts → types/common.d.ts} +2 -2
  7. package/dist/{entity → types/entity}/createInputObjectType.d.ts +3 -3
  8. package/dist/{entity → types/entity}/entitySchema.d.ts +4 -4
  9. package/dist/{entity → types/entity}/updateInputObjectType.d.ts +3 -3
  10. package/dist/{enumType.d.ts → types/enumType.d.ts} +3 -3
  11. package/dist/{enumValue.d.ts → types/enumValue.d.ts} +3 -3
  12. package/dist/{field.d.ts → types/field.d.ts} +7 -7
  13. package/dist/{inputField.d.ts → types/inputField.d.ts} +3 -3
  14. package/dist/{inputObjectType.d.ts → types/inputObjectType.d.ts} +5 -5
  15. package/dist/{naming → types/naming}/common.d.ts +1 -2
  16. package/dist/{naming → types/naming}/compact.d.ts +1 -1
  17. package/dist/{naming → types/naming}/descriptive.d.ts +1 -1
  18. package/dist/{objectType.d.ts → types/objectType.d.ts} +4 -4
  19. package/dist/{plugin → types/plugin}/MultiPlugin.d.ts +14 -14
  20. package/dist/{plugin → types/plugin}/acl/acl.d.ts +5 -5
  21. package/dist/{plugin → types/plugin}/acl/middleware.d.ts +4 -4
  22. package/dist/{plugin → types/plugin}/common.d.ts +13 -13
  23. package/dist/{plugin → types/plugin}/filter/equals.d.ts +5 -5
  24. package/dist/{plugin → types/plugin}/filter/search.d.ts +3 -3
  25. package/dist/{plugin → types/plugin}/pagination/connection.d.ts +3 -3
  26. package/dist/{plugin → types/plugin}/pagination/firstAfter.d.ts +3 -3
  27. package/dist/{plugin → types/plugin}/pagination/items.d.ts +3 -3
  28. package/dist/{plugin → types/plugin}/pagination/offsetLimit.d.ts +3 -3
  29. package/dist/{plugin → types/plugin}/pagination/simple.d.ts +1 -1
  30. package/dist/{plugin → types/plugin}/sort/sort.d.ts +5 -5
  31. package/dist/{schema.d.ts → types/schema.d.ts} +9 -9
  32. package/dist/{unionType.d.ts → types/unionType.d.ts} +3 -3
  33. package/dist/{util.d.ts → types/util.d.ts} +4 -4
  34. package/package.json +43 -34
  35. package/dist/Builder.js +0 -113
  36. package/dist/argument.js +0 -100
  37. package/dist/common.js +0 -2
  38. package/dist/entity/createInputObjectType.js +0 -55
  39. package/dist/entity/entitySchema.js +0 -212
  40. package/dist/entity/index.js +0 -24
  41. package/dist/entity/updateInputObjectType.js +0 -55
  42. package/dist/enumType.js +0 -126
  43. package/dist/enumValue.js +0 -60
  44. package/dist/error/FrameworkError.js +0 -12
  45. package/dist/error/index.js +0 -18
  46. package/dist/error/resolver/DataError.js +0 -11
  47. package/dist/error/resolver/ForbiddenError.js +0 -11
  48. package/dist/error/resolver/InvalidInputError.js +0 -11
  49. package/dist/error/resolver/NotFoundError.js +0 -11
  50. package/dist/error/resolver/ResolverError.js +0 -11
  51. package/dist/error/resolver/index.js +0 -21
  52. package/dist/field.js +0 -193
  53. package/dist/inputField.js +0 -100
  54. package/dist/inputObjectType.js +0 -119
  55. package/dist/naming/common.js +0 -2
  56. package/dist/naming/compact.js +0 -54
  57. package/dist/naming/descriptive.js +0 -54
  58. package/dist/naming/index.js +0 -20
  59. package/dist/naming/util.js +0 -22
  60. package/dist/objectType.js +0 -140
  61. package/dist/plugin/MultiPlugin.js +0 -147
  62. package/dist/plugin/PluginError.js +0 -11
  63. package/dist/plugin/acl/acl.js +0 -205
  64. package/dist/plugin/acl/index.js +0 -18
  65. package/dist/plugin/acl/middleware.js +0 -48
  66. package/dist/plugin/common.js +0 -2
  67. package/dist/plugin/filter/equals.js +0 -124
  68. package/dist/plugin/filter/index.js +0 -18
  69. package/dist/plugin/filter/search.js +0 -24
  70. package/dist/plugin/index.js +0 -23
  71. package/dist/plugin/pagination/connection.js +0 -115
  72. package/dist/plugin/pagination/firstAfter.js +0 -19
  73. package/dist/plugin/pagination/index.js +0 -22
  74. package/dist/plugin/pagination/items.js +0 -78
  75. package/dist/plugin/pagination/offsetLimit.js +0 -19
  76. package/dist/plugin/pagination/relay.js +0 -26
  77. package/dist/plugin/pagination/simple.js +0 -20
  78. package/dist/plugin/sort/index.js +0 -22
  79. package/dist/plugin/sort/sort.js +0 -151
  80. package/dist/schema.js +0 -380
  81. package/dist/unionType.js +0 -75
  82. package/dist/util.js +0 -142
  83. /package/dist/{entity → types/entity}/index.d.ts +0 -0
  84. /package/dist/{error → types/error}/FrameworkError.d.ts +0 -0
  85. /package/dist/{error → types/error}/index.d.ts +0 -0
  86. /package/dist/{error → types/error}/resolver/DataError.d.ts +0 -0
  87. /package/dist/{error → types/error}/resolver/ForbiddenError.d.ts +0 -0
  88. /package/dist/{error → types/error}/resolver/InvalidInputError.d.ts +0 -0
  89. /package/dist/{error → types/error}/resolver/NotFoundError.d.ts +0 -0
  90. /package/dist/{error → types/error}/resolver/ResolverError.d.ts +0 -0
  91. /package/dist/{error → types/error}/resolver/index.d.ts +0 -0
  92. /package/dist/{index.d.ts → types/index.d.ts} +0 -0
  93. /package/dist/{naming → types/naming}/index.d.ts +0 -0
  94. /package/dist/{naming → types/naming}/util.d.ts +0 -0
  95. /package/dist/{plugin → types/plugin}/PluginError.d.ts +0 -0
  96. /package/dist/{plugin → types/plugin}/acl/index.d.ts +0 -0
  97. /package/dist/{plugin → types/plugin}/filter/index.d.ts +0 -0
  98. /package/dist/{plugin → types/plugin}/index.d.ts +0 -0
  99. /package/dist/{plugin → types/plugin}/pagination/index.d.ts +0 -0
  100. /package/dist/{plugin → types/plugin}/pagination/relay.d.ts +0 -0
  101. /package/dist/{plugin → types/plugin}/sort/index.d.ts +0 -0
package/dist/schema.js DELETED
@@ -1,380 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.SchemaBuilder = exports.AbstractSchemaBuilder = void 0;
4
- exports.schema = schema;
5
- const lodash_1 = require("lodash");
6
- const schema_1 = require("@graphql-tools/schema");
7
- const graphql_middleware_1 = require("graphql-middleware");
8
- const graphql_1 = require("graphql");
9
- const objectType_1 = require("./objectType");
10
- const inputObjectType_1 = require("./inputObjectType");
11
- const enumType_1 = require("./enumType");
12
- const unionType_1 = require("./unionType");
13
- const util_1 = require("./util");
14
- const Builder_1 = require("./Builder");
15
- const DefaultScalars = [graphql_1.GraphQLInt, graphql_1.GraphQLFloat, graphql_1.GraphQLString, graphql_1.GraphQLBoolean, graphql_1.GraphQLID];
16
- class AbstractSchemaBuilder {
17
- constructor(name = null) {
18
- this._plugins = [];
19
- this._middleware = [];
20
- this._subSchemas = [];
21
- this._objectTypes = new Map();
22
- this._inputObjectTypes = new Map();
23
- this._enumTypes = new Map();
24
- this._unionTypes = new Map();
25
- this._scalarTypes = new Map();
26
- this._allowedRoles = new Set();
27
- this._deniedRoles = new Set();
28
- this._allowedQueryRoles = new Set();
29
- this._deniedQueryRoles = new Set();
30
- this._allowedMutationRoles = new Set();
31
- this._deniedMutationRoles = new Set();
32
- this._queryObject = new objectType_1.ObjectTypeBuilder('Query');
33
- this._name = name;
34
- this._tag = Math.round(Math.random() * 1000000);
35
- this._addDefaultScalars();
36
- }
37
- naming(strategy) {
38
- this._namingStrategy = strategy;
39
- return this;
40
- }
41
- setDefaultNamingStrategy(strategy) {
42
- this._defaultNamingStrategy = strategy;
43
- }
44
- get namingStrategy() {
45
- return this._namingStrategy || this._defaultNamingStrategy;
46
- }
47
- customConfig(config) {
48
- this._customConfig = config;
49
- return this;
50
- }
51
- object(objectOrName, configurator = null) {
52
- const resolvedArgs = (0, util_1.resolveBuilderArgs)(objectOrName, configurator, objectType_1.ObjectTypeBuilder);
53
- const resolvedBuilder = (0, util_1.resolveBuilder)(resolvedArgs, name => new objectType_1.ObjectTypeBuilder(name));
54
- this._objectTypes.set(resolvedBuilder.name, resolvedBuilder);
55
- return this;
56
- }
57
- getObjectTypes() {
58
- return (0, lodash_1.compact)([this._queryObject, this._mutationObject, ...Array.from(this._objectTypes.values())]);
59
- }
60
- inputObject(objectOrName, configurator = null) {
61
- const resolvedArgs = (0, util_1.resolveBuilderArgs)(objectOrName, configurator, inputObjectType_1.InputObjectTypeBuilder);
62
- const resolvedBuilder = (0, util_1.resolveBuilder)(resolvedArgs, name => new inputObjectType_1.InputObjectTypeBuilder(name));
63
- this._inputObjectTypes.set(resolvedBuilder.name, resolvedBuilder);
64
- return this;
65
- }
66
- getInputObjectTypes() {
67
- return Array.from(this._inputObjectTypes.values());
68
- }
69
- enum(enumOrName, configuratorOrValuesObject = null) {
70
- let builder = null;
71
- let name = null;
72
- let configurator = null;
73
- let valuesObject = null;
74
- if (enumOrName instanceof enumType_1.EnumTypeBuilder) {
75
- builder = enumOrName;
76
- if ((0, lodash_1.isFunction)(configuratorOrValuesObject)) {
77
- configurator = configuratorOrValuesObject;
78
- }
79
- }
80
- else if ((0, lodash_1.isString)(enumOrName)) {
81
- name = enumOrName;
82
- if ((0, lodash_1.isFunction)(configuratorOrValuesObject)) {
83
- configurator = configuratorOrValuesObject;
84
- }
85
- else {
86
- valuesObject = configuratorOrValuesObject;
87
- }
88
- }
89
- const resolvedArgs = { builder, name, configurator };
90
- const resolvedBuilder = (0, util_1.resolveBuilder)(resolvedArgs, name => new enumType_1.EnumTypeBuilder(name, valuesObject));
91
- this._enumTypes.set(resolvedBuilder.name, resolvedBuilder);
92
- return this;
93
- }
94
- getEnumTypes() {
95
- return Array.from(this._enumTypes.values());
96
- }
97
- union(objectOrName, configuratorOrTypes = null) {
98
- let builder = null;
99
- let name = null;
100
- let configurator = null;
101
- let resolvedTypes = null;
102
- if (objectOrName instanceof unionType_1.UnionTypeBuilder) {
103
- builder = objectOrName;
104
- if ((0, lodash_1.isFunction)(configuratorOrTypes)) {
105
- configurator = configuratorOrTypes;
106
- }
107
- }
108
- else if ((0, lodash_1.isString)(objectOrName)) {
109
- name = objectOrName;
110
- if ((0, lodash_1.isFunction)(configuratorOrTypes)) {
111
- configurator = configuratorOrTypes;
112
- }
113
- else if ((0, lodash_1.isArray)(configuratorOrTypes)) {
114
- resolvedTypes = configuratorOrTypes;
115
- }
116
- }
117
- const resolvedArgs = { builder, name, configurator };
118
- const resolvedBuilder = (0, util_1.resolveBuilder)(resolvedArgs, name => new unionType_1.UnionTypeBuilder(name, resolvedTypes));
119
- this._unionTypes.set(resolvedBuilder.name, resolvedBuilder);
120
- return this;
121
- }
122
- getUnionTypes() {
123
- return Array.from(this._unionTypes.values());
124
- }
125
- scalar(scalar) {
126
- this._scalarTypes.set(scalar.name, scalar);
127
- return this;
128
- }
129
- query(fieldOrName, type = null, configurator = null) {
130
- this._queryObject.field(fieldOrName, type, configurator);
131
- return this;
132
- }
133
- mutation(fieldOrName, type = null, configurator = null) {
134
- if (!this._mutationObject) {
135
- this._mutationObject = new objectType_1.ObjectTypeBuilder('Mutation');
136
- }
137
- this._mutationObject.field(fieldOrName, type, configurator);
138
- return this;
139
- }
140
- resolvers(resolvers) {
141
- this._resolvers = resolvers;
142
- return this;
143
- }
144
- queryResolvers(resolvers) {
145
- this._queryResolvers = resolvers;
146
- return this;
147
- }
148
- mutationResolvers(resolvers) {
149
- this._mutationResolvers = resolvers;
150
- return this;
151
- }
152
- allow(...roles) {
153
- roles.forEach(role => this._allowedRoles.add(role));
154
- return this;
155
- }
156
- deny(...roles) {
157
- roles.forEach(role => this._deniedRoles.add(role));
158
- return this;
159
- }
160
- allowQuery(...roles) {
161
- roles.forEach(role => this._allowedQueryRoles.add(role));
162
- return this;
163
- }
164
- denyQuery(...roles) {
165
- roles.forEach(role => this._deniedQueryRoles.add(role));
166
- return this;
167
- }
168
- allowMutation(...roles) {
169
- roles.forEach(role => this._allowedMutationRoles.add(role));
170
- return this;
171
- }
172
- denyMutation(...roles) {
173
- roles.forEach(role => this._deniedMutationRoles.add(role));
174
- return this;
175
- }
176
- merge(schema) {
177
- this._subSchemas.push(schema);
178
- return this;
179
- }
180
- use(...middlewareOrPlugins) {
181
- for (let item of middlewareOrPlugins) {
182
- if ((0, lodash_1.isObjectLike)(item)) {
183
- this._plugins.push(item);
184
- }
185
- else if ((0, lodash_1.isFunction)(item)) {
186
- this._middleware.push(item);
187
- }
188
- }
189
- return this;
190
- }
191
- findType(name, deep = false) {
192
- var _a;
193
- return (_a = this.locateType(name, deep)) === null || _a === void 0 ? void 0 : _a.type;
194
- }
195
- locateType(name, deep = false) {
196
- var _a, _b, _c, _d, _e, _f;
197
- let type = null;
198
- if (name === this._queryObject.name) {
199
- type = this._queryObject;
200
- }
201
- else if (name === ((_a = this._mutationObject) === null || _a === void 0 ? void 0 : _a.name)) {
202
- type = this._mutationObject;
203
- }
204
- else {
205
- type = (_f = (_e = (_d = (_c = (_b = this._objectTypes.get(name)) !== null && _b !== void 0 ? _b : this._inputObjectTypes.get(name)) !== null && _c !== void 0 ? _c : this._enumTypes.get(name)) !== null && _d !== void 0 ? _d : this._unionTypes.get(name)) !== null && _e !== void 0 ? _e : this._scalarTypes.get(name)) !== null && _f !== void 0 ? _f : null;
206
- }
207
- if (!type && deep) {
208
- for (let sub of this._subSchemas) {
209
- const result = sub.locateType(name, true);
210
- if (result) {
211
- return result;
212
- }
213
- }
214
- }
215
- return type ? { schema: this, type } : null;
216
- }
217
- hasType(name, deep = false) {
218
- return !!this.findType(name, deep);
219
- }
220
- findResolver(typeName, fieldName) {
221
- const resolvers = this.compiledResolvers;
222
- let resolver = null;
223
- const typeResolvers = resolvers[typeName];
224
- if (typeResolvers && typeResolvers[fieldName]) {
225
- resolver = typeResolvers[fieldName].bind(typeResolvers);
226
- }
227
- return resolver;
228
- }
229
- get name() {
230
- return (0, Builder_1.resolveName)(this._name);
231
- }
232
- get tag() {
233
- return this._tag;
234
- }
235
- async finalize(rootSchema) {
236
- const resolvedRootSchema = rootSchema || this;
237
- // Assign naming strategy to sub schemas as default
238
- if (this._namingStrategy) {
239
- for (let subSchema of this._subSchemas) {
240
- subSchema.setDefaultNamingStrategy(this._namingStrategy);
241
- }
242
- }
243
- // Attach plugins, middleware & acl rules to sub schemas
244
- for (let subSchema of this._subSchemas) {
245
- this._plugins.forEach(plugin => subSchema.use(plugin));
246
- this._middleware.forEach(middleware => subSchema.use(middleware));
247
- subSchema.allow(...Array.from(this._allowedRoles));
248
- subSchema.deny(...Array.from(this._deniedRoles));
249
- subSchema.allowQuery(...Array.from(this._allowedQueryRoles));
250
- subSchema.denyQuery(...Array.from(this._deniedQueryRoles));
251
- subSchema.allowMutation(...Array.from(this._allowedMutationRoles));
252
- subSchema.denyMutation(...Array.from(this._deniedMutationRoles));
253
- }
254
- await this._executePlugins('beforeFinalizeSchema', plugin => plugin.beforeFinalizeSchema(this));
255
- await this.finalizeSchema();
256
- await this._executePlugins('afterFinalizeSchema', plugin => plugin.afterFinalizeSchema(this));
257
- // Attach plugins to members
258
- for (let objectType of this.getObjectTypes()) {
259
- this._plugins.forEach(plugin => objectType.use(plugin));
260
- }
261
- for (let inputObject of this._inputObjectTypes.values()) {
262
- this._plugins.forEach(plugin => inputObject.use(plugin));
263
- }
264
- for (let unionType of this._unionTypes.values()) {
265
- this._plugins.forEach(plugin => unionType.use(plugin));
266
- }
267
- for (let enumType of this._enumTypes.values()) {
268
- this._plugins.forEach(plugin => enumType.use(plugin));
269
- }
270
- // Apply rules
271
- for (let objectType of Array.from(this._objectTypes.values())) {
272
- objectType.allow(...Array.from(this._allowedRoles)).deny(...Array.from(this._deniedRoles));
273
- }
274
- const fullAllowedQueryRoles = [...Array.from(this._allowedRoles), ...Array.from(this._allowedQueryRoles)];
275
- const fullDeniedQueryRoles = [...Array.from(this._deniedRoles), ...Array.from(this._deniedQueryRoles)];
276
- for (let queryField of this._queryObject.info().fields) {
277
- queryField.allow(...fullAllowedQueryRoles).deny(...fullDeniedQueryRoles);
278
- }
279
- if (this._mutationObject) {
280
- const fullAllowedMutationRoles = [...Array.from(this._allowedRoles), ...Array.from(this._allowedMutationRoles)];
281
- const fullDeniedMutationRoles = [...Array.from(this._deniedRoles), ...Array.from(this._deniedMutationRoles)];
282
- for (let mutationField of this._mutationObject.info().fields) {
283
- mutationField.allow(...fullAllowedMutationRoles).deny(...fullDeniedMutationRoles);
284
- }
285
- }
286
- // Finalize types
287
- const finalizeContext = new Builder_1.FinalizeContext(this, resolvedRootSchema);
288
- for (let objectType of this.getObjectTypes()) {
289
- await objectType.finalize(finalizeContext);
290
- }
291
- for (let inputObjectType of this._inputObjectTypes.values()) {
292
- await inputObjectType.finalize(finalizeContext);
293
- }
294
- for (let unionType of this._unionTypes.values()) {
295
- await unionType.finalize(finalizeContext);
296
- }
297
- for (let enumType of this._enumTypes.values()) {
298
- await enumType.finalize(finalizeContext);
299
- }
300
- // Finalize sub schemas
301
- for (let subSchema of this._subSchemas) {
302
- await subSchema.finalize(resolvedRootSchema);
303
- }
304
- }
305
- async finalizeSchema() { }
306
- async build() {
307
- // Finalize schema
308
- await this.finalize();
309
- // Build schema
310
- this._executePluginsSync('beforeBuild', plugin => plugin.beforeBuild(this));
311
- const resolvedTypes = new Map();
312
- const schema = await this.buildSchema(resolvedTypes);
313
- this._executePluginsSync('afterBuild', plugin => plugin.afterBuild(this, schema));
314
- return schema;
315
- }
316
- async buildSchema(resolvedTypes, rootSchema) {
317
- const resolvedRootSchema = rootSchema || this;
318
- this._executePluginsSync('beforeBuildSchema', plugin => plugin.beforeBuildSchema(this, resolvedRootSchema));
319
- const context = new Builder_1.BuildContext(this, resolvedRootSchema, resolvedTypes);
320
- // Schema
321
- const schemaConfig = Object.assign(Object.assign({}, (this._customConfig || {})), { query: this._queryObject.build(context) });
322
- if (this._mutationObject) {
323
- schemaConfig['mutation'] = this._mutationObject.build(context);
324
- }
325
- const schema = new graphql_1.GraphQLSchema(schemaConfig);
326
- // Create full schema
327
- const fullSchema = (0, graphql_middleware_1.applyMiddleware)(schema, ...this._middleware);
328
- const builtSubSchemas = [];
329
- for (let subSchema of this._subSchemas) {
330
- const builtSchema = await subSchema.buildSchema(resolvedTypes, resolvedRootSchema);
331
- builtSubSchemas.push(builtSchema);
332
- }
333
- const mergedSchema = (0, schema_1.mergeSchemas)({
334
- schemas: [fullSchema, ...builtSubSchemas]
335
- });
336
- this._executePluginsSync('afterBuildSchema', plugin => plugin.afterBuildSchema(this, mergedSchema, resolvedRootSchema));
337
- return mergedSchema;
338
- }
339
- get compiledResolvers() {
340
- let resolvers = this._resolvers ? (0, lodash_1.clone)(this._resolvers) : {};
341
- if (this._queryResolvers) {
342
- resolvers['Query'] = (0, util_1.ensureInstantiated)(this._queryResolvers);
343
- }
344
- if (this._mutationResolvers && this._mutationObject) {
345
- resolvers['Mutation'] = (0, util_1.ensureInstantiated)(this._mutationResolvers);
346
- }
347
- for (let objectType of this._objectTypes.values()) {
348
- const objectResolvers = objectType.getResolvers();
349
- if (objectResolvers) {
350
- resolvers[objectType.name] = objectResolvers;
351
- }
352
- }
353
- return resolvers;
354
- }
355
- async _executePlugins(methodName, fn) {
356
- for (let plugin of this._plugins) {
357
- if (plugin[methodName]) {
358
- await fn(plugin);
359
- }
360
- }
361
- }
362
- _executePluginsSync(methodName, fn) {
363
- for (let plugin of this._plugins) {
364
- if (plugin[methodName]) {
365
- fn(plugin);
366
- }
367
- }
368
- }
369
- _addDefaultScalars() {
370
- DefaultScalars.forEach(scalar => this.scalar(scalar));
371
- }
372
- }
373
- exports.AbstractSchemaBuilder = AbstractSchemaBuilder;
374
- class SchemaBuilder extends AbstractSchemaBuilder {
375
- }
376
- exports.SchemaBuilder = SchemaBuilder;
377
- function schema(name = null) {
378
- return new SchemaBuilder(name);
379
- }
380
- exports.default = schema;
package/dist/unionType.js DELETED
@@ -1,75 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.UnionTypeBuilder = void 0;
7
- exports.unionType = unionType;
8
- const definition_1 = require("graphql/type/definition");
9
- const lodash_1 = require("lodash");
10
- const Builder_1 = __importDefault(require("./Builder"));
11
- class UnionTypeBuilder extends Builder_1.default {
12
- constructor(name, types = null) {
13
- super(name);
14
- this._extensions = new Map();
15
- this._types = new Set(types || []);
16
- }
17
- type(...types) {
18
- types.forEach(role => this._types.add(role));
19
- return this;
20
- }
21
- description(description) {
22
- this._description = description;
23
- return this;
24
- }
25
- extension(name, value) {
26
- this._extensions.set(name, value);
27
- return this;
28
- }
29
- async finalizeBuilder(context) {
30
- const info = this.info();
31
- await this._executePlugins('beforeFinalizeUnionType', plugin => plugin.beforeFinalizeUnionType(this, context, info));
32
- await this.finalizeUnionType(context, info);
33
- await this._executePlugins('afterFinalizeUnionType', plugin => plugin.afterFinalizeUnionType(this, context, info));
34
- }
35
- async finalizeUnionType(context, info) { }
36
- build(context) {
37
- const info = this.info();
38
- this._executePluginsSync('beforeBuildUnionType', plugin => plugin.beforeBuildUnionType(this, context, info));
39
- // Resolve types
40
- const unionType = new definition_1.GraphQLUnionType({
41
- name: this.name,
42
- description: this._description,
43
- types: () => {
44
- let resolvedTypes = [];
45
- for (let type of this._types) {
46
- if ((0, lodash_1.isString)(type)) {
47
- const resolved = context.getType(type);
48
- resolvedTypes.push(resolved);
49
- }
50
- else {
51
- resolvedTypes.push(type);
52
- }
53
- }
54
- return resolvedTypes;
55
- },
56
- extensions: Object.assign({}, Object.fromEntries(this._extensions))
57
- });
58
- this._executePluginsSync('afterBuildUnionType', plugin => plugin.afterBuildUnionType(this, context, info, unionType));
59
- return unionType;
60
- }
61
- info() {
62
- return {
63
- name: this.name,
64
- types: new Set(this._types),
65
- description: this._description,
66
- extensions: new Map(this._extensions),
67
- plugins: (0, lodash_1.clone)(this._plugins)
68
- };
69
- }
70
- }
71
- exports.UnionTypeBuilder = UnionTypeBuilder;
72
- function unionType(name, types = null) {
73
- return new UnionTypeBuilder(name, types);
74
- }
75
- exports.default = unionType;
package/dist/util.js DELETED
@@ -1,142 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.defaultScalarNames = void 0;
4
- exports.resolveAutoBuilderArgs = resolveAutoBuilderArgs;
5
- exports.resolveBuilderArgs = resolveBuilderArgs;
6
- exports.resolveBuilder = resolveBuilder;
7
- exports.resolveType = resolveType;
8
- exports.isTypeInput = isTypeInput;
9
- exports.isTypeScalar = isTypeScalar;
10
- exports.isFieldId = isFieldId;
11
- exports.ensureInstantiated = ensureInstantiated;
12
- exports.getAclExtension = getAclExtension;
13
- exports.camelize = camelize;
14
- const lodash_1 = require("lodash");
15
- const graphql_1 = require("graphql");
16
- const definition_1 = require("graphql/type/definition");
17
- const enumType_1 = require("./enumType");
18
- const inputObjectType_1 = require("./inputObjectType");
19
- exports.defaultScalarNames = ['Int', 'Float', 'String', 'Boolean', 'ID'];
20
- function resolveAutoBuilderArgs(builderOrConfiguratorOrName, configuratorArg, builderType) {
21
- let builder = null;
22
- let name = null;
23
- let configurator = null;
24
- if (builderOrConfiguratorOrName instanceof builderType) {
25
- builder = builderOrConfiguratorOrName;
26
- configurator = configuratorArg;
27
- }
28
- else if ((0, lodash_1.isString)(builderOrConfiguratorOrName)) {
29
- name = builderOrConfiguratorOrName;
30
- configurator = configuratorArg;
31
- }
32
- else {
33
- configurator = builderOrConfiguratorOrName;
34
- }
35
- return {
36
- builder, name, configurator
37
- };
38
- }
39
- function resolveBuilderArgs(builderOrName, configuratorArg, builderType) {
40
- let builder = null;
41
- let name = null;
42
- let configurator = null;
43
- if (builderOrName instanceof builderType) {
44
- builder = builderOrName;
45
- configurator = configuratorArg;
46
- }
47
- else if ((0, lodash_1.isString)(builderOrName)) {
48
- name = builderOrName;
49
- configurator = configuratorArg;
50
- }
51
- return {
52
- builder, name, configurator
53
- };
54
- }
55
- function resolveBuilder(args, defaultBuilderGenerator) {
56
- let resolvedBuilder = args.builder;
57
- if (!resolvedBuilder) {
58
- resolvedBuilder = defaultBuilderGenerator(args.name);
59
- }
60
- if (args.configurator) {
61
- args.configurator(resolvedBuilder);
62
- }
63
- return resolvedBuilder;
64
- }
65
- const nonNullTypePattern = /(.+)!$/;
66
- const nonNullListTypePattern = /\[(.+)!]/;
67
- const listTypePattern = /\[(.+)]/;
68
- const baseTypePattern = /\[?(\w+)]?!?/;
69
- function resolveType(type) {
70
- if (!(0, lodash_1.isString)(type)) {
71
- return { type, nonNull: false, nonNullList: false, list: false };
72
- }
73
- const nonNull = nonNullTypePattern.test(type);
74
- const nonNullList = nonNullListTypePattern.test(type);
75
- const list = listTypePattern.test(type);
76
- const baseMatches = baseTypePattern.exec(type);
77
- return { nonNull, list, nonNullList, type: baseMatches[1] };
78
- }
79
- function isTypeInput(type, schema) {
80
- if ((0, lodash_1.isString)(type)) {
81
- const typeName = type;
82
- if (exports.defaultScalarNames.indexOf(typeName) >= 0) {
83
- return true;
84
- }
85
- else {
86
- const builderType = schema.findType(typeName, true);
87
- if (builderType && (builderType instanceof enumType_1.EnumTypeBuilder || builderType instanceof graphql_1.GraphQLScalarType || builderType instanceof inputObjectType_1.InputObjectTypeBuilder)) {
88
- return true;
89
- }
90
- }
91
- }
92
- else if (type instanceof graphql_1.GraphQLScalarType || type instanceof definition_1.GraphQLEnumType) {
93
- return true;
94
- }
95
- return false;
96
- }
97
- function isTypeScalar(type, schema) {
98
- if ((0, lodash_1.isString)(type)) {
99
- const typeName = type;
100
- if (exports.defaultScalarNames.indexOf(typeName) >= 0) {
101
- return true;
102
- }
103
- else {
104
- const builderType = schema.findType(typeName, true);
105
- if (builderType && builderType instanceof graphql_1.GraphQLScalarType) {
106
- return true;
107
- }
108
- }
109
- }
110
- else if (type instanceof graphql_1.GraphQLScalarType) {
111
- return true;
112
- }
113
- return false;
114
- }
115
- function isFieldId(info) {
116
- return info.type === 'ID' && info.name === 'id';
117
- }
118
- function ensureInstantiated(input, ...args) {
119
- if ((0, lodash_1.isFunction)(input)) {
120
- try {
121
- let inputClass = input;
122
- return new inputClass(...args);
123
- }
124
- catch (_a) {
125
- // Silence
126
- }
127
- }
128
- return input;
129
- }
130
- function getAclExtension(allowed, denied) {
131
- return {
132
- allowedRoles: Array.from(allowed).join(','),
133
- deniedRoles: Array.from(denied).join(','),
134
- };
135
- }
136
- function camelize(text) {
137
- return text.replace(/^([A-Z])|[\s-_]+(\w)/g, function (match, p1, p2) {
138
- if (p2)
139
- return p2.toUpperCase();
140
- return p1.toLowerCase();
141
- });
142
- }
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes