@tinkerstack/graphql-annotation 0.0.8 → 0.0.9
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 +10 -7
- package/dist/index.mjs +10 -7
- package/package.json +2 -2
- package/src/modules/core/annotation.loader.ts +20 -9
package/dist/index.js
CHANGED
|
@@ -290,12 +290,6 @@ function split(array, predicate) {
|
|
|
290
290
|
];
|
|
291
291
|
}
|
|
292
292
|
__name(split, "split");
|
|
293
|
-
function shallowMerge(objects) {
|
|
294
|
-
const res = {};
|
|
295
|
-
objects.forEach((o) => Object.assign(res, o));
|
|
296
|
-
return res;
|
|
297
|
-
}
|
|
298
|
-
__name(shallowMerge, "shallowMerge");
|
|
299
293
|
function isPlainObject(obj) {
|
|
300
294
|
const prototype = Object.getPrototypeOf(obj);
|
|
301
295
|
return prototype === Object.getPrototypeOf({}) || prototype === null;
|
|
@@ -335,7 +329,16 @@ var GraphQLAnnotatedSchemaLoader = class {
|
|
|
335
329
|
const schema = (0, import_stitch.stitchSchemas)({
|
|
336
330
|
subschemas: loadedSources.map((s) => s.subschema)
|
|
337
331
|
});
|
|
338
|
-
const annotations =
|
|
332
|
+
const annotations = {
|
|
333
|
+
name: loadedSources.map((s) => s.annotation?.name).filter(Boolean).join(","),
|
|
334
|
+
resolvers: loadedSources.reduce((acc, s) => {
|
|
335
|
+
for (const [field, infos] of Object.entries(s.annotation?.resolvers ?? {})) acc[field] = acc[field] ? [
|
|
336
|
+
...acc[field],
|
|
337
|
+
...infos
|
|
338
|
+
] : infos;
|
|
339
|
+
return acc;
|
|
340
|
+
}, {})
|
|
341
|
+
};
|
|
339
342
|
const annotationResolvers = await this.discoverAnnotationResolvers();
|
|
340
343
|
return this.embedAnnotationResolversToSchema(schema, annotations, annotationResolvers);
|
|
341
344
|
}
|
package/dist/index.mjs
CHANGED
|
@@ -261,12 +261,6 @@ function split(array, predicate) {
|
|
|
261
261
|
];
|
|
262
262
|
}
|
|
263
263
|
__name(split, "split");
|
|
264
|
-
function shallowMerge(objects) {
|
|
265
|
-
const res = {};
|
|
266
|
-
objects.forEach((o) => Object.assign(res, o));
|
|
267
|
-
return res;
|
|
268
|
-
}
|
|
269
|
-
__name(shallowMerge, "shallowMerge");
|
|
270
264
|
function isPlainObject(obj) {
|
|
271
265
|
const prototype = Object.getPrototypeOf(obj);
|
|
272
266
|
return prototype === Object.getPrototypeOf({}) || prototype === null;
|
|
@@ -306,7 +300,16 @@ var GraphQLAnnotatedSchemaLoader = class {
|
|
|
306
300
|
const schema = stitchSchemas({
|
|
307
301
|
subschemas: loadedSources.map((s) => s.subschema)
|
|
308
302
|
});
|
|
309
|
-
const annotations =
|
|
303
|
+
const annotations = {
|
|
304
|
+
name: loadedSources.map((s) => s.annotation?.name).filter(Boolean).join(","),
|
|
305
|
+
resolvers: loadedSources.reduce((acc, s) => {
|
|
306
|
+
for (const [field, infos] of Object.entries(s.annotation?.resolvers ?? {})) acc[field] = acc[field] ? [
|
|
307
|
+
...acc[field],
|
|
308
|
+
...infos
|
|
309
|
+
] : infos;
|
|
310
|
+
return acc;
|
|
311
|
+
}, {})
|
|
312
|
+
};
|
|
310
313
|
const annotationResolvers = await this.discoverAnnotationResolvers();
|
|
311
314
|
return this.embedAnnotationResolversToSchema(schema, annotations, annotationResolvers);
|
|
312
315
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tinkerstack/graphql-annotation",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.9",
|
|
4
4
|
"description": "Better type-safe-able graphql directives",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
},
|
|
23
23
|
"repository": {
|
|
24
24
|
"type": "git",
|
|
25
|
-
"url": "git+https://github.com/
|
|
25
|
+
"url": "git+https://github.com/tinkerve/tinkerstack.git"
|
|
26
26
|
},
|
|
27
27
|
"peerDependencies": {
|
|
28
28
|
"@nestjs/common": "^10 || ^11",
|
|
@@ -20,6 +20,7 @@ import {
|
|
|
20
20
|
ANNOTATION_RESOLVER_METADATA,
|
|
21
21
|
AnnotationResolverMetadata,
|
|
22
22
|
AnnotationSchemaSources,
|
|
23
|
+
GraphQLResolversAnnotations,
|
|
23
24
|
ResolverName,
|
|
24
25
|
} from "./annotation.constants";
|
|
25
26
|
import {
|
|
@@ -27,12 +28,7 @@ import {
|
|
|
27
28
|
GraphQLAnnotationMeta,
|
|
28
29
|
GraphQLAnnotationResolver,
|
|
29
30
|
} from "./annotation.resolver";
|
|
30
|
-
import {
|
|
31
|
-
isPlainObject,
|
|
32
|
-
loadGraphQLSchema,
|
|
33
|
-
shallowMerge,
|
|
34
|
-
split,
|
|
35
|
-
} from "./annotation.utils";
|
|
31
|
+
import { isPlainObject, loadGraphQLSchema, split } from "./annotation.utils";
|
|
36
32
|
import { ResolverDiscoveryService } from "./resolver.explorer";
|
|
37
33
|
import { instanceToPlain } from "class-transformer";
|
|
38
34
|
|
|
@@ -57,9 +53,24 @@ export class GraphQLAnnotatedSchemaLoader {
|
|
|
57
53
|
const schema = stitchSchemas({
|
|
58
54
|
subschemas: loadedSources.map((s) => s.subschema),
|
|
59
55
|
});
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
56
|
+
// Deep-merge each source's `resolvers` map. A shallow merge of the whole
|
|
57
|
+
// annotation objects lets a later source's `resolvers` clobber earlier ones
|
|
58
|
+
// wholesale — silently dropping every annotation (e.g. session injection)
|
|
59
|
+
// from all but the last-loaded sub-gateway. Merge per field-name instead so
|
|
60
|
+
// every stitched sub-gateway keeps its annotations.
|
|
61
|
+
const annotations = {
|
|
62
|
+
name: loadedSources
|
|
63
|
+
.map((s) => s.annotation?.name)
|
|
64
|
+
.filter(Boolean)
|
|
65
|
+
.join(","),
|
|
66
|
+
resolvers: loadedSources.reduce((acc, s) => {
|
|
67
|
+
for (const [field, infos] of Object.entries(
|
|
68
|
+
s.annotation?.resolvers ?? {},
|
|
69
|
+
))
|
|
70
|
+
acc[field] = acc[field] ? [...acc[field], ...infos] : infos;
|
|
71
|
+
return acc;
|
|
72
|
+
}, {} as GraphQLResolversAnnotations),
|
|
73
|
+
} satisfies GraphQLAnnotationMeta;
|
|
63
74
|
const annotationResolvers = await this.discoverAnnotationResolvers();
|
|
64
75
|
|
|
65
76
|
return this.embedAnnotationResolversToSchema(
|