Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Preserve @deprecated when reason = null #4006

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/utilities/__tests__/buildClientSchema-test.ts
Expand Up @@ -382,15 +382,15 @@ describe('Type System: build schema from introspection', () => {
name: 'VEGETABLES',
description: 'Foods that are vegetables.',
value: 'VEGETABLES',
deprecationReason: null,
deprecationReason: undefined,
extensions: {},
astNode: undefined,
},
{
name: 'FRUITS',
description: null,
value: 'FRUITS',
deprecationReason: null,
deprecationReason: undefined,
extensions: {},
astNode: undefined,
},
Expand Down
9 changes: 9 additions & 0 deletions src/utilities/__tests__/printSchema-test.ts
Expand Up @@ -591,6 +591,15 @@ describe('Type System Printer', () => {
`);
});

it('Prints deprecated directives with explicitly `null` reason', () => {
const SDL = dedent`
type Query {
someField: String @deprecated(reason: null)
}`;
const schema = buildSchema(SDL);
expectPrintedSchema(schema).to.equal(SDL);
});

it('Prints custom directives', () => {
const SimpleDirective = new GraphQLDirective({
name: 'simpleDirective',
Expand Down
12 changes: 9 additions & 3 deletions src/utilities/buildClientSchema.ts
Expand Up @@ -292,7 +292,9 @@ export function buildClientSchema(
(valueIntrospection) => valueIntrospection.name,
(valueIntrospection) => ({
description: valueIntrospection.description,
deprecationReason: valueIntrospection.deprecationReason,
deprecationReason: valueIntrospection.isDeprecated
? valueIntrospection.deprecationReason
: undefined,
}),
),
});
Expand Down Expand Up @@ -350,7 +352,9 @@ export function buildClientSchema(

return {
description: fieldIntrospection.description,
deprecationReason: fieldIntrospection.deprecationReason,
deprecationReason: fieldIntrospection.isDeprecated
? fieldIntrospection.deprecationReason
: undefined,
type,
args: buildInputValueDefMap(fieldIntrospection.args),
};
Expand Down Expand Up @@ -383,7 +387,9 @@ export function buildClientSchema(
description: inputValueIntrospection.description,
type,
defaultValue,
deprecationReason: inputValueIntrospection.deprecationReason,
deprecationReason: inputValueIntrospection.isDeprecated
? inputValueIntrospection.deprecationReason
: undefined,
};
}

Expand Down
8 changes: 6 additions & 2 deletions src/utilities/printSchema.ts
Expand Up @@ -282,11 +282,15 @@ export function printDirective(directive: GraphQLDirective): string {
}

function printDeprecated(reason: Maybe<string>): string {
if (reason == null) {
if (reason === undefined) {
return '';
}
if (reason !== DEFAULT_DEPRECATION_REASON) {
const astValue = print({ kind: Kind.STRING, value: reason });
const astValue = print(
reason === null
? { kind: Kind.NULL }
: { kind: Kind.STRING, value: reason },
);
return ` @deprecated(reason: ${astValue})`;
}
return ' @deprecated';
Expand Down