Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions .changeset/green-chairs-nail.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
"@apollo/composition": patch
"@apollo/federation-internals": patch
---

Include default deprecation reason in the composed supergraph

`@deprecated` reason used to be optional so if a subgraph does not specify the reason, it is omitted from the supergraph
schema. [Reason is no longer optional](https://github.com/graphql/graphql-spec/pull/1040) so we should always include it
(even if it has a default value).
2 changes: 1 addition & 1 deletion composition-js/src/__tests__/compose.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1939,7 +1939,7 @@ describe('composition', () => {
const [_, api] = schemas(result);
expect(printSchema(api)).toMatchString(`
type Query {
a: String @deprecated
a: String @deprecated(reason: "No longer supported")
b: String
}
`);
Expand Down
6 changes: 6 additions & 0 deletions internals-js/src/definitions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3260,6 +3260,12 @@ export class Directive<
const args = entries.length == 0 ? '' : '(' + entries.map(([n, v]) => `${n}: ${valueToString(v, this.argumentType(n))}`).join(', ') + ')';
return `@${this.name}${args}`;
}

toStringWithDefaultValues(): string {
const entries = Object.entries(this.arguments(true)).filter(([_, v]) => v !== undefined);
const args = entries.length == 0 ? '' : '(' + entries.map(([n, v]) => `${n}: ${valueToString(v, this.argumentType(n))}`).join(', ') + ')';
return `@${this.name}${args}`;
}
}

/**
Expand Down
9 changes: 8 additions & 1 deletion internals-js/src/print.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import {
} from "./definitions";
import { assert } from "./utils";
import { valueToString } from "./values";
import { GraphQLDeprecatedDirective } from 'graphql/type';

export type PrintOptions = {
indentString: string;
Expand Down Expand Up @@ -235,7 +236,13 @@ function printAppliedDirectives(
return "";
}
const joinStr = onNewLines ? '\n' + options.indentString : ' ';
const directives = appliedDirectives.map(d => d.toString()).join(joinStr);
const directives = appliedDirectives.map(d => {
if (GraphQLDeprecatedDirective.name === d.name) {
return d.toStringWithDefaultValues();
} else {
return d.toString();
}
}).join(joinStr);
return onNewLines ? '\n' + options.indentString + directives + (endWithNewLine ? '\n' : '') : ' ' + directives;
}

Expand Down