@tinkerstack/graphql-annotation 0.0.0 → 0.0.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/dist/index.js CHANGED
@@ -2,7 +2,7 @@ var __defProp = Object.defineProperty;
2
2
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
3
  var __getOwnPropNames = Object.getOwnPropertyNames;
4
4
  var __hasOwnProp = Object.prototype.hasOwnProperty;
5
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
5
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
6
6
  var __export = (target, all) => {
7
7
  for (var name in all)
8
8
  __defProp(target, name, { get: all[name], enumerable: true });
@@ -16,16 +16,6 @@ var __copyProps = (to, from, except, desc) => {
16
16
  return to;
17
17
  };
18
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
- var __decorateClass = (decorators, target, key, kind) => {
20
- var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
21
- for (var i = decorators.length - 1, decorator; i >= 0; i--)
22
- if (decorator = decorators[i])
23
- result = (kind ? decorator(target, key, result) : decorator(result)) || result;
24
- if (kind && result) __defProp(target, key, result);
25
- return result;
26
- };
27
- var __decorateParam = (index, decorator) => (target, key) => decorator(target, key, index);
28
- var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
29
19
 
30
20
  // src/index.ts
31
21
  var index_exports = {};
@@ -76,47 +66,38 @@ function Annotate(name, opts) {
76
66
  case "number": {
77
67
  const paramIndex = descriptorOrParameterIndex;
78
68
  const paramName = opts?.parameter;
79
- if (!paramName)
80
- throw new Error(
81
- `Unable to apply annotation "${annotationName}". Parameter name not specified.`
82
- );
83
- (0, import_graphql.Args)(paramName)(target, propertyKey, paramIndex);
84
- _updateAnnotation(
85
- target.constructor,
86
- (meta) => ({
87
- ...meta,
88
- [`${annotationName}@${paramIndex}`]: {
89
- annotation: annotationName,
90
- data: annotationData,
91
- target: {
92
- type: "parameter",
93
- paramIndex,
94
- paramName
95
- }
69
+ if (!paramName) throw new Error(`Unable to apply annotation "${annotationName}". Parameter name not specified.`);
70
+ (0, import_graphql.Args)({
71
+ name: paramName,
72
+ type: opts?.type,
73
+ description: opts?.description
74
+ })(target, propertyKey, paramIndex);
75
+ _updateAnnotation(target.constructor, (meta) => ({
76
+ ...meta,
77
+ [`${annotationName}@${paramIndex}`]: {
78
+ annotation: annotationName,
79
+ data: annotationData,
80
+ target: {
81
+ type: "parameter",
82
+ paramIndex,
83
+ paramName
96
84
  }
97
- }),
98
- propertyKey
99
- );
85
+ }
86
+ }), propertyKey);
100
87
  break;
101
88
  }
102
89
  default:
103
- throw new Error(
104
- `Unable to attach annotation "${name}". Unsupported target.`
105
- );
90
+ throw new Error(`Unable to attach annotation "${name}". Unsupported target.`);
106
91
  }
107
92
  };
108
93
  }
94
+ __name(Annotate, "Annotate");
109
95
  function _updateAnnotation(target, updateFn, propertyKey) {
110
96
  const meta = Reflect.getMetadata(ANNOTATION_METADATA, target) ?? {};
111
- if (propertyKey)
112
- Reflect.defineMetadata(
113
- ANNOTATION_METADATA,
114
- updateFn(meta),
115
- target,
116
- propertyKey
117
- );
97
+ if (propertyKey) Reflect.defineMetadata(ANNOTATION_METADATA, updateFn(meta), target, propertyKey);
118
98
  else Reflect.defineMetadata(ANNOTATION_METADATA, updateFn(meta), target);
119
99
  }
100
+ __name(_updateAnnotation, "_updateAnnotation");
120
101
  function ResolveAnnotation(name) {
121
102
  return (target, property, descriptor) => {
122
103
  (0, import_common.SetMetadata)(ANNOTATION_RESOLVER_METADATA, {
@@ -124,41 +105,119 @@ function ResolveAnnotation(name) {
124
105
  })(target, property, descriptor);
125
106
  };
126
107
  }
108
+ __name(ResolveAnnotation, "ResolveAnnotation");
127
109
 
128
110
  // src/modules/core/annotation.loader.ts
129
111
  var import_stitch = require("@graphql-tools/stitch");
130
112
  var import_utils = require("@graphql-tools/utils");
131
113
  var import_wrap2 = require("@graphql-tools/wrap");
132
- var import_common3 = require("@nestjs/common");
133
- var import_graphql3 = require("@nestjs/graphql");
114
+ var import_common4 = require("@nestjs/common");
115
+ var import_core3 = require("@nestjs/core");
116
+ var import_graphql4 = require("@nestjs/graphql");
134
117
  var import_gql_paramtype = require("@nestjs/graphql/dist/enums/gql-paramtype.enum");
135
118
  var import_graphql_request = require("graphql-request");
136
119
 
137
120
  // src/modules/core/annotation.resolver.ts
138
- var import_common2 = require("@nestjs/common");
139
- var import_graphql2 = require("@nestjs/graphql");
121
+ var import_common3 = require("@nestjs/common");
122
+ var import_core2 = require("@nestjs/core");
123
+ var import_graphql3 = require("@nestjs/graphql");
140
124
  var import_graphql_scalars = require("graphql-scalars");
141
125
  var import_reflect_metadata2 = require("reflect-metadata");
126
+
127
+ // src/modules/core/resolver.explorer.ts
128
+ var import_common2 = require("@nestjs/common");
129
+ var import_core = require("@nestjs/core");
130
+ var import_graphql2 = require("@nestjs/graphql");
131
+ function _ts_decorate(decorators, target, key, desc) {
132
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
133
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
134
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
135
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
136
+ }
137
+ __name(_ts_decorate, "_ts_decorate");
138
+ function _ts_metadata(k, v) {
139
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
140
+ }
141
+ __name(_ts_metadata, "_ts_metadata");
142
+ var ResolverDiscoveryService = class {
143
+ static {
144
+ __name(this, "ResolverDiscoveryService");
145
+ }
146
+ discoveryService;
147
+ constructor(discoveryService) {
148
+ this.discoveryService = discoveryService;
149
+ }
150
+ explore() {
151
+ const wrappedProviders = this.discoveryService.getProviders();
152
+ return wrappedProviders.flatMap((wrapped) => {
153
+ const { instance } = wrapped;
154
+ if (!instance) return [];
155
+ const isResolver = Reflect.hasMetadata(import_graphql2.RESOLVER_TYPE_METADATA, instance.constructor);
156
+ if (!isResolver) return [];
157
+ return wrapped;
158
+ });
159
+ }
160
+ };
161
+ ResolverDiscoveryService = _ts_decorate([
162
+ (0, import_common2.Injectable)(),
163
+ _ts_metadata("design:type", Function),
164
+ _ts_metadata("design:paramtypes", [
165
+ typeof import_core.DiscoveryService === "undefined" ? Object : import_core.DiscoveryService
166
+ ])
167
+ ], ResolverDiscoveryService);
168
+
169
+ // src/modules/core/annotation.resolver.ts
170
+ function _ts_decorate2(decorators, target, key, desc) {
171
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
172
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
173
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
174
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
175
+ }
176
+ __name(_ts_decorate2, "_ts_decorate");
177
+ function _ts_metadata2(k, v) {
178
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
179
+ }
180
+ __name(_ts_metadata2, "_ts_metadata");
181
+ function _ts_param(paramIndex, decorator) {
182
+ return function(target, key) {
183
+ decorator(target, key, paramIndex);
184
+ };
185
+ }
186
+ __name(_ts_param, "_ts_param");
142
187
  var GraphQLAnnotationMeta = class {
188
+ static {
189
+ __name(this, "GraphQLAnnotationMeta");
190
+ }
143
191
  name;
144
192
  resolvers;
145
193
  };
146
- __decorateClass([
147
- (0, import_graphql2.Field)(() => String)
148
- ], GraphQLAnnotationMeta.prototype, "name", 2);
149
- __decorateClass([
150
- (0, import_graphql2.Field)(() => import_graphql_scalars.GraphQLJSONObject, { name: "resolvers" })
151
- ], GraphQLAnnotationMeta.prototype, "resolvers", 2);
152
- GraphQLAnnotationMeta = __decorateClass([
153
- (0, import_graphql2.ObjectType)()
194
+ _ts_decorate2([
195
+ (0, import_graphql3.Field)(() => String),
196
+ _ts_metadata2("design:type", String)
197
+ ], GraphQLAnnotationMeta.prototype, "name", void 0);
198
+ _ts_decorate2([
199
+ (0, import_graphql3.Field)(() => import_graphql_scalars.GraphQLJSONObject, {
200
+ name: "resolvers"
201
+ }),
202
+ _ts_metadata2("design:type", typeof GraphQLResolversAnnotations === "undefined" ? Object : GraphQLResolversAnnotations)
203
+ ], GraphQLAnnotationMeta.prototype, "resolvers", void 0);
204
+ GraphQLAnnotationMeta = _ts_decorate2([
205
+ (0, import_graphql3.ObjectType)()
154
206
  ], GraphQLAnnotationMeta);
207
+ var ANNOTATION_QUERY_NAME = "_annotations";
155
208
  var GraphQLAnnotationResolver = class {
209
+ static {
210
+ __name(this, "GraphQLAnnotationResolver");
211
+ }
212
+ metadataScanner;
213
+ resolverDiscoveryService;
214
+ meta;
215
+ _logger = new import_common3.Logger("GraphQLAnnotationModule");
156
216
  constructor(metadataScanner, resolverDiscoveryService, meta) {
157
217
  this.metadataScanner = metadataScanner;
158
218
  this.resolverDiscoveryService = resolverDiscoveryService;
159
219
  this.meta = meta;
160
220
  }
161
- _logger = new import_common2.Logger("GraphQLAnnotationModule");
162
221
  async getGraphQLAnnotations() {
163
222
  return {
164
223
  ...this.meta,
@@ -172,41 +231,36 @@ var GraphQLAnnotationResolver = class {
172
231
  compileResolversAnnotations() {
173
232
  const instances = this.resolverDiscoveryService.explore();
174
233
  const resolversAnnotations = {};
175
- for (const { instance } of instances)
176
- for (const methodName of this.metadataScanner.getAllMethodNames(
177
- Object.getPrototypeOf(instance)
178
- )) {
179
- const annotations = [
180
- ...Object.values(
181
- Reflect.getMetadata(ANNOTATION_METADATA, instance[methodName]) ?? {}
182
- ),
183
- ...Object.values(
184
- Reflect.getMetadata(
185
- ANNOTATION_METADATA,
186
- instance.constructor,
187
- methodName
188
- ) ?? {}
189
- )
190
- ];
191
- if (annotations.length <= 0) continue;
192
- resolversAnnotations[methodName] = annotations;
193
- this._logger.log(
194
- `Discovered annotated resolver "${instance.constructor.name}.${methodName}" with ${annotations.length} annotation(s)`
195
- );
196
- }
234
+ for (const { instance } of instances) for (const methodName of this.metadataScanner.getAllMethodNames(Object.getPrototypeOf(instance))) {
235
+ const annotations = [
236
+ ...Object.values(Reflect.getMetadata(ANNOTATION_METADATA, instance[methodName]) ?? {}),
237
+ ...Object.values(Reflect.getMetadata(ANNOTATION_METADATA, instance.constructor, methodName) ?? {})
238
+ ];
239
+ if (annotations.length <= 0) continue;
240
+ resolversAnnotations[methodName] = annotations;
241
+ this._logger.log(`Discovered annotated resolver "${instance.constructor.name}.${methodName}" with ${annotations.length} annotation(s)`);
242
+ }
197
243
  return resolversAnnotations;
198
244
  }
199
245
  };
200
- __publicField(GraphQLAnnotationResolver, "QUERY_NAME", "_annotations");
201
- __decorateClass([
202
- (0, import_graphql2.Query)(() => GraphQLAnnotationMeta, {
203
- name: GraphQLAnnotationResolver.QUERY_NAME
204
- })
205
- ], GraphQLAnnotationResolver.prototype, "getGraphQLAnnotations", 1);
206
- GraphQLAnnotationResolver = __decorateClass([
207
- (0, import_graphql2.Resolver)(),
208
- (0, import_common2.Injectable)(),
209
- __decorateParam(2, (0, import_common2.Inject)(ANNOTATION_RESOLVER_METADATA))
246
+ _ts_decorate2([
247
+ (0, import_graphql3.Query)(() => GraphQLAnnotationMeta, {
248
+ name: ANNOTATION_QUERY_NAME
249
+ }),
250
+ _ts_metadata2("design:type", Function),
251
+ _ts_metadata2("design:paramtypes", []),
252
+ _ts_metadata2("design:returntype", Promise)
253
+ ], GraphQLAnnotationResolver.prototype, "getGraphQLAnnotations", null);
254
+ GraphQLAnnotationResolver = _ts_decorate2([
255
+ (0, import_graphql3.Resolver)(),
256
+ (0, import_common3.Injectable)(),
257
+ _ts_param(2, (0, import_common3.Inject)(ANNOTATION_RESOLVER_METADATA)),
258
+ _ts_metadata2("design:type", Function),
259
+ _ts_metadata2("design:paramtypes", [
260
+ typeof import_core2.MetadataScanner === "undefined" ? Object : import_core2.MetadataScanner,
261
+ typeof ResolverDiscoveryService === "undefined" ? Object : ResolverDiscoveryService,
262
+ typeof GraphQLAnnotationResolverMetadata === "undefined" ? Object : GraphQLAnnotationResolverMetadata
263
+ ])
210
264
  ], GraphQLAnnotationResolver);
211
265
 
212
266
  // src/modules/core/annotation.utils.ts
@@ -219,9 +273,9 @@ async function loadGraphQLSchema(url) {
219
273
  return {
220
274
  schema: await (0, import_wrap.schemaFromExecutor)(executor),
221
275
  executor
222
- // Has to be included.
223
276
  };
224
277
  }
278
+ __name(loadGraphQLSchema, "loadGraphQLSchema");
225
279
  function split(array, predicate) {
226
280
  const match = [];
227
281
  const rest = [];
@@ -235,71 +289,64 @@ function split(array, predicate) {
235
289
  rest
236
290
  ];
237
291
  }
292
+ __name(split, "split");
238
293
  function shallowMerge(objects) {
239
294
  const res = {};
240
295
  objects.forEach((o) => Object.assign(res, o));
241
296
  return res;
242
297
  }
298
+ __name(shallowMerge, "shallowMerge");
243
299
  function isPlainObject(obj) {
244
300
  const prototype = Object.getPrototypeOf(obj);
245
301
  return prototype === Object.getPrototypeOf({}) || prototype === null;
246
302
  }
303
+ __name(isPlainObject, "isPlainObject");
247
304
 
248
305
  // src/modules/core/annotation.loader.ts
249
306
  var import_class_transformer = require("class-transformer");
307
+ function _ts_decorate3(decorators, target, key, desc) {
308
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
309
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
310
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
311
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
312
+ }
313
+ __name(_ts_decorate3, "_ts_decorate");
314
+ function _ts_metadata3(k, v) {
315
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
316
+ }
317
+ __name(_ts_metadata3, "_ts_metadata");
250
318
  var GraphQLAnnotatedSchemaLoader = class {
319
+ static {
320
+ __name(this, "GraphQLAnnotatedSchemaLoader");
321
+ }
322
+ resolverDiscoveryService;
323
+ metadataScanner;
324
+ externalContextCreator;
325
+ _logger = new import_common4.Logger("GraphQLAnnotationModule");
251
326
  constructor(resolverDiscoveryService, metadataScanner, externalContextCreator) {
252
327
  this.resolverDiscoveryService = resolverDiscoveryService;
253
328
  this.metadataScanner = metadataScanner;
254
329
  this.externalContextCreator = externalContextCreator;
255
330
  }
256
- _logger = new import_common3.Logger("GraphQLAnnotationModule");
257
331
  async load(sources) {
258
332
  const loadedSources = await this.batchLoadSources(sources);
259
333
  const schema = (0, import_stitch.stitchSchemas)({
260
334
  subschemas: loadedSources.map((s) => s.subschema)
261
335
  });
262
- const annotations = shallowMerge(
263
- loadedSources.map((s) => s.annotation)
264
- );
336
+ const annotations = shallowMerge(loadedSources.map((s) => s.annotation));
265
337
  const annotationResolvers = await this.discoverAnnotationResolvers();
266
- return this.embedAnnotationResolversToSchema(
267
- schema,
268
- annotations,
269
- annotationResolvers
270
- );
338
+ return this.embedAnnotationResolversToSchema(schema, annotations, annotationResolvers);
271
339
  }
272
340
  async discoverAnnotationResolvers() {
273
341
  const annotationResolvers = /* @__PURE__ */ new Map();
274
342
  const paramFactory = new GraphQLAnnotationResolverParamsFactory();
275
343
  const instances = this.resolverDiscoveryService.explore();
276
- for (const { instance } of instances)
277
- for (const methodName of this.metadataScanner.getAllMethodNames(
278
- Object.getPrototypeOf(instance)
279
- )) {
280
- const resolverMeta = Reflect.getMetadata(
281
- ANNOTATION_RESOLVER_METADATA,
282
- instance[methodName]
283
- );
284
- if (!resolverMeta) continue;
285
- this._logger.log(
286
- `Discovered resolver for annotation "${resolverMeta.annotation}"`
287
- );
288
- annotationResolvers.set(
289
- resolverMeta.annotation,
290
- this.externalContextCreator.create(
291
- instance,
292
- instance[methodName],
293
- methodName,
294
- import_graphql3.PARAM_ARGS_METADATA,
295
- paramFactory,
296
- void 0,
297
- void 0,
298
- void 0,
299
- "graphql"
300
- )
301
- );
302
- }
344
+ for (const { instance } of instances) for (const methodName of this.metadataScanner.getAllMethodNames(Object.getPrototypeOf(instance))) {
345
+ const resolverMeta = Reflect.getMetadata(ANNOTATION_RESOLVER_METADATA, instance[methodName]);
346
+ if (!resolverMeta) continue;
347
+ this._logger.log(`Discovered resolver for annotation "${resolverMeta.annotation}"`);
348
+ annotationResolvers.set(resolverMeta.annotation, this.externalContextCreator.create(instance, instance[methodName], methodName, import_graphql4.PARAM_ARGS_METADATA, paramFactory, void 0, void 0, void 0, "graphql"));
349
+ }
303
350
  return annotationResolvers;
304
351
  }
305
352
  async batchLoadSources(sources) {
@@ -314,9 +361,7 @@ var GraphQLAnnotatedSchemaLoader = class {
314
361
  annotation: await this.loadAnnotations(url)
315
362
  };
316
363
  loaded2.subschema.transforms = [
317
- new import_wrap2.FilterRootFields(
318
- (op, fieldName) => !fieldName.endsWith(GraphQLAnnotationResolver.QUERY_NAME)
319
- )
364
+ new import_wrap2.FilterRootFields((op, fieldName) => !fieldName.endsWith(ANNOTATION_QUERY_NAME))
320
365
  ];
321
366
  this._logger.log(`Loaded schema for ${loadId}`);
322
367
  return loaded2;
@@ -325,14 +370,8 @@ var GraphQLAnnotatedSchemaLoader = class {
325
370
  throw err;
326
371
  }
327
372
  });
328
- const [loaded, failed] = split(
329
- await Promise.allSettled(pending),
330
- (q) => q.status === "fulfilled"
331
- );
332
- if (failed.length > 0)
333
- throw new Error(
334
- `Failed to load ${failed.length} schema(s) from sources.`
335
- );
373
+ const [loaded, failed] = split(await Promise.allSettled(pending), (q) => q.status === "fulfilled");
374
+ if (failed.length > 0) throw new Error(`Failed to load ${failed.length} schema(s) from sources.`);
336
375
  return loaded.map((l) => l.value);
337
376
  }
338
377
  async loadAnnotations(url) {
@@ -340,14 +379,14 @@ var GraphQLAnnotatedSchemaLoader = class {
340
379
  try {
341
380
  const res = await client.rawRequest(`
342
381
  query IntrospectAnnotations {
343
- ${GraphQLAnnotationResolver.QUERY_NAME} {
382
+ ${ANNOTATION_QUERY_NAME} {
344
383
  name
345
384
  resolvers
346
385
  }
347
386
  }
348
387
  `);
349
388
  this._logger.log(`Loaded annotations for ${url}`);
350
- return res.data[GraphQLAnnotationResolver.QUERY_NAME];
389
+ return res.data[ANNOTATION_QUERY_NAME];
351
390
  } catch (err) {
352
391
  this._logger.warn(`Failed to load annotations at ${url}, assuming empty`);
353
392
  return {};
@@ -359,65 +398,58 @@ var GraphQLAnnotatedSchemaLoader = class {
359
398
  const fieldAnnotations = (annotations.resolvers[name] ?? []).map((info) => ({
360
399
  ...info,
361
400
  resolver: annotationResolvers.get(info.annotation)
362
- // NOTE: should be validated in filter
363
401
  })).filter((info) => {
364
402
  const annotationHasResolver = info.resolver !== void 0;
365
- if (!annotationHasResolver)
366
- this._logger.warn(
367
- `Found unhandled annotation "${info.annotation}", skipping linking process`
368
- );
403
+ if (!annotationHasResolver) this._logger.warn(`Found unhandled annotation "${info.annotation}", skipping linking process`);
369
404
  return annotationHasResolver;
370
405
  });
371
406
  if (fieldAnnotations.length <= 0) return fieldSchema;
372
- for (const annotation of fieldAnnotations)
373
- if (annotation.target.type === "parameter" && fieldSchema.args)
374
- delete fieldSchema.args[annotation.target.paramName];
407
+ for (const annotation of fieldAnnotations) if (annotation.target.type === "parameter" && fieldSchema.args) delete fieldSchema.args[annotation.target.paramName];
375
408
  const defaultResolver = fieldSchema.resolve;
376
409
  fieldSchema.resolve = async function(parent, args, context, info) {
377
- const annotationCallbacks = await Promise.all(
378
- fieldAnnotations.map(async (annotation) => ({
379
- annotation,
380
- return: await annotation.resolver(
381
- ...[
382
- info.rootValue,
383
- annotation.data,
384
- context,
385
- info
386
- ]
387
- )
388
- }))
389
- );
390
- const resolvedParams = annotationCallbacks.reduce(
391
- (params, call) => {
392
- if (call.annotation.target.type !== "parameter") return params;
393
- const returnedClassType = typeof call.return === "object" && !isPlainObject(call.return);
394
- const returnValue = returnedClassType ? (0, import_class_transformer.instanceToPlain)(call.return) : call.return;
395
- params[call.annotation.target.paramName] = returnValue;
396
- return params;
397
- },
398
- {}
399
- );
400
- return defaultResolver(
401
- parent,
402
- { ...args, ...resolvedParams },
403
- context,
404
- info
405
- );
410
+ const annotationCallbacks = await Promise.all(fieldAnnotations.map(async (annotation) => ({
411
+ annotation,
412
+ return: await annotation.resolver(...[
413
+ info.rootValue,
414
+ annotation.data,
415
+ context,
416
+ info
417
+ ])
418
+ })));
419
+ const resolvedParams = annotationCallbacks.reduce((params, call) => {
420
+ if (call.annotation.target.type !== "parameter") return params;
421
+ const returnedClassType = typeof call.return === "object" && !isPlainObject(call.return);
422
+ const returnValue = returnedClassType ? (0, import_class_transformer.instanceToPlain)(call.return) : call.return;
423
+ params[call.annotation.target.paramName] = returnValue;
424
+ return params;
425
+ }, {});
426
+ return defaultResolver(parent, {
427
+ ...args,
428
+ ...resolvedParams
429
+ }, context, info);
406
430
  };
407
431
  return fieldSchema;
408
432
  }
409
433
  });
410
434
  }
411
435
  };
412
- GraphQLAnnotatedSchemaLoader = __decorateClass([
413
- (0, import_common3.Injectable)()
436
+ GraphQLAnnotatedSchemaLoader = _ts_decorate3([
437
+ (0, import_common4.Injectable)(),
438
+ _ts_metadata3("design:type", Function),
439
+ _ts_metadata3("design:paramtypes", [
440
+ typeof ResolverDiscoveryService === "undefined" ? Object : ResolverDiscoveryService,
441
+ typeof import_core3.MetadataScanner === "undefined" ? Object : import_core3.MetadataScanner,
442
+ typeof import_core3.ExternalContextCreator === "undefined" ? Object : import_core3.ExternalContextCreator
443
+ ])
414
444
  ], GraphQLAnnotatedSchemaLoader);
415
- var GraphQLAnnotationResolverParamsFactory = class {
445
+ var GraphQLAnnotationResolverParamsFactory = class GraphQLAnnotationResolverParamsFactory2 {
446
+ static {
447
+ __name(this, "GraphQLAnnotationResolverParamsFactory");
448
+ }
416
449
  // This param factory extends graphql's own just with different inputs from annotations instead.
417
450
  // https://github.com/nestjs/graphql/blob/master/packages/graphql/lib/factories/params.factory.ts#L9
418
451
  exchangeKeyForValue(type, possibleKey, argsContext) {
419
452
  if (!argsContext) return null;
420
- console.log(type, possibleKey, argsContext);
421
453
  const args = {
422
454
  parentValue: argsContext[0],
423
455
  data: argsContext[1],
@@ -441,62 +473,55 @@ var GraphQLAnnotationResolverParamsFactory = class {
441
473
 
442
474
  // src/modules/core/annotation.module.ts
443
475
  var import_common5 = require("@nestjs/common");
444
- var import_core = require("@nestjs/core");
445
-
446
- // src/modules/core/resolver.explorer.ts
447
- var import_common4 = require("@nestjs/common");
448
- var import_graphql4 = require("@nestjs/graphql");
449
- var ResolverDiscoveryService = class {
450
- constructor(discoveryService) {
451
- this.discoveryService = discoveryService;
452
- }
453
- explore() {
454
- const wrappedProviders = this.discoveryService.getProviders();
455
- return wrappedProviders.flatMap((wrapped) => {
456
- const { instance } = wrapped;
457
- if (!instance) return [];
458
- const isResolver = Reflect.hasMetadata(
459
- import_graphql4.RESOLVER_TYPE_METADATA,
460
- instance.constructor
461
- );
462
- if (!isResolver) return [];
463
- return wrapped;
464
- });
476
+ var import_core4 = require("@nestjs/core");
477
+ function _ts_decorate4(decorators, target, key, desc) {
478
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
479
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
480
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
481
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
482
+ }
483
+ __name(_ts_decorate4, "_ts_decorate");
484
+ var GraphQLAnnotationModule = class _GraphQLAnnotationModule {
485
+ static {
486
+ __name(this, "GraphQLAnnotationModule");
465
487
  }
466
- };
467
- ResolverDiscoveryService = __decorateClass([
468
- (0, import_common4.Injectable)()
469
- ], ResolverDiscoveryService);
470
-
471
- // src/modules/core/annotation.module.ts
472
- var GraphQLAnnotationModule = class {
473
488
  static forRoot(opts) {
474
- if (opts?.serveAnnotations)
475
- return {
476
- global: true,
477
- module: GraphQLAnnotationModule,
478
- imports: [import_core.DiscoveryModule],
479
- providers: [
480
- ResolverDiscoveryService,
481
- GraphQLAnnotatedSchemaLoader,
482
- {
483
- provide: ANNOTATION_RESOLVER_METADATA,
484
- useValue: opts.serveConfig
485
- },
486
- GraphQLAnnotationResolver
487
- ],
488
- exports: [GraphQLAnnotatedSchemaLoader]
489
- };
489
+ if (opts?.serveAnnotations) return {
490
+ global: true,
491
+ module: _GraphQLAnnotationModule,
492
+ imports: [
493
+ import_core4.DiscoveryModule
494
+ ],
495
+ providers: [
496
+ ResolverDiscoveryService,
497
+ GraphQLAnnotatedSchemaLoader,
498
+ {
499
+ provide: ANNOTATION_RESOLVER_METADATA,
500
+ useValue: opts.serveConfig
501
+ },
502
+ GraphQLAnnotationResolver
503
+ ],
504
+ exports: [
505
+ GraphQLAnnotatedSchemaLoader
506
+ ]
507
+ };
490
508
  return {
491
509
  global: true,
492
- module: GraphQLAnnotationModule,
493
- imports: [import_core.DiscoveryModule],
494
- providers: [ResolverDiscoveryService, GraphQLAnnotatedSchemaLoader],
495
- exports: [GraphQLAnnotatedSchemaLoader]
510
+ module: _GraphQLAnnotationModule,
511
+ imports: [
512
+ import_core4.DiscoveryModule
513
+ ],
514
+ providers: [
515
+ ResolverDiscoveryService,
516
+ GraphQLAnnotatedSchemaLoader
517
+ ],
518
+ exports: [
519
+ GraphQLAnnotatedSchemaLoader
520
+ ]
496
521
  };
497
522
  }
498
523
  };
499
- GraphQLAnnotationModule = __decorateClass([
524
+ GraphQLAnnotationModule = _ts_decorate4([
500
525
  (0, import_common5.Module)({})
501
526
  ], GraphQLAnnotationModule);
502
527
  // Annotate the CommonJS export names for ESM import in node: