@apollo/federation-internals 2.0.0-preview.7 → 2.0.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 (109) hide show
  1. package/CHANGELOG.md +32 -3
  2. package/dist/buildSchema.d.ts.map +1 -1
  3. package/dist/buildSchema.js +51 -41
  4. package/dist/buildSchema.js.map +1 -1
  5. package/dist/coreSpec.d.ts +16 -8
  6. package/dist/coreSpec.d.ts.map +1 -1
  7. package/dist/coreSpec.js +205 -53
  8. package/dist/coreSpec.js.map +1 -1
  9. package/dist/definitions.d.ts +28 -11
  10. package/dist/definitions.d.ts.map +1 -1
  11. package/dist/definitions.js +185 -67
  12. package/dist/definitions.js.map +1 -1
  13. package/dist/directiveAndTypeSpecification.d.ts +11 -1
  14. package/dist/directiveAndTypeSpecification.d.ts.map +1 -1
  15. package/dist/directiveAndTypeSpecification.js +77 -20
  16. package/dist/directiveAndTypeSpecification.js.map +1 -1
  17. package/dist/error.d.ts +17 -0
  18. package/dist/error.d.ts.map +1 -1
  19. package/dist/error.js +54 -2
  20. package/dist/error.js.map +1 -1
  21. package/dist/extractSubgraphsFromSupergraph.d.ts.map +1 -1
  22. package/dist/extractSubgraphsFromSupergraph.js +7 -1
  23. package/dist/extractSubgraphsFromSupergraph.js.map +1 -1
  24. package/dist/federation.d.ts +22 -5
  25. package/dist/federation.d.ts.map +1 -1
  26. package/dist/federation.js +143 -86
  27. package/dist/federation.js.map +1 -1
  28. package/dist/federationSpec.d.ts +6 -2
  29. package/dist/federationSpec.d.ts.map +1 -1
  30. package/dist/federationSpec.js +47 -22
  31. package/dist/federationSpec.js.map +1 -1
  32. package/dist/inaccessibleSpec.d.ts +10 -2
  33. package/dist/inaccessibleSpec.d.ts.map +1 -1
  34. package/dist/inaccessibleSpec.js +634 -16
  35. package/dist/inaccessibleSpec.js.map +1 -1
  36. package/dist/index.d.ts +2 -0
  37. package/dist/index.d.ts.map +1 -1
  38. package/dist/index.js +2 -0
  39. package/dist/index.js.map +1 -1
  40. package/dist/introspection.d.ts.map +1 -1
  41. package/dist/introspection.js +8 -3
  42. package/dist/introspection.js.map +1 -1
  43. package/dist/joinSpec.d.ts +5 -1
  44. package/dist/joinSpec.d.ts.map +1 -1
  45. package/dist/joinSpec.js +21 -0
  46. package/dist/joinSpec.js.map +1 -1
  47. package/dist/knownCoreFeatures.d.ts +4 -0
  48. package/dist/knownCoreFeatures.d.ts.map +1 -0
  49. package/dist/knownCoreFeatures.js +16 -0
  50. package/dist/knownCoreFeatures.js.map +1 -0
  51. package/dist/operations.d.ts +1 -0
  52. package/dist/operations.d.ts.map +1 -1
  53. package/dist/operations.js +16 -1
  54. package/dist/operations.js.map +1 -1
  55. package/dist/{sharing.d.ts → precompute.d.ts} +1 -1
  56. package/dist/precompute.d.ts.map +1 -0
  57. package/dist/{sharing.js → precompute.js} +3 -3
  58. package/dist/precompute.js.map +1 -0
  59. package/dist/schemaUpgrader.d.ts.map +1 -1
  60. package/dist/schemaUpgrader.js +17 -7
  61. package/dist/schemaUpgrader.js.map +1 -1
  62. package/dist/suggestions.d.ts +1 -1
  63. package/dist/suggestions.d.ts.map +1 -1
  64. package/dist/suggestions.js.map +1 -1
  65. package/dist/supergraphs.d.ts.map +1 -1
  66. package/dist/supergraphs.js +2 -0
  67. package/dist/supergraphs.js.map +1 -1
  68. package/dist/tagSpec.d.ts +7 -2
  69. package/dist/tagSpec.d.ts.map +1 -1
  70. package/dist/tagSpec.js +35 -14
  71. package/dist/tagSpec.js.map +1 -1
  72. package/dist/validate.js +13 -7
  73. package/dist/validate.js.map +1 -1
  74. package/dist/values.d.ts +2 -2
  75. package/dist/values.d.ts.map +1 -1
  76. package/dist/values.js +13 -11
  77. package/dist/values.js.map +1 -1
  78. package/package.json +4 -4
  79. package/src/__tests__/coreSpec.test.ts +212 -0
  80. package/src/__tests__/definitions.test.ts +75 -0
  81. package/src/__tests__/removeInaccessibleElements.test.ts +2229 -137
  82. package/src/__tests__/schemaUpgrader.test.ts +3 -2
  83. package/src/__tests__/subgraphValidation.test.ts +419 -4
  84. package/src/__tests__/values.test.ts +315 -3
  85. package/src/buildSchema.ts +98 -51
  86. package/src/coreSpec.ts +277 -65
  87. package/src/definitions.ts +317 -92
  88. package/src/directiveAndTypeSpecification.ts +98 -21
  89. package/src/error.ts +119 -1
  90. package/src/extractSubgraphsFromSupergraph.ts +7 -1
  91. package/src/federation.ts +184 -102
  92. package/src/federationSpec.ts +56 -24
  93. package/src/inaccessibleSpec.ts +985 -39
  94. package/src/index.ts +2 -0
  95. package/src/introspection.ts +8 -3
  96. package/src/joinSpec.ts +33 -3
  97. package/src/knownCoreFeatures.ts +13 -0
  98. package/src/operations.ts +15 -0
  99. package/src/{sharing.ts → precompute.ts} +3 -6
  100. package/src/schemaUpgrader.ts +29 -13
  101. package/src/suggestions.ts +1 -1
  102. package/src/supergraphs.ts +2 -0
  103. package/src/tagSpec.ts +49 -16
  104. package/src/validate.ts +20 -9
  105. package/src/values.ts +39 -12
  106. package/tsconfig.test.tsbuildinfo +1 -1
  107. package/tsconfig.tsbuildinfo +1 -1
  108. package/dist/sharing.d.ts.map +0 -1
  109. package/dist/sharing.js.map +0 -1
@@ -9,10 +9,12 @@ import {
9
9
  createDirectiveSpecification,
10
10
  createScalarTypeSpecification,
11
11
  } from "./directiveAndTypeSpecification";
12
- import { DirectiveLocation } from "graphql";
12
+ import { DirectiveLocation, GraphQLError } from "graphql";
13
13
  import { assert } from "./utils";
14
- import { tagLocations } from "./tagSpec";
14
+ import { TAG_VERSIONS } from "./tagSpec";
15
15
  import { federationMetadata } from "./federation";
16
+ import { registerKnownFeature } from "./knownCoreFeatures";
17
+ import { INACCESSIBLE_VERSIONS } from "./inaccessibleSpec";
16
18
 
17
19
  export const federationIdentity = 'https://specs.apollo.dev/federation';
18
20
 
@@ -22,10 +24,13 @@ export const keyDirectiveSpec = createDirectiveSpecification({
22
24
  name:'key',
23
25
  locations: [DirectiveLocation.OBJECT, DirectiveLocation.INTERFACE],
24
26
  repeatable: true,
25
- argumentFct: (schema) => [
26
- fieldsArgument(schema),
27
- { name: 'resolvable', type: schema.booleanType(), defaultValue: true },
28
- ]
27
+ argumentFct: (schema) => ({
28
+ args: [
29
+ fieldsArgument(schema),
30
+ { name: 'resolvable', type: schema.booleanType(), defaultValue: true },
31
+ ],
32
+ errors: [],
33
+ }),
29
34
  });
30
35
 
31
36
  export const extendsDirectiveSpec = createDirectiveSpecification({
@@ -36,22 +41,28 @@ export const extendsDirectiveSpec = createDirectiveSpecification({
36
41
  export const externalDirectiveSpec = createDirectiveSpecification({
37
42
  name:'external',
38
43
  locations: [DirectiveLocation.OBJECT, DirectiveLocation.FIELD_DEFINITION],
44
+ argumentFct: (schema) => ({
45
+ args: [{ name: 'reason', type: schema.stringType() }],
46
+ errors: [],
47
+ }),
39
48
  });
40
49
 
41
50
  export const requiresDirectiveSpec = createDirectiveSpecification({
42
51
  name:'requires',
43
52
  locations: [DirectiveLocation.FIELD_DEFINITION],
44
- argumentFct: (schema) => {
45
- return [fieldsArgument(schema)];
46
- }
53
+ argumentFct: (schema) => ({
54
+ args: [fieldsArgument(schema)],
55
+ errors: [],
56
+ }),
47
57
  });
48
58
 
49
59
  export const providesDirectiveSpec = createDirectiveSpecification({
50
60
  name:'provides',
51
61
  locations: [DirectiveLocation.FIELD_DEFINITION],
52
- argumentFct: (schema) => {
53
- return [fieldsArgument(schema)];
54
- }
62
+ argumentFct: (schema) => ({
63
+ args: [fieldsArgument(schema)],
64
+ errors: [],
65
+ }),
55
66
  });
56
67
 
57
68
  export const shareableDirectiveSpec = createDirectiveSpecification({
@@ -59,13 +70,13 @@ export const shareableDirectiveSpec = createDirectiveSpecification({
59
70
  locations: [DirectiveLocation.OBJECT, DirectiveLocation.FIELD_DEFINITION],
60
71
  });
61
72
 
62
- export const tagDirectiveSpec = createDirectiveSpecification({
63
- name:'tag',
64
- locations: tagLocations,
65
- repeatable: true,
66
- argumentFct: (schema) => {
67
- return [{ name: 'name', type: new NonNullType(schema.stringType()) }];
68
- }
73
+ export const overrideDirectiveSpec = createDirectiveSpecification({
74
+ name: 'override',
75
+ locations: [DirectiveLocation.FIELD_DEFINITION],
76
+ argumentFct: (schema) => ({
77
+ args: [{ name: 'from', type: new NonNullType(schema.stringType()) }],
78
+ errors: [],
79
+ }),
69
80
  });
70
81
 
71
82
  function fieldsArgument(schema: Schema): ArgumentSpecification {
@@ -78,17 +89,28 @@ function fieldSetType(schema: Schema): InputType {
78
89
  return new NonNullType(metadata.fieldSetType());
79
90
  }
80
91
 
92
+ export const FEDERATION2_ONLY_SPEC_DIRECTIVES = [
93
+ shareableDirectiveSpec,
94
+ INACCESSIBLE_VERSIONS.latest().inaccessibleDirectiveSpec,
95
+ overrideDirectiveSpec,
96
+ ];
97
+
81
98
  // Note that this is only used for federation 2+ (federation 1 adds the same directive, but not through a core spec).
82
99
  export const FEDERATION2_SPEC_DIRECTIVES = [
83
100
  keyDirectiveSpec,
84
101
  requiresDirectiveSpec,
85
102
  providesDirectiveSpec,
86
103
  externalDirectiveSpec,
87
- shareableDirectiveSpec,
88
- tagDirectiveSpec,
104
+ TAG_VERSIONS.latest().tagDirectiveSpec,
89
105
  extendsDirectiveSpec, // TODO: should we stop supporting that?
106
+ ...FEDERATION2_ONLY_SPEC_DIRECTIVES,
90
107
  ];
91
108
 
109
+ // Note that this is meant to contain _all_ federation directive names ever supported, regardless of which version.
110
+ // But currently, fed2 directives are a superset of fed1's so ... (but this may change if we stop supporting `@extends`
111
+ // in fed2).
112
+ export const ALL_FEDERATION_DIRECTIVES_DEFAULT_NAMES = FEDERATION2_SPEC_DIRECTIVES.map((spec) => spec.name);
113
+
92
114
  export const FEDERATION_SPEC_TYPES = [
93
115
  fieldSetTypeSpec,
94
116
  ]
@@ -98,17 +120,27 @@ export class FederationSpecDefinition extends FeatureDefinition {
98
120
  super(new FeatureUrl(federationIdentity, 'federation', version));
99
121
  }
100
122
 
101
- addElementsToSchema(schema: Schema) {
123
+ addElementsToSchema(schema: Schema): GraphQLError[] {
102
124
  const feature = this.featureInSchema(schema);
103
125
  assert(feature, 'The federation specification should have been added to the schema before this is called');
104
126
 
105
- fieldSetTypeSpec.checkOrAdd(schema, feature.typeNameInSchema(fieldSetTypeSpec.name));
127
+ let errors: GraphQLError[] = [];
128
+ errors = errors.concat(this.addTypeSpec(schema, fieldSetTypeSpec));
106
129
 
107
130
  for (const directive of FEDERATION2_SPEC_DIRECTIVES) {
108
- directive.checkOrAdd(schema, feature.directiveNameInSchema(directive.name));
131
+ errors = errors.concat(this.addDirectiveSpec(schema, directive));
109
132
  }
133
+ return errors;
134
+ }
135
+
136
+ allElementNames(): string[] {
137
+ return FEDERATION2_SPEC_DIRECTIVES.map((spec) => `@${spec.name}`).concat([
138
+ fieldSetTypeSpec.name,
139
+ ])
110
140
  }
111
141
  }
112
142
 
113
143
  export const FEDERATION_VERSIONS = new FeatureDefinitions<FederationSpecDefinition>(federationIdentity)
114
144
  .add(new FederationSpecDefinition(new FeatureVersion(2, 0)));
145
+
146
+ registerKnownFeature(FEDERATION_VERSIONS);