@galaxy-stack/orbit-graphql-federation 0.1.10 → 0.1.11

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.
Files changed (2) hide show
  1. package/dist/index.js +95 -14
  2. package/package.json +2 -2
package/dist/index.js CHANGED
@@ -192,6 +192,8 @@ class DataLoaderContext {
192
192
  }
193
193
 
194
194
  // ../graphql/src/schema/schema-builder.ts
195
+ var roots = new Set(["Query", "Mutation", "Subscription"]);
196
+
195
197
  class SchemaBuilder {
196
198
  objectTypes = new Map;
197
199
  inputTypes = new Map;
@@ -240,7 +242,8 @@ class SchemaBuilder {
240
242
  fields: subscriptionFields
241
243
  });
242
244
  }
243
- return new GraphQLSchema(schemaConfig);
245
+ this.builtSchema = new GraphQLSchema(schemaConfig);
246
+ return this.builtSchema;
244
247
  }
245
248
  buildFieldConfig(resolver, metadata) {
246
249
  const returnType = this.getReturnType(metadata);
@@ -442,6 +445,68 @@ class SchemaBuilder {
442
445
  this.inputTypes.set(type, inputType);
443
446
  return inputType;
444
447
  }
448
+ schemaGraph() {
449
+ if (!this.builtSchema) {
450
+ this.build();
451
+ }
452
+ const schema = this.builtSchema;
453
+ const typeMap = schema.getTypeMap();
454
+ const builtins = new Set([
455
+ "__Schema",
456
+ "__Type",
457
+ "__TypeKind",
458
+ "__Field",
459
+ "__InputValue",
460
+ "__EnumValue",
461
+ "__Directive",
462
+ "__DirectiveLocation",
463
+ "String",
464
+ "Boolean",
465
+ "Int",
466
+ "Float",
467
+ "ID"
468
+ ]);
469
+ const nodes = [];
470
+ const edges = [];
471
+ const roots = new Set(["Query", "Mutation", "Subscription"].filter((n) => typeMap[n]));
472
+ for (const [name, type] of Object.entries(typeMap)) {
473
+ if (name.startsWith("__") || builtins.has(name))
474
+ continue;
475
+ const kind = name === "Query" ? "query" : name === "Mutation" ? "mutation" : name === "Subscription" ? "subscription" : typeMap[name] instanceof GraphQLInputObjectType ? "input" : "type";
476
+ const fields = [];
477
+ if (type instanceof GraphQLObjectType || type instanceof GraphQLInputObjectType) {
478
+ for (const [fieldName, field] of Object.entries(type.getFields())) {
479
+ const fieldType = String(field.type).replace(/[[\]!]/g, "");
480
+ fields.push({ name: fieldName, type: fieldType });
481
+ }
482
+ }
483
+ nodes.push({ name, kind, fields });
484
+ }
485
+ for (const rootName of roots) {
486
+ const rootType = typeMap[rootName];
487
+ if (!(rootType instanceof GraphQLObjectType))
488
+ continue;
489
+ for (const [fieldName, field] of Object.entries(rootType.getFields())) {
490
+ const returnType = String(field.type).replace(/[[\]!]/g, "");
491
+ if (!builtins.has(returnType)) {
492
+ edges.push({ from: rootName, to: returnType, via: fieldName });
493
+ }
494
+ }
495
+ }
496
+ for (const node of nodes) {
497
+ const type = typeMap[node.name];
498
+ if (!(type instanceof GraphQLObjectType) || roots.has(node.name))
499
+ continue;
500
+ for (const [fieldName, field] of Object.entries(type.getFields())) {
501
+ const returnType = String(field.type).replace(/[[\]!]/g, "");
502
+ if (!builtins.has(returnType) && typeMap[returnType]) {
503
+ edges.push({ from: node.name, to: returnType, via: fieldName });
504
+ }
505
+ }
506
+ }
507
+ return { nodes, edges };
508
+ }
509
+ builtSchema;
445
510
  }
446
511
  // ../graphql/src/module/graphql.module.ts
447
512
  import"reflect-metadata";
@@ -543,21 +608,34 @@ function buildSecureHeaders(options = {}) {
543
608
  }
544
609
  return headers;
545
610
  }
546
- function withSecureHeaders(response, options = {}) {
547
- const secure = buildSecureHeaders(options);
548
- const headers = new Headers(response.headers);
549
- for (const [key, value] of Object.entries(secure)) {
550
- if (value === "") {
551
- headers.delete(key);
552
- } else {
553
- headers.set(key, value);
611
+ function applySecureHeaderRecord(response, secure) {
612
+ try {
613
+ for (const [key, value] of Object.entries(secure)) {
614
+ if (value === "") {
615
+ response.headers.delete(key);
616
+ } else {
617
+ response.headers.set(key, value);
618
+ }
619
+ }
620
+ return response;
621
+ } catch {
622
+ const headers = new Headers(response.headers);
623
+ for (const [key, value] of Object.entries(secure)) {
624
+ if (value === "") {
625
+ headers.delete(key);
626
+ } else {
627
+ headers.set(key, value);
628
+ }
554
629
  }
630
+ return new Response(response.body, {
631
+ status: response.status,
632
+ statusText: response.statusText,
633
+ headers
634
+ });
555
635
  }
556
- return new Response(response.body, {
557
- status: response.status,
558
- statusText: response.statusText,
559
- headers
560
- });
636
+ }
637
+ function withSecureHeaders(response, options = {}) {
638
+ return applySecureHeaderRecord(response, buildSecureHeaders(options));
561
639
  }
562
640
  // ../graphql/src/security/validation-rules.ts
563
641
  import {
@@ -793,6 +871,9 @@ class GraphQLHandler {
793
871
  this.schema = schema;
794
872
  this.options = options;
795
873
  }
874
+ getSchema() {
875
+ return this.schema;
876
+ }
796
877
  wrap(response) {
797
878
  if (this.options.secureHeaders === false)
798
879
  return response;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@galaxy-stack/orbit-graphql-federation",
3
- "version": "0.1.10",
3
+ "version": "0.1.11",
4
4
  "description": "GraphQL Federation support for Orbit framework",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -15,7 +15,7 @@
15
15
  },
16
16
  "dependencies": {
17
17
  "@galaxy-stack/orbit-core": "^0.2.0",
18
- "@galaxy-stack/orbit-graphql": "^0.1.11"
18
+ "@galaxy-stack/orbit-graphql": "^0.1.14"
19
19
  },
20
20
  "devDependencies": {
21
21
  "graphql": "^16.9.0",