Skip to content

Commit

Permalink
Simplify printSchema directive printing
Browse files Browse the repository at this point in the history
  • Loading branch information
leebyron committed May 10, 2021
1 parent 78d5f83 commit 693ff9d
Showing 1 changed file with 6 additions and 11 deletions.
17 changes: 6 additions & 11 deletions src/utilities/printSchema.js
Expand Up @@ -18,7 +18,7 @@ import type {
GraphQLInputObjectType,
} from '../type/definition';
import { isIntrospectionType } from '../type/introspection';
import { GraphQLString, isSpecifiedScalarType } from '../type/scalars';
import { isSpecifiedScalarType } from '../type/scalars';
import {
DEFAULT_DEPRECATION_REASON,
isSpecifiedDirective,
Expand Down Expand Up @@ -282,9 +282,9 @@ function printDeprecated(reason: ?string): string {
if (reason == null) {
return '';
}
const reasonAST = astFromValue(reason, GraphQLString);
if (reasonAST && reason !== DEFAULT_DEPRECATION_REASON) {
return ' @deprecated(reason: ' + print(reasonAST) + ')';
if (reason !== DEFAULT_DEPRECATION_REASON) {
const astValue = print({ kind: 'StringValue', value: reason });
return ` @deprecated(reason: ${astValue})`;
}
return ' @deprecated';
}
Expand All @@ -293,13 +293,8 @@ function printSpecifiedByURL(scalar: GraphQLScalarType): string {
if (scalar.specifiedByURL == null) {
return '';
}
const url = scalar.specifiedByURL;
const urlAST = astFromValue(url, GraphQLString);
invariant(
urlAST,
'Unexpected null value returned from `astFromValue` for specifiedByURL',
);
return ' @specifiedBy(url: ' + print(urlAST) + ')';
const astValue = print({ kind: 'StringValue', value: scalar.specifiedByURL });
return ` @specifiedBy(url: ${astValue})`;
}

function printDescription(
Expand Down

0 comments on commit 693ff9d

Please sign in to comment.