@tinkerstack/graphql-annotation 0.0.2 → 0.0.4

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.
@@ -1,5 +1,5 @@
1
1
 
2
- > @tinkerstack/graphql-annotation@0.0.2 build C:\Users\mori\Documents\Work\tinkerstack\packages\graphql-annotation
2
+ > @tinkerstack/graphql-annotation@0.0.4 build C:\Users\mori\Documents\Work\tinkerstack\packages\graphql-annotation
3
3
  > tsup
4
4
 
5
5
  CLI Building entry: src/index.ts
@@ -10,11 +10,11 @@
10
10
  CLI Cleaning output folder
11
11
  ESM Build start
12
12
  CJS Build start
13
- CJS dist\index.js 21.17 KB
14
- CJS ⚡️ Build success in 645ms
15
- ESM dist\index.mjs 19.24 KB
16
- ESM ⚡️ Build success in 646ms
13
+ CJS dist\index.js 21.41 KB
14
+ CJS ⚡️ Build success in 137ms
15
+ ESM dist\index.mjs 19.48 KB
16
+ ESM ⚡️ Build success in 137ms
17
17
  DTS Build start
18
- DTS ⚡️ Build success in 2927ms
19
- DTS dist\index.d.mts 2.89 KB
20
- DTS dist\index.d.ts 2.89 KB
18
+ DTS ⚡️ Build success in 3496ms
19
+ DTS dist\index.d.mts 3.00 KB
20
+ DTS dist\index.d.ts 3.00 KB
package/dist/index.d.mts CHANGED
@@ -10,6 +10,8 @@ declare function Annotate(name: string, opts?: {
10
10
  declare function Annotate(name: string, opts: {
11
11
  data?: Record<string, any>;
12
12
  parameter: string;
13
+ description?: string;
14
+ type?: () => any;
13
15
  }): ParameterDecorator & MethodDecorator;
14
16
  declare function ResolveAnnotation(): MethodDecorator;
15
17
  declare function ResolveAnnotation(annotation: string): MethodDecorator;
@@ -56,7 +58,9 @@ declare class GraphQLAnnotatedSchemaLoader {
56
58
  private readonly externalContextCreator;
57
59
  private _logger;
58
60
  constructor(resolverDiscoveryService: ResolverDiscoveryService, metadataScanner: MetadataScanner, externalContextCreator: ExternalContextCreator);
59
- load(sources: AnnotationSchemaSources): Promise<GraphQLSchema>;
61
+ load(sources: AnnotationSchemaSources, opts?: {
62
+ ignoreMissingSources?: boolean;
63
+ }): Promise<GraphQLSchema>;
60
64
  private discoverAnnotationResolvers;
61
65
  private batchLoadSources;
62
66
  private loadAnnotations;
package/dist/index.d.ts CHANGED
@@ -10,6 +10,8 @@ declare function Annotate(name: string, opts?: {
10
10
  declare function Annotate(name: string, opts: {
11
11
  data?: Record<string, any>;
12
12
  parameter: string;
13
+ description?: string;
14
+ type?: () => any;
13
15
  }): ParameterDecorator & MethodDecorator;
14
16
  declare function ResolveAnnotation(): MethodDecorator;
15
17
  declare function ResolveAnnotation(annotation: string): MethodDecorator;
@@ -56,7 +58,9 @@ declare class GraphQLAnnotatedSchemaLoader {
56
58
  private readonly externalContextCreator;
57
59
  private _logger;
58
60
  constructor(resolverDiscoveryService: ResolverDiscoveryService, metadataScanner: MetadataScanner, externalContextCreator: ExternalContextCreator);
59
- load(sources: AnnotationSchemaSources): Promise<GraphQLSchema>;
61
+ load(sources: AnnotationSchemaSources, opts?: {
62
+ ignoreMissingSources?: boolean;
63
+ }): Promise<GraphQLSchema>;
60
64
  private discoverAnnotationResolvers;
61
65
  private batchLoadSources;
62
66
  private loadAnnotations;
package/dist/index.js CHANGED
@@ -328,8 +328,10 @@ var GraphQLAnnotatedSchemaLoader = class {
328
328
  this.metadataScanner = metadataScanner;
329
329
  this.externalContextCreator = externalContextCreator;
330
330
  }
331
- async load(sources) {
332
- const loadedSources = await this.batchLoadSources(sources);
331
+ async load(sources, opts) {
332
+ const loadedSources = await this.batchLoadSources(sources, {
333
+ ignoreMissingSources: opts?.ignoreMissingSources ?? false
334
+ });
333
335
  const schema = (0, import_stitch.stitchSchemas)({
334
336
  subschemas: loadedSources.map((s) => s.subschema)
335
337
  });
@@ -349,7 +351,7 @@ var GraphQLAnnotatedSchemaLoader = class {
349
351
  }
350
352
  return annotationResolvers;
351
353
  }
352
- async batchLoadSources(sources) {
354
+ async batchLoadSources(sources, opts) {
353
355
  const pending = Object.entries(sources).map(async ([name, url]) => {
354
356
  const loadId = `${name}@${url}`;
355
357
  try {
@@ -371,7 +373,11 @@ var GraphQLAnnotatedSchemaLoader = class {
371
373
  }
372
374
  });
373
375
  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.`);
376
+ const shouldThrow = opts?.ignoreMissingSources ?? true;
377
+ if (failed.length > 0) {
378
+ if (shouldThrow) throw new Error(`Failed to load ${failed.length} schema(s) from sources.`);
379
+ else this._logger.warn(`Failed to load ${failed.length}, ignoring.`);
380
+ }
375
381
  return loaded.map((l) => l.value);
376
382
  }
377
383
  async loadAnnotations(url) {
package/dist/index.mjs CHANGED
@@ -299,8 +299,10 @@ var GraphQLAnnotatedSchemaLoader = class {
299
299
  this.metadataScanner = metadataScanner;
300
300
  this.externalContextCreator = externalContextCreator;
301
301
  }
302
- async load(sources) {
303
- const loadedSources = await this.batchLoadSources(sources);
302
+ async load(sources, opts) {
303
+ const loadedSources = await this.batchLoadSources(sources, {
304
+ ignoreMissingSources: opts?.ignoreMissingSources ?? false
305
+ });
304
306
  const schema = stitchSchemas({
305
307
  subschemas: loadedSources.map((s) => s.subschema)
306
308
  });
@@ -320,7 +322,7 @@ var GraphQLAnnotatedSchemaLoader = class {
320
322
  }
321
323
  return annotationResolvers;
322
324
  }
323
- async batchLoadSources(sources) {
325
+ async batchLoadSources(sources, opts) {
324
326
  const pending = Object.entries(sources).map(async ([name, url]) => {
325
327
  const loadId = `${name}@${url}`;
326
328
  try {
@@ -342,7 +344,11 @@ var GraphQLAnnotatedSchemaLoader = class {
342
344
  }
343
345
  });
344
346
  const [loaded, failed] = split(await Promise.allSettled(pending), (q) => q.status === "fulfilled");
345
- if (failed.length > 0) throw new Error(`Failed to load ${failed.length} schema(s) from sources.`);
347
+ const shouldThrow = opts?.ignoreMissingSources ?? true;
348
+ if (failed.length > 0) {
349
+ if (shouldThrow) throw new Error(`Failed to load ${failed.length} schema(s) from sources.`);
350
+ else this._logger.warn(`Failed to load ${failed.length}, ignoring.`);
351
+ }
346
352
  return loaded.map((l) => l.value);
347
353
  }
348
354
  async loadAnnotations(url) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tinkerstack/graphql-annotation",
3
- "version": "0.0.2",
3
+ "version": "0.0.4",
4
4
  "description": "Better type-safe-able graphql directives",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
@@ -14,7 +14,6 @@
14
14
  "@graphql-tools/stitch": "^10.1.8",
15
15
  "@graphql-tools/utils": "^11.0.0",
16
16
  "@graphql-tools/wrap": "^11.1.4",
17
- "class-transformer": "^0.5.1",
18
17
  "graphql-request": "^7.2.0"
19
18
  },
20
19
  "publishConfig": {
@@ -40,6 +39,7 @@
40
39
  "@nestjs/mapped-types": "^2.1.0",
41
40
  "@nestjs/platform-fastify": "^11.1.11",
42
41
  "@swc/core": "^1.15.11",
42
+ "class-transformer": "^0.5.1",
43
43
  "class-validator": "^0.14.2",
44
44
  "concurrently": "^9.2.1",
45
45
  "eslint": "^9.37.0",
@@ -30,7 +30,12 @@ export function Annotate(
30
30
  */
31
31
  export function Annotate(
32
32
  name: string,
33
- opts: { data?: Record<string, any>; parameter: string },
33
+ opts: {
34
+ data?: Record<string, any>;
35
+ parameter: string;
36
+ description?: string;
37
+ type?: () => any;
38
+ },
34
39
  ): ParameterDecorator & MethodDecorator;
35
40
  /**
36
41
  * Applies an annotation to a Query or Mutation handler or parameter for
@@ -46,8 +46,13 @@ export class GraphQLAnnotatedSchemaLoader {
46
46
  private readonly externalContextCreator: ExternalContextCreator,
47
47
  ) {}
48
48
 
49
- public async load(sources: AnnotationSchemaSources) {
50
- const loadedSources = await this.batchLoadSources(sources);
49
+ public async load(
50
+ sources: AnnotationSchemaSources,
51
+ opts?: { ignoreMissingSources?: boolean },
52
+ ) {
53
+ const loadedSources = await this.batchLoadSources(sources, {
54
+ ignoreMissingSources: opts?.ignoreMissingSources ?? false,
55
+ });
51
56
 
52
57
  const schema = stitchSchemas({
53
58
  subschemas: loadedSources.map((s) => s.subschema),
@@ -108,7 +113,10 @@ export class GraphQLAnnotatedSchemaLoader {
108
113
  return annotationResolvers;
109
114
  }
110
115
 
111
- private async batchLoadSources(sources: AnnotationSchemaSources) {
116
+ private async batchLoadSources(
117
+ sources: AnnotationSchemaSources,
118
+ opts?: { ignoreMissingSources?: boolean },
119
+ ) {
112
120
  const pending = Object.entries(sources).map(async ([name, url]) => {
113
121
  const loadId = `${name}@${url}`;
114
122
  try {
@@ -140,10 +148,15 @@ export class GraphQLAnnotatedSchemaLoader {
140
148
  await Promise.allSettled(pending),
141
149
  (q) => q.status === "fulfilled",
142
150
  );
143
- if (failed.length > 0)
144
- throw new Error(
145
- `Failed to load ${failed.length} schema(s) from sources.`,
146
- );
151
+
152
+ const shouldThrow = opts?.ignoreMissingSources ?? true;
153
+ if (failed.length > 0) {
154
+ if (shouldThrow)
155
+ throw new Error(
156
+ `Failed to load ${failed.length} schema(s) from sources.`,
157
+ );
158
+ else this._logger.warn(`Failed to load ${failed.length}, ignoring.`);
159
+ }
147
160
 
148
161
  return loaded.map((l) => l.value);
149
162
  }