@apollo/federation-internals 2.8.0-connectors.4 → 2.8.0

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 (88) hide show
  1. package/dist/directiveAndTypeSpecification.d.ts +13 -1
  2. package/dist/directiveAndTypeSpecification.d.ts.map +1 -1
  3. package/dist/directiveAndTypeSpecification.js +2 -2
  4. package/dist/directiveAndTypeSpecification.js.map +1 -1
  5. package/dist/error.d.ts +25 -0
  6. package/dist/error.d.ts.map +1 -1
  7. package/dist/error.js +50 -0
  8. package/dist/error.js.map +1 -1
  9. package/dist/extractSubgraphsFromSupergraph.d.ts +1 -1
  10. package/dist/extractSubgraphsFromSupergraph.d.ts.map +1 -1
  11. package/dist/extractSubgraphsFromSupergraph.js +62 -7
  12. package/dist/extractSubgraphsFromSupergraph.js.map +1 -1
  13. package/dist/federation.d.ts +19 -2
  14. package/dist/federation.d.ts.map +1 -1
  15. package/dist/federation.js +420 -9
  16. package/dist/federation.js.map +1 -1
  17. package/dist/index.d.ts +2 -1
  18. package/dist/index.d.ts.map +1 -1
  19. package/dist/index.js +2 -1
  20. package/dist/index.js.map +1 -1
  21. package/dist/knownCoreFeatures.d.ts +3 -0
  22. package/dist/knownCoreFeatures.d.ts.map +1 -1
  23. package/dist/knownCoreFeatures.js +12 -1
  24. package/dist/knownCoreFeatures.js.map +1 -1
  25. package/dist/operations.d.ts +10 -8
  26. package/dist/operations.d.ts.map +1 -1
  27. package/dist/operations.js +48 -16
  28. package/dist/operations.js.map +1 -1
  29. package/dist/specs/contextSpec.d.ts +20 -0
  30. package/dist/specs/contextSpec.d.ts.map +1 -0
  31. package/dist/specs/contextSpec.js +62 -0
  32. package/dist/specs/contextSpec.js.map +1 -0
  33. package/dist/specs/coreSpec.d.ts +1 -0
  34. package/dist/specs/coreSpec.d.ts.map +1 -1
  35. package/dist/specs/coreSpec.js +3 -0
  36. package/dist/specs/coreSpec.js.map +1 -1
  37. package/dist/specs/federationSpec.d.ts +8 -2
  38. package/dist/specs/federationSpec.d.ts.map +1 -1
  39. package/dist/specs/federationSpec.js +16 -1
  40. package/dist/specs/federationSpec.js.map +1 -1
  41. package/dist/specs/joinSpec.d.ts +6 -0
  42. package/dist/specs/joinSpec.d.ts.map +1 -1
  43. package/dist/specs/joinSpec.js +11 -1
  44. package/dist/specs/joinSpec.js.map +1 -1
  45. package/dist/specs/sourceSpec.d.ts +69 -0
  46. package/dist/specs/sourceSpec.d.ts.map +1 -0
  47. package/dist/specs/sourceSpec.js +345 -0
  48. package/dist/specs/sourceSpec.js.map +1 -0
  49. package/dist/supergraphs.d.ts +4 -0
  50. package/dist/supergraphs.d.ts.map +1 -1
  51. package/dist/supergraphs.js +35 -2
  52. package/dist/supergraphs.js.map +1 -1
  53. package/dist/utils.d.ts +3 -0
  54. package/dist/utils.d.ts.map +1 -1
  55. package/dist/utils.js +39 -1
  56. package/dist/utils.js.map +1 -1
  57. package/package.json +1 -1
  58. package/src/directiveAndTypeSpecification.ts +8 -1
  59. package/src/error.ts +175 -0
  60. package/src/extractSubgraphsFromSupergraph.ts +76 -14
  61. package/src/federation.ts +636 -17
  62. package/src/index.ts +2 -1
  63. package/src/knownCoreFeatures.ts +15 -0
  64. package/src/operations.ts +63 -23
  65. package/src/specs/contextSpec.ts +87 -0
  66. package/src/specs/coreSpec.ts +5 -0
  67. package/src/specs/federationSpec.ts +18 -1
  68. package/src/specs/joinSpec.ts +27 -3
  69. package/src/specs/sourceSpec.ts +607 -0
  70. package/src/supergraphs.ts +37 -1
  71. package/src/utils.ts +38 -0
  72. package/dist/specs/connectSpec.d.ts +0 -42
  73. package/dist/specs/connectSpec.d.ts.map +0 -1
  74. package/dist/specs/connectSpec.js +0 -82
  75. package/dist/specs/connectSpec.js.map +0 -1
  76. package/dist/wasm.d.ts +0 -4
  77. package/dist/wasm.d.ts.map +0 -1
  78. package/dist/wasm.js +0 -83
  79. package/dist/wasm.js.map +0 -1
  80. package/src/specs/connectSpec.ts +0 -181
  81. package/src/wasm.ts +0 -111
  82. package/wasm/node/.gitignore +0 -1
  83. package/wasm/node/.npmignore +0 -2
  84. package/wasm/node/federation_internals_wasm.d.ts +0 -49
  85. package/wasm/node/federation_internals_wasm.js +0 -367
  86. package/wasm/node/federation_internals_wasm_bg.wasm +0 -0
  87. package/wasm/node/federation_internals_wasm_bg.wasm.d.ts +0 -19
  88. package/wasm/node/package.json +0 -15
package/src/utils.ts CHANGED
@@ -441,3 +441,41 @@ export function findLast<T>(array: T[], predicate: (t: T) => boolean): T | undef
441
441
  }
442
442
  return undefined;
443
443
  }
444
+
445
+ export function mergeMapOrNull<K,V>(m1: Map<K, V> | null, m2: Map<K, V> | null): Map<K, V> | null {
446
+ if (!m1) {
447
+ return m2;
448
+ }
449
+ if (!m2) {
450
+ return m1;
451
+ }
452
+ return new Map<K, V>([...m1, ...m2]);
453
+ }
454
+
455
+ export function composeSets<T>(s1: Set<T> | null, s2: Set<T> | null): Set<T> | null {
456
+ if (!s1 && !s2) {
457
+ return null;
458
+ }
459
+ const result = new Set<T>();
460
+ s1?.forEach(v => result.add(v));
461
+ s2?.forEach(v => result.add(v));
462
+ return result;
463
+ }
464
+
465
+ export function setsEqual<T>(s1: Set<T> | null, s2: Set<T> | null): boolean {
466
+ if (s1 === s2) {
467
+ return true;
468
+ }
469
+ if (!s1 && !s2) {
470
+ return true;
471
+ }
472
+ if (!s1 || !s2 || s1.size !== s2.size) {
473
+ return false;
474
+ }
475
+ for (const key of s1) {
476
+ if (!s2.has(key)) {
477
+ return false;
478
+ }
479
+ }
480
+ return true;
481
+ }
@@ -1,42 +0,0 @@
1
- import { GraphQLError } from 'graphql';
2
- import { CorePurpose, FeatureDefinition, FeatureDefinitions, FeatureVersion } from "./coreSpec";
3
- import { Schema } from '../definitions';
4
- export declare const connectIdentity = "https://specs.apollo.dev/connect";
5
- export declare class ConnectSpecDefinition extends FeatureDefinition {
6
- readonly minimumFederationVersion: FeatureVersion;
7
- constructor(version: FeatureVersion, minimumFederationVersion: FeatureVersion);
8
- addElementsToSchema(schema: Schema): GraphQLError[];
9
- get defaultCorePurpose(): CorePurpose;
10
- }
11
- export type SourceDirectiveArgs = {
12
- name: string;
13
- http: SourceDirectiveHTTP;
14
- };
15
- export type SourceDirectiveHTTP = {
16
- baseURL: string;
17
- headers?: HTTPHeaderMapping[];
18
- };
19
- type HTTPHeaderMapping = {
20
- name: string;
21
- as?: string;
22
- value?: string;
23
- };
24
- type URLPathTemplate = string;
25
- type JSONSelection = string;
26
- export type ConnectDirectiveArgs = {
27
- source: string;
28
- http: ConnectDirectiveHTTP;
29
- selection?: JSONSelection;
30
- };
31
- export type ConnectDirectiveHTTP = {
32
- GET?: URLPathTemplate;
33
- POST?: URLPathTemplate;
34
- PUT?: URLPathTemplate;
35
- PATCH?: URLPathTemplate;
36
- DELETE?: URLPathTemplate;
37
- body?: JSONSelection;
38
- headers?: HTTPHeaderMapping[];
39
- };
40
- export declare const CONNECT_VERSIONS: FeatureDefinitions<ConnectSpecDefinition>;
41
- export {};
42
- //# sourceMappingURL=connectSpec.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"connectSpec.d.ts","sourceRoot":"","sources":["../../src/specs/connectSpec.ts"],"names":[],"mappings":"AAAA,OAAO,EAAoB,YAAY,EAAC,MAAM,SAAS,CAAC;AACxD,OAAO,EAAE,WAAW,EAAE,iBAAiB,EAAE,kBAAkB,EAAc,cAAc,EAAE,MAAM,YAAY,CAAC;AAC5G,OAAO,EACL,MAAM,EAKP,MAAM,gBAAgB,CAAC;AAIxB,eAAO,MAAM,eAAe,qCAAqC,CAAC;AAUlE,qBAAa,qBAAsB,SAAQ,iBAAiB;IACrB,QAAQ,CAAC,wBAAwB,EAAE,cAAc;gBAA1E,OAAO,EAAE,cAAc,EAAW,wBAAwB,EAAE,cAAc;IA2BtF,mBAAmB,CAAC,MAAM,EAAE,MAAM,GAAG,YAAY,EAAE;IAuFnD,IAAI,kBAAkB,IAAI,WAAW,CAEpC;CACF;AAED,MAAM,MAAM,mBAAmB,GAAG;IAChC,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,mBAAmB,CAAC;CAC3B,CAAC;AAEF,MAAM,MAAM,mBAAmB,GAAG;IAChC,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,iBAAiB,EAAE,CAAC;CAC/B,CAAC;AAEF,KAAK,iBAAiB,GAAG;IACvB,IAAI,EAAE,MAAM,CAAC;IACb,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF,KAAK,eAAe,GAAG,MAAM,CAAC;AAC9B,KAAK,aAAa,GAAG,MAAM,CAAC;AAE5B,MAAM,MAAM,oBAAoB,GAAG;IACjC,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,oBAAoB,CAAC;IAC3B,SAAS,CAAC,EAAE,aAAa,CAAC;CAC3B,CAAC;AAEF,MAAM,MAAM,oBAAoB,GAAG;IACjC,GAAG,CAAC,EAAE,eAAe,CAAC;IACtB,IAAI,CAAC,EAAE,eAAe,CAAC;IACvB,GAAG,CAAC,EAAE,eAAe,CAAC;IACtB,KAAK,CAAC,EAAE,eAAe,CAAC;IACxB,MAAM,CAAC,EAAE,eAAe,CAAC;IACzB,IAAI,CAAC,EAAE,aAAa,CAAC;IACrB,OAAO,CAAC,EAAE,iBAAiB,EAAE,CAAC;CAC/B,CAAC;AAEF,eAAO,MAAM,gBAAgB,2CACwD,CAAC"}
@@ -1,82 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.CONNECT_VERSIONS = exports.ConnectSpecDefinition = exports.connectIdentity = void 0;
4
- const graphql_1 = require("graphql");
5
- const coreSpec_1 = require("./coreSpec");
6
- const definitions_1 = require("../definitions");
7
- const knownCoreFeatures_1 = require("../knownCoreFeatures");
8
- const directiveAndTypeSpecification_1 = require("../directiveAndTypeSpecification");
9
- exports.connectIdentity = 'https://specs.apollo.dev/connect';
10
- const CONNECT = "connect";
11
- const SOURCE = "source";
12
- const URL_PATH_TEMPLATE = "URLPathTemplate";
13
- const JSON_SELECTION = "JSONSelection";
14
- const CONNECT_HTTP = "ConnectHTTP";
15
- const SOURCE_HTTP = "SourceHTTP";
16
- const HTTP_HEADER_MAPPING = "HTTPHeaderMapping";
17
- class ConnectSpecDefinition extends coreSpec_1.FeatureDefinition {
18
- constructor(version, minimumFederationVersion) {
19
- super(new coreSpec_1.FeatureUrl(exports.connectIdentity, CONNECT, version), minimumFederationVersion);
20
- this.minimumFederationVersion = minimumFederationVersion;
21
- this.registerDirective((0, directiveAndTypeSpecification_1.createDirectiveSpecification)({
22
- name: CONNECT,
23
- locations: [graphql_1.DirectiveLocation.FIELD_DEFINITION],
24
- repeatable: true,
25
- composes: false,
26
- }));
27
- this.registerDirective((0, directiveAndTypeSpecification_1.createDirectiveSpecification)({
28
- name: SOURCE,
29
- locations: [graphql_1.DirectiveLocation.SCHEMA],
30
- repeatable: true,
31
- composes: false,
32
- }));
33
- this.registerType({ name: URL_PATH_TEMPLATE, checkOrAdd: () => [] });
34
- this.registerType({ name: JSON_SELECTION, checkOrAdd: () => [] });
35
- this.registerType({ name: CONNECT_HTTP, checkOrAdd: () => [] });
36
- this.registerType({ name: SOURCE_HTTP, checkOrAdd: () => [] });
37
- this.registerType({ name: HTTP_HEADER_MAPPING, checkOrAdd: () => [] });
38
- }
39
- addElementsToSchema(schema) {
40
- const URLPathTemplate = this.addScalarType(schema, URL_PATH_TEMPLATE);
41
- const JSONSelection = this.addScalarType(schema, JSON_SELECTION);
42
- const connect = this.addDirective(schema, CONNECT).addLocations(graphql_1.DirectiveLocation.FIELD_DEFINITION);
43
- connect.repeatable = true;
44
- connect.addArgument(SOURCE, schema.stringType());
45
- const HTTPHeaderMapping = schema.addType(new definitions_1.InputObjectType(this.typeNameInSchema(schema, HTTP_HEADER_MAPPING)));
46
- HTTPHeaderMapping.addField(new definitions_1.InputFieldDefinition('name')).type =
47
- new definitions_1.NonNullType(schema.stringType());
48
- HTTPHeaderMapping.addField(new definitions_1.InputFieldDefinition('as')).type =
49
- schema.stringType();
50
- HTTPHeaderMapping.addField(new definitions_1.InputFieldDefinition('value')).type =
51
- schema.stringType();
52
- const ConnectHTTP = schema.addType(new definitions_1.InputObjectType(this.typeNameInSchema(schema, CONNECT_HTTP)));
53
- ConnectHTTP.addField(new definitions_1.InputFieldDefinition('GET')).type = URLPathTemplate;
54
- ConnectHTTP.addField(new definitions_1.InputFieldDefinition('POST')).type = URLPathTemplate;
55
- ConnectHTTP.addField(new definitions_1.InputFieldDefinition('PUT')).type = URLPathTemplate;
56
- ConnectHTTP.addField(new definitions_1.InputFieldDefinition('PATCH')).type = URLPathTemplate;
57
- ConnectHTTP.addField(new definitions_1.InputFieldDefinition('DELETE')).type = URLPathTemplate;
58
- ConnectHTTP.addField(new definitions_1.InputFieldDefinition('body')).type = JSONSelection;
59
- ConnectHTTP.addField(new definitions_1.InputFieldDefinition('headers')).type =
60
- new definitions_1.ListType(new definitions_1.NonNullType(HTTPHeaderMapping));
61
- connect.addArgument('http', new definitions_1.NonNullType(ConnectHTTP));
62
- connect.addArgument('selection', JSONSelection);
63
- const source = this.addDirective(schema, SOURCE).addLocations(graphql_1.DirectiveLocation.SCHEMA);
64
- source.repeatable = true;
65
- source.addArgument('name', new definitions_1.NonNullType(schema.stringType()));
66
- const SourceHTTP = schema.addType(new definitions_1.InputObjectType(this.typeNameInSchema(schema, SOURCE_HTTP)));
67
- SourceHTTP.addField(new definitions_1.InputFieldDefinition('baseURL')).type =
68
- new definitions_1.NonNullType(schema.stringType());
69
- SourceHTTP.addField(new definitions_1.InputFieldDefinition('headers')).type =
70
- new definitions_1.ListType(new definitions_1.NonNullType(HTTPHeaderMapping));
71
- source.addArgument('http', new definitions_1.NonNullType(SourceHTTP));
72
- return [];
73
- }
74
- get defaultCorePurpose() {
75
- return 'EXECUTION';
76
- }
77
- }
78
- exports.ConnectSpecDefinition = ConnectSpecDefinition;
79
- exports.CONNECT_VERSIONS = new coreSpec_1.FeatureDefinitions(exports.connectIdentity)
80
- .add(new ConnectSpecDefinition(new coreSpec_1.FeatureVersion(0, 1), new coreSpec_1.FeatureVersion(2, 7)));
81
- (0, knownCoreFeatures_1.registerKnownFeature)(exports.CONNECT_VERSIONS);
82
- //# sourceMappingURL=connectSpec.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"connectSpec.js","sourceRoot":"","sources":["../../src/specs/connectSpec.ts"],"names":[],"mappings":";;;AAAA,qCAAwD;AACxD,yCAA4G;AAC5G,gDAMwB;AACxB,4DAA4D;AAC5D,oFAAgF;AAEnE,QAAA,eAAe,GAAG,kCAAkC,CAAC;AAElE,MAAM,OAAO,GAAG,SAAS,CAAC;AAC1B,MAAM,MAAM,GAAG,QAAQ,CAAC;AACxB,MAAM,iBAAiB,GAAG,iBAAiB,CAAC;AAC5C,MAAM,cAAc,GAAG,eAAe,CAAC;AACvC,MAAM,YAAY,GAAG,aAAa,CAAC;AACnC,MAAM,WAAW,GAAG,YAAY,CAAC;AACjC,MAAM,mBAAmB,GAAG,mBAAmB,CAAC;AAEhD,MAAa,qBAAsB,SAAQ,4BAAiB;IAC1D,YAAY,OAAuB,EAAW,wBAAwC;QACpF,KAAK,CAAC,IAAI,qBAAU,CAAC,uBAAe,EAAE,OAAO,EAAE,OAAO,CAAC,EAAE,wBAAwB,CAAC,CAAC;QADvC,6BAAwB,GAAxB,wBAAwB,CAAgB;QAGpF,IAAI,CAAC,iBAAiB,CAAC,IAAA,4DAA4B,EAAC;YAClD,IAAI,EAAE,OAAO;YACb,SAAS,EAAE,CAAC,2BAAiB,CAAC,gBAAgB,CAAC;YAC/C,UAAU,EAAE,IAAI;YAIhB,QAAQ,EAAE,KAAK;SAChB,CAAC,CAAC,CAAC;QAEJ,IAAI,CAAC,iBAAiB,CAAC,IAAA,4DAA4B,EAAC;YAClD,IAAI,EAAE,MAAM;YACZ,SAAS,EAAE,CAAC,2BAAiB,C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AAI,yBAAc,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,IAAI,yBAAc,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC;AAEtF,IAAA,wCAAoB,EAAC,wBAAgB,CAAC,CAAC"}
package/dist/wasm.d.ts DELETED
@@ -1,4 +0,0 @@
1
- import { Schema } from "./definitions";
2
- import { DocumentNode } from "graphql/index";
3
- export declare function validateSubgraphSchema(schema: Schema, ast: DocumentNode): void;
4
- //# sourceMappingURL=wasm.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"wasm.d.ts","sourceRoot":"","sources":["../src/wasm.ts"],"names":[],"mappings":"AAMA,OAAO,EAAC,MAAM,EAAC,MAAM,eAAe,CAAC;AACrC,OAAO,EAGH,YAAY,EAGf,MAAM,eAAe,CAAC;AAUvB,wBAAgB,sBAAsB,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,EAAE,YAAY,QASvE"}
package/dist/wasm.js DELETED
@@ -1,83 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.validateSubgraphSchema = void 0;
4
- const index_1 = require("graphql/index");
5
- const coreSpec_1 = require("./specs/coreSpec");
6
- const connectSpec_1 = require("./specs/connectSpec");
7
- const error_1 = require("./error");
8
- function validateSubgraphSchema(schema, ast) {
9
- const errors = [];
10
- if (hasConnectDirectives(schema)) {
11
- errors.push(...validateConnectDirectives(ast));
12
- }
13
- if (errors.length > 0) {
14
- throw (0, error_1.aggregateError)("FROM_WASM", "WASM validation detected errors", errors);
15
- }
16
- }
17
- exports.validateSubgraphSchema = validateSubgraphSchema;
18
- function hasConnectDirectives(schema) {
19
- return schema.schemaDefinition.appliedDirectivesOf('link')
20
- .some(linkDirective => {
21
- const { url, import: imports } = linkDirective.arguments();
22
- const featureUrl = coreSpec_1.FeatureUrl.maybeParse(url);
23
- return imports && featureUrl && featureUrl.identity === connectSpec_1.connectIdentity && imports.some(nameOrRename => {
24
- const originalName = typeof nameOrRename === 'string' ? nameOrRename : nameOrRename.name;
25
- return originalName === '@source' || originalName === '@connect';
26
- });
27
- });
28
- }
29
- function validateConnectDirectives(ast) {
30
- const { validate_connect_directives } = require('../wasm/node');
31
- const source = (0, index_1.print)(ast);
32
- return validate_connect_directives(source).map(raw => new index_1.GraphQLError(raw.message, {
33
- nodes: raw.location && findNode(ast, raw.location),
34
- extensions: { code: raw.code },
35
- }));
36
- }
37
- function findNode(ast, location) {
38
- if (location.source) {
39
- const sourceDirective = findSourceDirective(ast, location.source);
40
- if (sourceDirective) {
41
- return sourceDirective;
42
- }
43
- }
44
- return undefined;
45
- }
46
- function findSourceDirective(ast, sourceDirective) {
47
- var _a, _b, _c;
48
- const { SourceArgument } = require('../wasm/node');
49
- const schema = ast.definitions.find(isSchemaExtension);
50
- const sourceDirectives = (_a = schema === null || schema === void 0 ? void 0 : schema.directives) === null || _a === void 0 ? void 0 : _a.filter(directive => directive.name.value === "source");
51
- const matchingSource = sourceDirectives === null || sourceDirectives === void 0 ? void 0 : sourceDirectives.find(directive => {
52
- var _a;
53
- const nameArg = (_a = directive.arguments) === null || _a === void 0 ? void 0 : _a.find(arg => arg.name.value === "name");
54
- return nameArg && isStringValue(nameArg.value) && nameArg.value.value === sourceDirective.name;
55
- });
56
- if (sourceDirective.arg === SourceArgument.Url) {
57
- const arg = (_b = matchingSource === null || matchingSource === void 0 ? void 0 : matchingSource.arguments) === null || _b === void 0 ? void 0 : _b.find(arg => arg.name.value === "http");
58
- const value = arg === null || arg === void 0 ? void 0 : arg.value;
59
- if (value && isObjectValue(value)) {
60
- const field = value.fields.find(field => field.name.value === "baseURL");
61
- if (field) {
62
- return field;
63
- }
64
- }
65
- }
66
- else if (sourceDirective.arg === SourceArgument.Name) {
67
- const arg = (_c = matchingSource === null || matchingSource === void 0 ? void 0 : matchingSource.arguments) === null || _c === void 0 ? void 0 : _c.find(arg => arg.name.value === "name");
68
- if (arg) {
69
- return arg;
70
- }
71
- }
72
- return matchingSource;
73
- }
74
- function isSchemaExtension(node) {
75
- return node.kind === "SchemaExtension";
76
- }
77
- function isStringValue(node) {
78
- return node.kind === "StringValue";
79
- }
80
- function isObjectValue(node) {
81
- return node.kind === "ObjectValue";
82
- }
83
- //# sourceMappingURL=wasm.js.map
package/dist/wasm.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"wasm.js","sourceRoot":"","sources":["../src/wasm.ts"],"names":[],"mappings":";;;AAOA,yCAMuB;AACvB,+CAA+D;AAC/D,qDAAoD;AACpD,mCAAuC;AAOvC,SAAgB,sBAAsB,CAAC,MAAc,EAAE,GAAiB;IACpE,MAAM,MAAM,GAAG,EAAE,CAAC;IAClB,IAAI,oBAAoB,CAAC,MAAM,CAAC,EAAE,CAAC;QAC/B,MAAM,CAAC,IAAI,CAAC,GAAG,yBAAyB,CAAC,GAAG,CAAC,CAAC,CAAC;IACnD,CAAC;IAED,IAAI,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACpB,MAAM,IAAA,sBAAc,EAAC,WAAW,EAAE,iCAAiC,EAAE,MAAM,CAAC,CAAA;IAChF,CAAC;AACL,CAAC;AATD,wDASC;AAED,SAAS,oBAAoB,CAAC,MAAc;IACxC,OAAO,MAAM,CAAC,gBAAgB,CAAC,mBAAmB,CAAoB,MAAM,CAAC;SACxE,IAAI,CAAC,aAAa,CAAC,EAAE;QAClB,MAAM,EAAC,GAAG,EAAE,MAAM,EAAE,OAAO,EAAC,GAAG,aAAa,CAAC,SAAS,EAAE,CAAC;QACzD,MAAM,UAAU,GAAG,qBAAU,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC;QAC9C,OAAO,OAAO,IAAI,UAAU,IAAI,UAAU,CAAC,QAAQ,KAAK,6BAAe,IAAI,OAAO,CAAC,IAAI,CAAC,YAAY,CAAC,EAAE;YACnG,MAAM,YAAY,GAAG,OAAO,YAAY,KAAK,QAAQ,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,YAAY,CAAC,IAAI,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C,KAAK,KAAK,MAAM,CAAC,CAAC;QAC9E,IAAI,GAAG,EAAE,CAAC;YACN,OAAO,GAAG,CAAC;QACf,CAAC;IACL,CAAC;IACD,OAAO,cAAc,CAAC;AAC1B,CAAC;AAED,SAAS,iBAAiB,CAAC,IAAoB;IAC3C,OAAO,IAAI,CAAC,IAAI,KAAK,iBAAiB,CAAC;AAC3C,CAAC;AAED,SAAS,aAAa,CAAC,IAAoB;IACvC,OAAO,IAAI,CAAC,IAAI,KAAK,aAAa,CAAC;AACvC,CAAC;AAED,SAAS,aAAa,CAAC,IAAoB;IACvC,OAAO,IAAI,CAAC,IAAI,KAAK,aAAa,CAAC;AACvC,CAAC"}
@@ -1,181 +0,0 @@
1
- import {DirectiveLocation, GraphQLError} from 'graphql';
2
- import { CorePurpose, FeatureDefinition, FeatureDefinitions, FeatureUrl, FeatureVersion } from "./coreSpec";
3
- import {
4
- Schema,
5
- NonNullType,
6
- InputObjectType,
7
- InputFieldDefinition,
8
- ListType,
9
- } from '../definitions';
10
- import { registerKnownFeature } from '../knownCoreFeatures';
11
- import { createDirectiveSpecification } from '../directiveAndTypeSpecification';
12
-
13
- export const connectIdentity = 'https://specs.apollo.dev/connect';
14
-
15
- const CONNECT = "connect";
16
- const SOURCE = "source";
17
- const URL_PATH_TEMPLATE = "URLPathTemplate";
18
- const JSON_SELECTION = "JSONSelection";
19
- const CONNECT_HTTP = "ConnectHTTP";
20
- const SOURCE_HTTP = "SourceHTTP";
21
- const HTTP_HEADER_MAPPING = "HTTPHeaderMapping";
22
-
23
- export class ConnectSpecDefinition extends FeatureDefinition {
24
- constructor(version: FeatureVersion, readonly minimumFederationVersion: FeatureVersion) {
25
- super(new FeatureUrl(connectIdentity, CONNECT, version), minimumFederationVersion);
26
-
27
- this.registerDirective(createDirectiveSpecification({
28
- name: CONNECT,
29
- locations: [DirectiveLocation.FIELD_DEFINITION],
30
- repeatable: true,
31
- // We "compose" these directives using the `@join__directive` mechanism,
32
- // so they do not need to be composed in the way passing `composes: true`
33
- // here implies.
34
- composes: false,
35
- }));
36
-
37
- this.registerDirective(createDirectiveSpecification({
38
- name: SOURCE,
39
- locations: [DirectiveLocation.SCHEMA],
40
- repeatable: true,
41
- composes: false,
42
- }));
43
-
44
- this.registerType({ name: URL_PATH_TEMPLATE, checkOrAdd: () => [] });
45
- this.registerType({ name: JSON_SELECTION, checkOrAdd: () => [] });
46
- this.registerType({ name: CONNECT_HTTP, checkOrAdd: () => [] });
47
- this.registerType({ name: SOURCE_HTTP, checkOrAdd: () => [] });
48
- this.registerType({ name: HTTP_HEADER_MAPPING, checkOrAdd: () => [] });
49
- }
50
-
51
- addElementsToSchema(schema: Schema): GraphQLError[] {
52
- /* scalar URLPathTemplate */
53
- const URLPathTemplate = this.addScalarType(schema, URL_PATH_TEMPLATE);
54
-
55
- /* scalar JSONSelection */
56
- const JSONSelection = this.addScalarType(schema, JSON_SELECTION);
57
-
58
- /*
59
- directive @connect(
60
- source: String
61
- http: ConnectHTTP
62
- selection: JSONSelection!
63
- ) repeatable on FIELD_DEFINITION
64
- */
65
- const connect = this.addDirective(schema, CONNECT).addLocations(DirectiveLocation.FIELD_DEFINITION);
66
- connect.repeatable = true;
67
-
68
- connect.addArgument(SOURCE, schema.stringType());
69
-
70
- /*
71
- input HTTPHeaderMapping {
72
- name: String!
73
- as: String
74
- value: String
75
- }
76
- */
77
- const HTTPHeaderMapping = schema.addType(new InputObjectType(this.typeNameInSchema(schema, HTTP_HEADER_MAPPING)!));
78
- HTTPHeaderMapping.addField(new InputFieldDefinition('name')).type =
79
- new NonNullType(schema.stringType());
80
- HTTPHeaderMapping.addField(new InputFieldDefinition('as')).type =
81
- schema.stringType();
82
- HTTPHeaderMapping.addField(new InputFieldDefinition('value')).type =
83
- schema.stringType();
84
-
85
- /*
86
- input ConnectHTTP {
87
- GET: URLPathTemplate
88
- POST: URLPathTemplate
89
- PUT: URLPathTemplate
90
- PATCH: URLPathTemplate
91
- DELETE: URLPathTemplate
92
- body: JSONSelection
93
- headers: [HTTPHeaderMapping!]
94
- }
95
- */
96
- const ConnectHTTP = schema.addType(new InputObjectType(this.typeNameInSchema(schema, CONNECT_HTTP)!));
97
- ConnectHTTP.addField(new InputFieldDefinition('GET')).type = URLPathTemplate;
98
- ConnectHTTP.addField(new InputFieldDefinition('POST')).type = URLPathTemplate;
99
- ConnectHTTP.addField(new InputFieldDefinition('PUT')).type = URLPathTemplate;
100
- ConnectHTTP.addField(new InputFieldDefinition('PATCH')).type = URLPathTemplate;
101
- ConnectHTTP.addField(new InputFieldDefinition('DELETE')).type = URLPathTemplate;
102
- ConnectHTTP.addField(new InputFieldDefinition('body')).type = JSONSelection;
103
- ConnectHTTP.addField(new InputFieldDefinition('headers')).type =
104
- new ListType(new NonNullType(HTTPHeaderMapping));
105
- connect.addArgument('http', new NonNullType(ConnectHTTP));
106
-
107
- connect.addArgument('selection', JSONSelection);
108
-
109
- /*
110
- directive @source(
111
- name: String!
112
- http: ConnectHTTP
113
- ) repeatable on SCHEMA
114
- */
115
- const source = this.addDirective(schema, SOURCE).addLocations(
116
- DirectiveLocation.SCHEMA,
117
- );
118
- source.repeatable = true;
119
- source.addArgument('name', new NonNullType(schema.stringType()));
120
-
121
- /*
122
- input SourceHTTP {
123
- baseURL: String!
124
- headers: [HTTPHeaderMapping!]
125
- }
126
- */
127
- const SourceHTTP = schema.addType(new InputObjectType(this.typeNameInSchema(schema, SOURCE_HTTP)!));
128
- SourceHTTP.addField(new InputFieldDefinition('baseURL')).type =
129
- new NonNullType(schema.stringType());
130
- SourceHTTP.addField(new InputFieldDefinition('headers')).type =
131
- new ListType(new NonNullType(HTTPHeaderMapping));
132
-
133
- source.addArgument('http', new NonNullType(SourceHTTP));
134
-
135
- return [];
136
- }
137
-
138
- get defaultCorePurpose(): CorePurpose {
139
- return 'EXECUTION';
140
- }
141
- }
142
-
143
- export type SourceDirectiveArgs = {
144
- name: string;
145
- http: SourceDirectiveHTTP;
146
- };
147
-
148
- export type SourceDirectiveHTTP = {
149
- baseURL: string;
150
- headers?: HTTPHeaderMapping[];
151
- };
152
-
153
- type HTTPHeaderMapping = {
154
- name: string;
155
- as?: string;
156
- value?: string;
157
- };
158
-
159
- type URLPathTemplate = string;
160
- type JSONSelection = string;
161
-
162
- export type ConnectDirectiveArgs = {
163
- source: string;
164
- http: ConnectDirectiveHTTP;
165
- selection?: JSONSelection;
166
- };
167
-
168
- export type ConnectDirectiveHTTP = {
169
- GET?: URLPathTemplate;
170
- POST?: URLPathTemplate;
171
- PUT?: URLPathTemplate;
172
- PATCH?: URLPathTemplate;
173
- DELETE?: URLPathTemplate;
174
- body?: JSONSelection;
175
- headers?: HTTPHeaderMapping[];
176
- };
177
-
178
- export const CONNECT_VERSIONS = new FeatureDefinitions<ConnectSpecDefinition>(connectIdentity)
179
- .add(new ConnectSpecDefinition(new FeatureVersion(0, 1), new FeatureVersion(2, 7)));
180
-
181
- registerKnownFeature(CONNECT_VERSIONS);
package/src/wasm.ts DELETED
@@ -1,111 +0,0 @@
1
- /* eslint-disable @typescript-eslint/no-var-requires */
2
- /**
3
- * The TypeScript interface to the `wasm` module (implemented in Rust) with all the helpers needed to convert between
4
- * the two.
5
- */
6
-
7
- import {Schema} from "./definitions";
8
- import {
9
- ConstObjectValueNode,
10
- DefinitionNode,
11
- DocumentNode,
12
- GraphQLError,
13
- print,
14
- } from "graphql/index";
15
- import {FeatureUrl, LinkDirectiveArgs} from "./specs/coreSpec";
16
- import {connectIdentity} from "./specs/connectSpec";
17
- import {aggregateError} from "./error";
18
- import type {ErrorLocation, SourceDirective} from "../wasm/node";
19
- import {ASTNode, ConstValueNode, SchemaExtensionNode, StringValueNode} from "graphql";
20
-
21
- /**
22
- * @throws AggregateGraphQLError
23
- */
24
- export function validateSubgraphSchema(schema: Schema, ast: DocumentNode) {
25
- const errors = [];
26
- if (hasConnectDirectives(schema)) {
27
- errors.push(...validateConnectDirectives(ast));
28
- }
29
-
30
- if (errors.length > 0) {
31
- throw aggregateError("FROM_WASM", "WASM validation detected errors", errors)
32
- }
33
- }
34
-
35
- function hasConnectDirectives(schema: Schema): boolean {
36
- return schema.schemaDefinition.appliedDirectivesOf<LinkDirectiveArgs>('link')
37
- .some(linkDirective => {
38
- const {url, import: imports} = linkDirective.arguments();
39
- const featureUrl = FeatureUrl.maybeParse(url);
40
- return imports && featureUrl && featureUrl.identity === connectIdentity && imports.some(nameOrRename => {
41
- const originalName = typeof nameOrRename === 'string' ? nameOrRename : nameOrRename.name;
42
- return originalName === '@source' || originalName === '@connect';
43
- });
44
- });
45
- }
46
-
47
- function validateConnectDirectives(ast: DocumentNode): GraphQLError[] {
48
- // TODO: pass the _original_ source, not the one with added federation stuff (otherwise positions will be wrong)
49
- // TODO: unless, of course, there's already infrastructure up above which does translation somehow
50
- const {validate_connect_directives} =
51
- require('../wasm/node') as typeof import('../wasm/node');
52
- const source = print(ast)
53
- return validate_connect_directives(source).map(
54
- raw => new GraphQLError(raw.message, {
55
- // source: new Source(source),
56
- nodes: raw.location && findNode(ast, raw.location),
57
- extensions: {code: raw.code},
58
- }),
59
- );
60
- }
61
-
62
-
63
- function findNode(ast: DocumentNode, location: ErrorLocation): ASTNode | undefined {
64
- if (location.source) {
65
- const sourceDirective = findSourceDirective(ast, location.source);
66
- if (sourceDirective) {
67
- return sourceDirective;
68
- }
69
- }
70
- return undefined;
71
- }
72
-
73
- function findSourceDirective(ast: DocumentNode, sourceDirective: SourceDirective): ASTNode | undefined {
74
- const {SourceArgument} =
75
- require('../wasm/node') as typeof import('../wasm/node');
76
- const schema = ast.definitions.find(isSchemaExtension);
77
- const sourceDirectives = schema?.directives?.
78
- filter(directive => directive.name.value === "source");
79
- const matchingSource = sourceDirectives?.find(directive => {
80
- const nameArg = directive.arguments?.find(arg => arg.name.value === "name");
81
- return nameArg && isStringValue(nameArg.value) && nameArg.value.value === sourceDirective.name;
82
- });
83
- if (sourceDirective.arg === SourceArgument.Url) {
84
- const arg = matchingSource?.arguments?.find(arg => arg.name.value === "http");
85
- const value = arg?.value;
86
- if (value && isObjectValue(value)) {
87
- const field = value.fields.find(field => field.name.value === "baseURL");
88
- if (field) {
89
- return field;
90
- }
91
- }
92
- } else if (sourceDirective.arg === SourceArgument.Name) {
93
- const arg = matchingSource?.arguments?.find(arg => arg.name.value === "name");
94
- if (arg) {
95
- return arg;
96
- }
97
- }
98
- return matchingSource;
99
- }
100
-
101
- function isSchemaExtension(node: DefinitionNode): node is SchemaExtensionNode {
102
- return node.kind === "SchemaExtension";
103
- }
104
-
105
- function isStringValue(node: ConstValueNode): node is StringValueNode {
106
- return node.kind === "StringValue";
107
- }
108
-
109
- function isObjectValue(node: ConstValueNode): node is ConstObjectValueNode {
110
- return node.kind === "ObjectValue";
111
- }
@@ -1 +0,0 @@
1
- *
@@ -1,2 +0,0 @@
1
- # We don't want to check in build artifacts (thus the .gitignore), but we _do_ need NPM to publish those files
2
- # .npmignore overrides .gitignore
@@ -1,49 +0,0 @@
1
- /* tslint:disable */
2
- /* eslint-disable */
3
- /**
4
- * @param {string} schema
5
- * @returns {(GraphQLError)[]}
6
- */
7
- export function validate_connect_directives(schema: string): (GraphQLError)[];
8
- /**
9
- */
10
- export enum SourceArgument {
11
- Name = 0,
12
- Url = 1,
13
- }
14
- /**
15
- */
16
- export class ErrorLocation {
17
- free(): void;
18
- /**
19
- */
20
- readonly source: SourceDirective | undefined;
21
- }
22
- /**
23
- * Rust representation of `GraphQLError` from TypeScript
24
- *
25
- * TODO: Import the JavaScript version directly to avoid extra copying?
26
- */
27
- export class GraphQLError {
28
- free(): void;
29
- /**
30
- */
31
- code: any;
32
- /**
33
- */
34
- readonly location: ErrorLocation | undefined;
35
- /**
36
- */
37
- readonly message: string;
38
- }
39
- /**
40
- */
41
- export class SourceDirective {
42
- free(): void;
43
- /**
44
- */
45
- arg: SourceArgument;
46
- /**
47
- */
48
- readonly name: string;
49
- }