Commit 3df4612
authored
Implement one-off support for input objects in the connect spec (#3311)
This PR implements one-off support for input objects in the connect
spec. Note that this implementation is hacky, and has various edge cases
where it won't behave as expected. In the short-term, we should avoid
using input objects in specs. In the long-term, there's a proper
strategy to supporting input objects in specs, which is described below.
To give some background:
1. Our schema representation (`Schema`) uses JS singleton objects for
schema elements.
2. Type references in these schema elements (e.g. the type of a field or
argument) will refer directly to these JS singletons.
3. This schema representation also tracks type/directive references in
the referenced schema element.
This means that schema building has to proceed in a two-phase process.
1. The first phase declares the types/directive definitions/extensions
(referred to as "shallow building" of the type/directive).
2. The second phase defines the types/directive definitions/extensions
(referred to as just "building" of the type/directive).
This is necessary because types/directives are allowed to form
referential cycles, so we can't just e.g. topologically sort the
types/directives by referential order and fully build in that order.
A problem arises, however, with subgraph schemas (a.k.a. schemas using
`FederationBlueprint`). In that case, schemas are allowed to omit
definitions/extensions of spec types/directives, for both the
`federation` and `connect` specs. These missing definitions/extensions
are added (or if already added, they're checked) by the `checkOrAdd()`
methods of type/directive specifications.
The `checkOrAdd()` pattern has a design flaw in that it bundles shallow
building, building, and checking into one single function. Specifically:
1. When building a schema, during the first phase, there may be missing
spec types/directives that are not written.
2. This blocks us from the second phase of building types/directives, as
they may depend on these missing types/directives.
3. This results in us calling `checkOrAdd()` for a type/directive spec
to fill in the missing definitions.
4. However, `checkOrAdd()` for a type/directive specification, in
bundling everything together, requires the types/directives it
references to be fully built.
This has several implications:
1. Specs with circular type/directive references just won't work.
2. Even if there's some topological order of references that can be
established, that order is currently not computed or followed. The
current `checkOrAdd()` calling logic just calls it for all registered
type specifications, and then all registered directive specifications.
This order has to be a topological referential order for schemas that
omit all spec type/directive definitions/extensions to build properly,
and that registration can be error-prone to manually specify/maintain.
- Also, this isn't done in a way that's interleaved with the building of
those elements if they already exist; for those elements, they need to
be built prior to the `checkOrAdd()` calls, otherwise the checking part
fails.
4. This has led to a very bespoke fragile pattern in schema building
where we first fully build enums and scalars while skipping directive
applications (since they can't reference other types/directives in that
case), then directive definitions while skipping directive applications,
and then call `checkOrAdd()` (after processing `@link`s).
5. This bespoke fragile pattern only worked before because the
federation spec just has type/directive definitions that only reference
enum/scalar types. And even in that case, if someone e.g. wrote in a
spec directive definition that referenced spec enums/scalars, they must
also write the definitions for those referenced enums/scalars, since
otherwise that directive definition would fail to build.
6. This bespoke fragile pattern does not work for connectors, since
those spec types/directives reference spec input object types, and some
of those spec input object types even reference other spec input object
types.
In order to support connectors usage of input object types in the
short-term, we must do a few things.
1. Verify there are no referential cycles (there aren't thankfully), and
register types/directives in the appropriate topological order.
2. Before calling `checkOrAdd()` for the connect spec, ensure that input
objects are built if they exist in the schema. This is going to have the
same limitation that the federation spec has with directive definitions,
where if someone wrote in a spec input object definition that references
other spec types/directives, they also need to write the definitions for
those referenced types/directives.
This will handle the main cases we wish to support, which are when no
connect spec definitions/extensions are provided and when they're all
provided. That's what this PR does (it also adds a test).
The actual long-term solution involves splitting the `checkOrAdd()`
logic into three separate functions:
1. Shallow building of spec types/directives that aren't in the schema
(accounting for renames as needed).
2. Full building of spec types/directives that aren't in the schema.
3. Checking of spec types/directives to ensure they conform to expected
definitions.
The gist is that we first do some processing on schema
definitions/extensions to bootstrap the `link` spec, then we couple spec
shallow building with the rest of shallow building (phase 1), couple
spec full building with the rest of full building (phase 2), and save
checking for after everything's built. There could be some additional
tracking to avoid doing checking for types/directives that weren't
originally in the schema, but that's not strictly necessary.
This PR also implements various fixes for bugs noticed in
#3310; these will be
pointed out in that PR's review.1 parent 7306739 commit 3df4612
File tree
4 files changed
+312
-166
lines changed- composition-js/src/__tests__
- internals-js/src
- specs
4 files changed
+312
-166
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | | - | |
| 2 | + | |
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
6 | | - | |
7 | | - | |
8 | | - | |
9 | | - | |
10 | | - | |
11 | | - | |
12 | | - | |
13 | | - | |
14 | | - | |
15 | | - | |
16 | | - | |
17 | | - | |
18 | | - | |
19 | | - | |
20 | | - | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
21 | 22 | | |
22 | | - | |
23 | | - | |
24 | | - | |
25 | | - | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
26 | 39 | | |
27 | | - | |
28 | | - | |
29 | | - | |
30 | | - | |
31 | | - | |
32 | | - | |
33 | | - | |
| 40 | + | |
34 | 41 | | |
35 | | - | |
36 | | - | |
37 | | - | |
38 | | - | |
39 | | - | |
40 | | - | |
41 | | - | |
42 | | - | |
43 | | - | |
44 | | - | |
45 | | - | |
46 | | - | |
47 | | - | |
| 42 | + | |
48 | 43 | | |
49 | | - | |
| 44 | + | |
50 | 45 | | |
51 | | - | |
| 46 | + | |
52 | 47 | | |
53 | | - | |
| 48 | + | |
54 | 49 | | |
55 | | - | |
| 50 | + | |
56 | 51 | | |
57 | | - | |
| 52 | + | |
58 | 53 | | |
59 | | - | |
| 54 | + | |
60 | 55 | | |
61 | | - | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
62 | 61 | | |
63 | | - | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
64 | 67 | | |
65 | | - | |
66 | | - | |
67 | | - | |
68 | | - | |
69 | | - | |
| 68 | + | |
70 | 69 | | |
71 | | - | |
72 | | - | |
73 | | - | |
74 | | - | |
75 | | - | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
76 | 73 | | |
77 | | - | |
| 74 | + | |
78 | 75 | | |
79 | | - | |
80 | | - | |
81 | | - | |
| 76 | + | |
82 | 77 | | |
83 | | - | |
| 78 | + | |
84 | 79 | | |
85 | | - | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
86 | 86 | | |
87 | | - | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
88 | 92 | | |
89 | | - | |
90 | | - | |
91 | | - | |
92 | | - | |
93 | | - | |
94 | | - | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
95 | 105 | | |
96 | | - | |
97 | | - | |
98 | | - | |
99 | | - | |
100 | | - | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
101 | 111 | | |
102 | | - | |
103 | | - | |
| 112 | + | |
| 113 | + | |
104 | 114 | | |
105 | | - | |
106 | | - | |
107 | | - | |
108 | | - | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
109 | 124 | | |
110 | 125 | | |
111 | | - | |
112 | | - | |
113 | | - | |
114 | | - | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
115 | 130 | | |
116 | | - | |
117 | | - | |
118 | | - | |
119 | | - | |
120 | | - | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
121 | 153 | | |
122 | 154 | | |
123 | 155 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
56 | 56 | | |
57 | 57 | | |
58 | 58 | | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
59 | 62 | | |
60 | 63 | | |
61 | 64 | | |
| |||
143 | 146 | | |
144 | 147 | | |
145 | 148 | | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
146 | 191 | | |
147 | 192 | | |
148 | 193 | | |
| |||
155 | 200 | | |
156 | 201 | | |
157 | 202 | | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
158 | 206 | | |
159 | 207 | | |
160 | 208 | | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
161 | 212 | | |
162 | 213 | | |
163 | 214 | | |
| |||
0 commit comments