@apollo/federation-internals 2.4.5 → 2.4.7
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/operations.d.ts +43 -113
- package/dist/operations.d.ts.map +1 -1
- package/dist/operations.js +370 -297
- package/dist/operations.js.map +1 -1
- package/dist/utils.d.ts +1 -1
- package/dist/utils.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/operations.ts +697 -453
- package/src/utils.ts +1 -1
- package/CHANGELOG.md +0 -211
- package/jest.config.js +0 -11
- package/src/__tests__/coreSpec.test.ts +0 -212
- package/src/__tests__/definitions.test.ts +0 -982
- package/src/__tests__/directiveAndTypeSpecifications.test.ts +0 -41
- package/src/__tests__/extractSubgraphsFromSupergraph.test.ts +0 -748
- package/src/__tests__/federation.test.ts +0 -31
- package/src/__tests__/graphQLJSSchemaToAST.test.ts +0 -156
- package/src/__tests__/matchers/index.ts +0 -1
- package/src/__tests__/matchers/toMatchString.ts +0 -87
- package/src/__tests__/operations.test.ts +0 -1266
- package/src/__tests__/removeInaccessibleElements.test.ts +0 -2471
- package/src/__tests__/schemaUpgrader.test.ts +0 -287
- package/src/__tests__/subgraphValidation.test.ts +0 -1254
- package/src/__tests__/supergraphSdl.graphql +0 -281
- package/src/__tests__/testUtils.ts +0 -28
- package/src/__tests__/toAPISchema.test.ts +0 -53
- package/src/__tests__/tsconfig.json +0 -7
- package/src/__tests__/utils.test.ts +0 -92
- package/src/__tests__/values.test.ts +0 -390
- package/tsconfig.json +0 -10
- package/tsconfig.test.json +0 -8
- package/tsconfig.tsbuildinfo +0 -1
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import gql from "graphql-tag";
|
|
2
|
-
import { buildSubgraph, federationMetadata } from "..";
|
|
3
|
-
|
|
4
|
-
it("detects federation 1 subgraphs correctly", () => {
|
|
5
|
-
const schema = gql`
|
|
6
|
-
type Query {
|
|
7
|
-
s: String
|
|
8
|
-
}
|
|
9
|
-
`;
|
|
10
|
-
|
|
11
|
-
const subgraph = buildSubgraph('s', 's', schema);
|
|
12
|
-
const metadata = federationMetadata(subgraph.schema);
|
|
13
|
-
expect(metadata).toBeDefined();
|
|
14
|
-
expect(metadata?.isFed2Schema()).toBeFalsy();
|
|
15
|
-
});
|
|
16
|
-
|
|
17
|
-
it("detects federation 2 subgraphs correctly", () => {
|
|
18
|
-
const schema = gql`
|
|
19
|
-
extend schema
|
|
20
|
-
@link(url: "https://specs.apollo.dev/federation/v2.0")
|
|
21
|
-
|
|
22
|
-
type Query {
|
|
23
|
-
s: String
|
|
24
|
-
}
|
|
25
|
-
`;
|
|
26
|
-
|
|
27
|
-
const subgraph = buildSubgraph('s', 's', schema);
|
|
28
|
-
const metadata = federationMetadata(subgraph.schema);
|
|
29
|
-
expect(metadata).toBeDefined();
|
|
30
|
-
expect(metadata?.isFed2Schema()).toBeTruthy();
|
|
31
|
-
});
|
|
@@ -1,156 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
buildClientSchema,
|
|
3
|
-
buildSchema,
|
|
4
|
-
GraphQLSchema,
|
|
5
|
-
introspectionFromSchema,
|
|
6
|
-
print
|
|
7
|
-
} from "graphql";
|
|
8
|
-
import { graphQLJSSchemaToAST } from "../graphQLJSSchemaToAST";
|
|
9
|
-
import './matchers';
|
|
10
|
-
|
|
11
|
-
function validateRoundtrip(schemaStr: string, expectedWithoutASTNodes: string | undefined = schemaStr) {
|
|
12
|
-
const schema = buildSchema(schemaStr);
|
|
13
|
-
expect(print(graphQLJSSchemaToAST(schema))).toMatchString(schemaStr);
|
|
14
|
-
if (expectedWithoutASTNodes) {
|
|
15
|
-
expect(print(graphQLJSSchemaToAST(withoutASTNodes(schema)))).toMatchString(expectedWithoutASTNodes);
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
function withoutASTNodes(schema: GraphQLSchema): GraphQLSchema {
|
|
20
|
-
return buildClientSchema(introspectionFromSchema(schema));
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
it('round-trip for all type definitions', () => {
|
|
24
|
-
const schema = `
|
|
25
|
-
type Query {
|
|
26
|
-
a: A
|
|
27
|
-
b: B
|
|
28
|
-
c: C
|
|
29
|
-
d(arg: D): Int
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
interface I {
|
|
33
|
-
x: Int
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
type A implements I {
|
|
37
|
-
x: Int
|
|
38
|
-
y: Int
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
union B = A | Query
|
|
42
|
-
|
|
43
|
-
enum C {
|
|
44
|
-
V1
|
|
45
|
-
V2
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
input D {
|
|
49
|
-
m: Int
|
|
50
|
-
n: Int = 3
|
|
51
|
-
}
|
|
52
|
-
`;
|
|
53
|
-
|
|
54
|
-
validateRoundtrip(schema);
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
it('round-trip with default arguments', () => {
|
|
58
|
-
const schemaFct = (v: string) => `
|
|
59
|
-
type Query {
|
|
60
|
-
f(arg: V = ${v}): Int
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
input V {
|
|
64
|
-
x: Int
|
|
65
|
-
y: Int = 3
|
|
66
|
-
}
|
|
67
|
-
`;
|
|
68
|
-
|
|
69
|
-
const schema = schemaFct('{x: 2}');
|
|
70
|
-
// We go through introspection to ensure the AST nodes are
|
|
71
|
-
// removed, but that also somehow expand default values (which is
|
|
72
|
-
// fine, we just have to account for it in our assertion).
|
|
73
|
-
const schemaWithDefaultExpanded = schemaFct('{x: 2, y: 3}');
|
|
74
|
-
|
|
75
|
-
validateRoundtrip(schema, schemaWithDefaultExpanded);
|
|
76
|
-
});
|
|
77
|
-
|
|
78
|
-
it('round-trip for directive definitions and applications', () => {
|
|
79
|
-
const directiveDefinitions = `directive @schemaDirective(v: Int!) on SCHEMA
|
|
80
|
-
|
|
81
|
-
directive @typeDirective repeatable on OBJECT
|
|
82
|
-
|
|
83
|
-
directive @fieldDirective(s: String, m: Int = 3) on FIELD_DEFINITION
|
|
84
|
-
`;
|
|
85
|
-
|
|
86
|
-
const schema = `
|
|
87
|
-
schema @schemaDirective(v: 3) {
|
|
88
|
-
query: Query
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
type Query @typeDirective @typeDirective {
|
|
92
|
-
f: Int @fieldDirective(s: "foo")
|
|
93
|
-
g: Int @deprecated
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
${directiveDefinitions}
|
|
97
|
-
`;
|
|
98
|
-
|
|
99
|
-
// With the ast nodes removed, we lose custom directive applications
|
|
100
|
-
const noApplications = `
|
|
101
|
-
type Query {
|
|
102
|
-
f: Int
|
|
103
|
-
g: Int @deprecated
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
${directiveDefinitions}
|
|
107
|
-
`;
|
|
108
|
-
|
|
109
|
-
validateRoundtrip(schema, noApplications);
|
|
110
|
-
});
|
|
111
|
-
|
|
112
|
-
it('round-trip with extensions', () => {
|
|
113
|
-
const common = `scalar federation_FieldSet
|
|
114
|
-
|
|
115
|
-
scalar link_Import
|
|
116
|
-
|
|
117
|
-
directive @link(url: String!, import: link_Import) on SCHEMA
|
|
118
|
-
|
|
119
|
-
directive @key(fields: federation_FieldSet) repeatable on OBJECT
|
|
120
|
-
`;
|
|
121
|
-
|
|
122
|
-
const schema = `
|
|
123
|
-
extend schema @link(url: "https://specs.apollo.dev", import: ["@key"])
|
|
124
|
-
|
|
125
|
-
type Query {
|
|
126
|
-
t: T
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
type T
|
|
130
|
-
|
|
131
|
-
extend type T @key(fields: "id") {
|
|
132
|
-
id: ID!
|
|
133
|
-
x: Int
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
${common}
|
|
137
|
-
`;
|
|
138
|
-
|
|
139
|
-
// No AST means we lose both the directive applications, but also whether something is an
|
|
140
|
-
// extension or not.
|
|
141
|
-
const noAST = `
|
|
142
|
-
type Query {
|
|
143
|
-
t: T
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
type T {
|
|
147
|
-
id: ID!
|
|
148
|
-
x: Int
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
${common}
|
|
152
|
-
`;
|
|
153
|
-
|
|
154
|
-
validateRoundtrip(schema, noAST);
|
|
155
|
-
});
|
|
156
|
-
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import './toMatchString';
|
|
@@ -1,87 +0,0 @@
|
|
|
1
|
-
// Make this file a module (See: https://github.com/microsoft/TypeScript/issues/17736)
|
|
2
|
-
export {};
|
|
3
|
-
|
|
4
|
-
// TODO: this is the same than in definition.test.ts. Could we move those to a common place (but is it worth having
|
|
5
|
-
// a new module for that)? Maybe there is a better, more jest-native, way to do this.
|
|
6
|
-
// Note(Sylvain): I initially added those because I didn't figure out a way to make `toMatchSnapshotInline` work
|
|
7
|
-
// with strings cleanly: I always either ended up with indentation issuels, or the result looks very ugly in the
|
|
8
|
-
// tests. But it could be I just don't understand well enough how it work.
|
|
9
|
-
declare global {
|
|
10
|
-
namespace jest {
|
|
11
|
-
interface Matchers<R> {
|
|
12
|
-
toMatchString(actual: string): R;
|
|
13
|
-
toMatchStringArray(actual: string[]): R;
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
function deIndent(str: string): string {
|
|
19
|
-
// Strip leading \n
|
|
20
|
-
str = str.slice(str.search(/[^\n]/));
|
|
21
|
-
// Strip trailing \n or space
|
|
22
|
-
while (str.charAt(str.length - 1) === '\n' || str.charAt(str.length - 1) === ' ') {
|
|
23
|
-
str = str.slice(0, str.length - 1);
|
|
24
|
-
}
|
|
25
|
-
const indent = str.search(/[^ ]/);
|
|
26
|
-
return str
|
|
27
|
-
.split('\n')
|
|
28
|
-
.map(line => line.slice(indent))
|
|
29
|
-
.join('\n');
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
expect.extend({
|
|
33
|
-
toMatchString(expected: string, received: string) {
|
|
34
|
-
received = deIndent(received);
|
|
35
|
-
// If the expected string as a trailing '\n', add one since we removed it.
|
|
36
|
-
if (expected.charAt(expected.length - 1) === '\n') {
|
|
37
|
-
received = received + '\n';
|
|
38
|
-
}
|
|
39
|
-
const pass = this.equals(expected, received);
|
|
40
|
-
const message = pass
|
|
41
|
-
? () => this.utils.matcherHint('toMatchString', undefined, undefined)
|
|
42
|
-
+ '\n\n'
|
|
43
|
-
+ `Expected: not ${this.printExpected(expected)}`
|
|
44
|
-
: () => {
|
|
45
|
-
return (
|
|
46
|
-
this.utils.matcherHint('toMatchString', undefined, undefined,)
|
|
47
|
-
+ '\n\n'
|
|
48
|
-
+ this.utils.printDiffOrStringify(expected, received, 'Expected', 'Received', true));
|
|
49
|
-
};
|
|
50
|
-
return {received, expected, message, name: 'toMatchString', pass};
|
|
51
|
-
},
|
|
52
|
-
|
|
53
|
-
toMatchStringArray(expected: string[], received: string[]) {
|
|
54
|
-
if (expected.length !== received.length) {
|
|
55
|
-
const message = () =>
|
|
56
|
-
this.utils.matcherHint('toMatchStringArray', undefined, undefined,)
|
|
57
|
-
+ `\n\nExpected an array of size ${expected.length} but got one of size ${received.length}\n\n`
|
|
58
|
-
+ this.utils.printDiffOrStringify(expected, received, 'Expected', 'Received', true);
|
|
59
|
-
return {received, expected, message, name: 'toMatchStringArray', pass: false};
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
let pass = true;
|
|
63
|
-
const messages: string[] = [];
|
|
64
|
-
for (let i = 0; i < expected.length; i++) {
|
|
65
|
-
const exp = expected[i];
|
|
66
|
-
let rec = deIndent(received[i]);
|
|
67
|
-
// If the expected string as a trailing '\n', add one since we removed it.
|
|
68
|
-
if (exp.charAt(exp.length - 1) === '\n') {
|
|
69
|
-
rec = rec + '\n';
|
|
70
|
-
}
|
|
71
|
-
if (!this.equals(exp, rec)) {
|
|
72
|
-
pass = false;
|
|
73
|
-
messages.push(
|
|
74
|
-
`Elements at index ${i} do no match:\n`
|
|
75
|
-
+ this.utils.printDiffOrStringify(exp, rec, 'Expected', 'Received', true)
|
|
76
|
-
);
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
const message = () =>
|
|
80
|
-
this.utils.matcherHint('toMatchString', undefined, undefined)
|
|
81
|
-
+ '\n\n'
|
|
82
|
-
+ (pass ? `Expected: not ${this.printExpected(expected)}` : messages.join('\n\n'));
|
|
83
|
-
|
|
84
|
-
return {received, expected, message, name: 'toMatchStringArray', pass};
|
|
85
|
-
}
|
|
86
|
-
});
|
|
87
|
-
|