@tinkerstack/graphql-annotation 0.0.7 → 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 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 = shallowMerge(loadedSources.map((s) => s.annotation));
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
  }
@@ -369,6 +372,7 @@ var GraphQLAnnotatedSchemaLoader = class {
369
372
  return loaded2;
370
373
  } catch (err) {
371
374
  this._logger.error(`Unable to load schema for ${loadId}`);
375
+ this._logger.error(err);
372
376
  throw err;
373
377
  }
374
378
  });
@@ -395,6 +399,7 @@ var GraphQLAnnotatedSchemaLoader = class {
395
399
  return res.data[ANNOTATION_QUERY_NAME];
396
400
  } catch (err) {
397
401
  this._logger.warn(`Failed to load annotations at ${url}, assuming empty`);
402
+ this._logger.warn(err);
398
403
  return {};
399
404
  }
400
405
  }
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 = shallowMerge(loadedSources.map((s) => s.annotation));
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
  }
@@ -340,6 +343,7 @@ var GraphQLAnnotatedSchemaLoader = class {
340
343
  return loaded2;
341
344
  } catch (err) {
342
345
  this._logger.error(`Unable to load schema for ${loadId}`);
346
+ this._logger.error(err);
343
347
  throw err;
344
348
  }
345
349
  });
@@ -366,6 +370,7 @@ var GraphQLAnnotatedSchemaLoader = class {
366
370
  return res.data[ANNOTATION_QUERY_NAME];
367
371
  } catch (err) {
368
372
  this._logger.warn(`Failed to load annotations at ${url}, assuming empty`);
373
+ this._logger.warn(err);
369
374
  return {};
370
375
  }
371
376
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tinkerstack/graphql-annotation",
3
- "version": "0.0.7",
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/plasteek/tinkerstack.git"
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
- const annotations = shallowMerge(
61
- loadedSources.map((s) => s.annotation),
62
- ) as GraphQLAnnotationMeta;
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(
@@ -140,6 +151,7 @@ export class GraphQLAnnotatedSchemaLoader {
140
151
  return loaded;
141
152
  } catch (err) {
142
153
  this._logger.error(`Unable to load schema for ${loadId}`);
154
+ this._logger.error(err);
143
155
  throw err;
144
156
  }
145
157
  });
@@ -184,6 +196,7 @@ export class GraphQLAnnotatedSchemaLoader {
184
196
  return res.data[ANNOTATION_QUERY_NAME];
185
197
  } catch (err) {
186
198
  this._logger.warn(`Failed to load annotations at ${url}, assuming empty`);
199
+ this._logger.warn(err);
187
200
  return {} as GraphQLAnnotationMeta;
188
201
  }
189
202
  }