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 133a641
Showing 1 changed file with 6 additions and 13 deletions.
19 changes: 6 additions & 13 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 All @@ -32,8 +32,6 @@ import {
isInputObjectType,
} from '../type/definition';

import { astFromValue } from './astFromValue';

export function printSchema(schema: GraphQLSchema): string {
return printFilteredSchema(
schema,
Expand Down Expand Up @@ -282,9 +280,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 +291,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 133a641

Please sign in to comment.