Skip to content

Commit

Permalink
Modify type of argument of @requiresScope (#2738)
Browse files Browse the repository at this point in the history
This modifies the type for the argument of the `@requiresScopes` from `[federation__Scope!]!` to `[[federation__Scope!]!]!` in order to support "OR" semantic within subgraphs.

Note that this PR does not bump any spec versions, even if technically `@requiresScopes` has already been part of 2.5.0+ because:
- the overarching feature it exists for has not be released yet so the directive is not really effectively usable yet.
- bumping the federation spec to 2.6, which this would require if we wanted to bump versions, would be disruption and confusing, so this feel unecessary given the previous.
  • Loading branch information
Sylvain Lebresne authored Aug 16, 2023
1 parent c6e0e76 commit 4b9a512
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 deletions.
13 changes: 13 additions & 0 deletions .changeset/great-lions-work.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
"@apollo/composition": patch
"@apollo/federation-internals": patch
---

Modifies the type for the argument of the `@requiresScopes` from `[federation__Scope!]!` to `[[federation__Scope!]!]!`.

The `@requiresScopes` directives has been pre-emptively introduced in 2.5.0 to support an upcoming Apollo Router
feature around scoped accesses. The argument for `@requiresScopes` in that upcoming feature is changed to accommodate a
new semantic. Note that this technically a breaking change to the `@requiresScopes` directive definition, but as the
full feature using that directive has been released yet, this directive cannot effectively be used and this should have
no concrete impact.

6 changes: 3 additions & 3 deletions composition-js/src/__tests__/compose.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4493,7 +4493,7 @@ describe('composition', () => {
"https://specs.apollo.dev/requiresScopes/v0.1"
);
expect(printDirectiveDefinition(result.schema.directive('requiresScopes')!)).toMatchString(`
directive @requiresScopes(scopes: [requiresScopes__Scope!]!) on FIELD_DEFINITION | OBJECT | INTERFACE | SCALAR | ENUM
directive @requiresScopes(scopes: [[requiresScopes__Scope!]!]!) on FIELD_DEFINITION | OBJECT | INTERFACE | SCALAR | ENUM
`);
});

Expand Down Expand Up @@ -4527,7 +4527,7 @@ describe('composition', () => {
const invalidDefinition = {
typeDefs: gql`
scalar federation__Scope
directive @requiresScopes(scopes: [federation__Scope!]!) on ENUM_VALUE
directive @requiresScopes(scopes: [[federation__Scope!]!]!) on ENUM_VALUE
type Query {
a: Int
Expand Down Expand Up @@ -4565,7 +4565,7 @@ describe('composition', () => {
const result = composeAsFed2Subgraphs([invalidDefinition]);
expect(errors(result)[0]).toEqual([
"DIRECTIVE_DEFINITION_INVALID",
"[invalidDefinition] Invalid definition for directive \"@requiresScopes\": argument \"scopes\" should have type \"[federation__Scope!]!\" but found type \"[federation__Scope]!\"",
"[invalidDefinition] Invalid definition for directive \"@requiresScopes\": argument \"scopes\" should have type \"[[federation__Scope!]!]!\" but found type \"[federation__Scope]!\"",
]);
});

Expand Down
2 changes: 1 addition & 1 deletion internals-js/src/requiresScopesSpec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export class RequiresScopesSpecDefinition extends FeatureDefinition {
const scopeName = feature.typeNameInSchema(RequiresScopesTypeName.SCOPE);
const scopeType = schema.type(scopeName);
assert(scopeType, () => `Expected "${scopeName}" to be defined`);
return new NonNullType(new ListType(new NonNullType(scopeType)));
return new NonNullType(new ListType(new NonNullType(new ListType(new NonNullType(scopeType)))));
},
compositionStrategy: ARGUMENT_COMPOSITION_STRATEGIES.UNION,
}],
Expand Down

0 comments on commit 4b9a512

Please sign in to comment.