Skip to content

Commit 4f3c3b9

Browse files
Introduce @requiresScopes directive in composition (#2649)
With this change, users can now compose `@requiresScopes` applications from their subgraphs into a supergraph. This addition will support a future version of Apollo Router that enables authenticated access to specific types and fields via directive applications. Since the implementation of `@requiresScopes` is strictly a composition and execution concern, there's no change to the query planner with this work. The execution work is well under way in Apollo Router (and won't be built at all for Gateway). So as far as this repo is concerned, only composition is concerned with `@requiresScopes`. Co-authored-by: Sylvain Lebresne <[email protected]>
1 parent fe1e3d7 commit 4f3c3b9

18 files changed

+692
-119
lines changed

.changeset/thirty-fans-deliver.md

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
---
2+
"@apollo/query-planner": minor
3+
"@apollo/composition": minor
4+
"@apollo/federation-internals": minor
5+
"@apollo/gateway": minor
6+
---
7+
8+
Introduce the new `@requiresScopes` directive for composition
9+
10+
> Note that this directive will only be _fully_ supported by the Apollo Router as a GraphOS Enterprise feature at runtime. Also note that _composition_ of valid `@requiresScopes` directive applications will succeed, but the resulting supergraph will not be _executable_ by the Gateway or an Apollo Router which doesn't have the GraphOS Enterprise entitlement.
11+
12+
Users may now compose `@requiresScopes` applications from their subgraphs into a supergraph. This addition will support a future version of Apollo Router that enables scoped access to specific types and fields via directive applications.
13+
14+
The directive is defined as follows:
15+
16+
```graphql
17+
scalar federation__Scope
18+
19+
directive @requiresScopes(scopes: [federation__Scope!]!) on
20+
| FIELD_DEFINITION
21+
| OBJECT
22+
| INTERFACE
23+
| SCALAR
24+
| ENUM
25+
```
26+
27+
The `Scope` scalar is effectively a `String`, similar to the `FieldSet` type.
28+
29+
In order to compose your `@requiresScopes` usages, you must update your subgraph's federation spec version to v2.5 and add the `@requiresScopes` import to your existing imports like so:
30+
```graphql
31+
@link(url: "https://specs.apollo.dev/federation/v2.5", import: [..., "@requiresScopes"])
32+
```

.cspell/cspell-dict.txt

+1
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,7 @@ subraph
221221
subraphs
222222
Substrat
223223
sugraph
224+
supergraph
224225
svitejs
225226
Sylvain
226227
sylvain

composition-js/src/__tests__/compose.composeDirective.test.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ describe('composing custom core directives', () => {
261261
});
262262

263263
it.each([
264-
'@tag', '@inaccessible', '@authenticated',
264+
'@tag', '@inaccessible', '@authenticated', '@requiresScopes',
265265
])('federation directives that result in a hint', (directive) => {
266266
const subgraphA = generateSubgraph({
267267
name: 'subgraphA',
@@ -282,7 +282,7 @@ describe('composing custom core directives', () => {
282282
});
283283

284284
it.each([
285-
'@tag', '@inaccessible', '@authenticated',
285+
'@tag', '@inaccessible', '@authenticated', '@requiresScopes',
286286
])('federation directives (with rename) that result in a hint', (directive) => {
287287
const subgraphA = {
288288
name: 'subgraphA',

0 commit comments

Comments
 (0)