Skip to content

Commit 796d231

Browse files
committed
Simplify print_schema directive printing
Replicates graphql/graphql-js@98dcac3
1 parent ba50fb8 commit 796d231

File tree

1 file changed

+6
-12
lines changed

1 file changed

+6
-12
lines changed

src/graphql/utilities/print_schema.py

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from typing import Any, Callable, Dict, List, Optional, Union, cast
22

3-
from ..language import print_ast
3+
from ..language import print_ast, StringValueNode
44
from ..language.block_string import print_block_string
55
from ..pyutils import inspect
66
from ..type import (
@@ -16,7 +16,6 @@
1616
GraphQLObjectType,
1717
GraphQLScalarType,
1818
GraphQLSchema,
19-
GraphQLString,
2019
GraphQLUnionType,
2120
is_enum_type,
2221
is_input_object_type,
@@ -258,22 +257,17 @@ def print_directive(directive: GraphQLDirective) -> str:
258257
def print_deprecated(reason: Optional[str]) -> str:
259258
if reason is None:
260259
return ""
261-
reason_ast = ast_from_value(reason, GraphQLString)
262-
if reason_ast and reason != DEFAULT_DEPRECATION_REASON:
263-
return f" @deprecated(reason: {print_ast(reason_ast)})"
260+
if reason != DEFAULT_DEPRECATION_REASON:
261+
ast_value = print_ast(StringValueNode(value=reason))
262+
return f" @deprecated(reason: {ast_value})"
264263
return " @deprecated"
265264

266265

267266
def print_specified_by_url(scalar: GraphQLScalarType) -> str:
268267
if scalar.specified_by_url is None:
269268
return ""
270-
url = scalar.specified_by_url
271-
url_ast = ast_from_value(url, GraphQLString)
272-
if not url_ast: # pragma: no cover
273-
raise TypeError(
274-
"Unexpected null value returned from `ast_from_value` for specifiedByURL."
275-
)
276-
return f" @specifiedBy(url: {print_ast(url_ast)})"
269+
ast_value = print_ast(StringValueNode(value=scalar.specified_by_url))
270+
return f" @specifiedBy(url: {ast_value})"
277271

278272

279273
def print_description(

0 commit comments

Comments
 (0)