Skip to content

Commit 7799ad1

Browse files
authored
fix: make composeDirective argument non-nullable (#3278)
Per our [docs](https://www.apollographql.com/docs/graphos/schema-design/federated-schemas/reference/directives#composedirective), `@composeDirective` requires non-nullable value to be passed as an argument. Our [validations](https://github.com/apollographql/federation/blob/main/composition-js/src/composeDirectiveManager.ts#L250-L255) were checking for valid values (it has to be a string that starts with `@`), but the generated schema was incorrectly specifying that the argument was nullable.
1 parent 31104c6 commit 7799ad1

File tree

3 files changed

+15
-4
lines changed

3 files changed

+15
-4
lines changed

.changeset/cool-roses-explode.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
---
2+
"@apollo/federation-internals": patch
3+
---
4+
5+
fix: make composeDirective argument non-nullable.
6+
7+
Per our [docs](https://www.apollographql.com/docs/graphos/schema-design/federated-schemas/reference/directives#composedirective),
8+
`@composeDirective` requires non-nullable value to be passed as an argument.
9+
10+
Our [validations](https://github.com/apollographql/federation/blob/main/composition-js/src/composeDirectiveManager.ts#L250-L255) were checking for valid values (it has to be a string that starts with `@`),
11+
but the generated schema was incorrectly specifying that the argument was nullable.

internals-js/src/specs/federationSpec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ export class FederationSpecDefinition extends FeatureDefinition {
153153
name: FederationDirectiveName.COMPOSE_DIRECTIVE,
154154
locations: [DirectiveLocation.SCHEMA],
155155
repeatable: true,
156-
args: [{ name: 'name', type: (schema) => schema.stringType() }],
156+
args: [{ name: 'name', type: (schema) => new NonNullType(schema.stringType()) }],
157157
}));
158158
}
159159

subgraph-js/src/__tests__/buildSubgraphSchema.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1349,7 +1349,7 @@ describe('buildSubgraphSchema', () => {
13491349
13501350
directive @federation__override(from: String!) on FIELD_DEFINITION
13511351
1352-
directive @federation__composeDirective(name: String) repeatable on SCHEMA
1352+
directive @federation__composeDirective(name: String!) repeatable on SCHEMA
13531353
13541354
type Query {
13551355
x: Int
@@ -1416,7 +1416,7 @@ describe('buildSubgraphSchema', () => {
14161416
14171417
directive @federation__override(from: String!) on FIELD_DEFINITION
14181418
1419-
directive @federation__composeDirective(name: String) repeatable on SCHEMA
1419+
directive @federation__composeDirective(name: String!) repeatable on SCHEMA
14201420
14211421
type Query {
14221422
x: Int
@@ -1484,7 +1484,7 @@ describe('buildSubgraphSchema', () => {
14841484
14851485
directive @federation__override(from: String!) on FIELD_DEFINITION
14861486
1487-
directive @federation__composeDirective(name: String) repeatable on SCHEMA
1487+
directive @federation__composeDirective(name: String!) repeatable on SCHEMA
14881488
14891489
directive @federation__interfaceObject on OBJECT
14901490

0 commit comments

Comments
 (0)