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