Skip to content

Commit 56d772a

Browse files
committed
fix: include default deprecation reason in the composed supergraph
`@deprecated` reason used to be optional in the past and as such it was omitted from the supergraph schema. [Reason is no longer optional](graphql/graphql-spec#1040) so we should always include it (even if it is a default).
1 parent 9ef306d commit 56d772a

3 files changed

Lines changed: 18 additions & 4 deletions

File tree

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ describe('composition', () => {
5454
type T @key(fields: "k") {
5555
k: ID
5656
a: Int
57-
b: String
57+
b: String @deprecated
5858
}
5959
6060
enum E {
@@ -66,6 +66,7 @@ describe('composition', () => {
6666

6767
const result = composeAsFed2Subgraphs([subgraph1, subgraph2]);
6868
assertCompositionSuccess(result);
69+
console.log(`${result.supergraphSdl}`);
6970

7071
expect(result.supergraphSdl).toMatchString(`
7172
schema
@@ -149,7 +150,7 @@ describe('composition', () => {
149150
{
150151
k: ID
151152
a: Int @join__field(graph: SUBGRAPH2)
152-
b: String @join__field(graph: SUBGRAPH2)
153+
b: String @join__field(graph: SUBGRAPH2) @deprecated(reason: "No longer supported")
153154
}
154155
155156
union U
@@ -177,7 +178,7 @@ describe('composition', () => {
177178
type T {
178179
k: ID
179180
a: Int
180-
b: String
181+
b: String @deprecated(reason: "No longer supported")
181182
}
182183
183184
union U = S | T

internals-js/src/definitions.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3260,6 +3260,12 @@ export class Directive<
32603260
const args = entries.length == 0 ? '' : '(' + entries.map(([n, v]) => `${n}: ${valueToString(v, this.argumentType(n))}`).join(', ') + ')';
32613261
return `@${this.name}${args}`;
32623262
}
3263+
3264+
toStringWithDefaultValues(): string {
3265+
const entries = Object.entries(this.arguments(true)).filter(([_, v]) => v !== undefined);
3266+
const args = entries.length == 0 ? '' : '(' + entries.map(([n, v]) => `${n}: ${valueToString(v, this.argumentType(n))}`).join(', ') + ')';
3267+
return `@${this.name}${args}`;
3268+
}
32633269
}
32643270

32653271
/**

internals-js/src/print.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import {
2424
} from "./definitions";
2525
import { assert } from "./utils";
2626
import { valueToString } from "./values";
27+
import { GraphQLDeprecatedDirective } from 'graphql/type';
2728

2829
export type PrintOptions = {
2930
indentString: string;
@@ -235,7 +236,13 @@ function printAppliedDirectives(
235236
return "";
236237
}
237238
const joinStr = onNewLines ? '\n' + options.indentString : ' ';
238-
const directives = appliedDirectives.map(d => d.toString()).join(joinStr);
239+
const directives = appliedDirectives.map(d => {
240+
if (GraphQLDeprecatedDirective.name === d.name) {
241+
return d.toStringWithDefaultValues();
242+
} else {
243+
return d.toString();
244+
}
245+
}).join(joinStr);
239246
return onNewLines ? '\n' + options.indentString + directives + (endWithNewLine ? '\n' : '') : ' ' + directives;
240247
}
241248

0 commit comments

Comments
 (0)