Skip to content

Commit 66334cc

Browse files
committed
Deprecate 'is_deprecated'
Replicates graphql/graphql-js@a86ffbb
1 parent c378b69 commit 66334cc

File tree

3 files changed

+10
-8
lines changed

3 files changed

+10
-8
lines changed

src/graphql/type/definition.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -550,6 +550,7 @@ def __copy__(self) -> "GraphQLField": # pragma: no cover
550550

551551
@property
552552
def is_deprecated(self) -> bool:
553+
# this property is officially deprecated, but we still keep it here
553554
return self.deprecation_reason is not None
554555

555556

@@ -1261,6 +1262,7 @@ def __copy__(self) -> "GraphQLEnumValue": # pragma: no cover
12611262

12621263
@property
12631264
def is_deprecated(self) -> bool:
1265+
# this property is officially deprecated, but we still keep it here
12641266
return self.deprecation_reason is not None
12651267

12661268

src/graphql/type/introspection.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ def fields(type_, _info, includeDeprecated=False):
291291
if is_object_type(type_) or is_interface_type(type_):
292292
items = type_.fields.items()
293293
if not includeDeprecated:
294-
return [item for item in items if not item[1].is_deprecated]
294+
return [item for item in items if item[1].deprecation_reason is None]
295295
return list(items)
296296

297297
@staticmethod
@@ -310,7 +310,7 @@ def enum_values(type_, _info, includeDeprecated=False):
310310
if is_enum_type(type_):
311311
items = type_.values.items()
312312
if not includeDeprecated:
313-
return [item for item in items if not item[1].is_deprecated]
313+
return [item for item in items if item[1].deprecation_reason is None]
314314
return items
315315

316316
@staticmethod
@@ -344,7 +344,7 @@ def of_type(type_, _info):
344344
),
345345
"isDeprecated": GraphQLField(
346346
GraphQLNonNull(GraphQLBoolean),
347-
resolve=lambda item, _info: item[1].is_deprecated,
347+
resolve=lambda item, _info: item[1].deprecation_reason is not None,
348348
),
349349
"deprecationReason": GraphQLField(
350350
GraphQLString, resolve=lambda item, _info: item[1].deprecation_reason
@@ -415,7 +415,7 @@ def default_value(item, _info):
415415
),
416416
"isDeprecated": GraphQLField(
417417
GraphQLNonNull(GraphQLBoolean),
418-
resolve=lambda item, _info: item[1].is_deprecated,
418+
resolve=lambda item, _info: item[1].deprecation_reason is not None,
419419
),
420420
"deprecationReason": GraphQLField(
421421
GraphQLString, resolve=lambda item, _info: item[1].deprecation_reason

src/graphql/utilities/print_schema.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -258,11 +258,11 @@ def print_directive(directive: GraphQLDirective) -> str:
258258

259259

260260
def print_deprecated(field_or_enum_value: Union[GraphQLField, GraphQLEnumValue]) -> str:
261-
if not field_or_enum_value.is_deprecated:
261+
deprecation_reason = field_or_enum_value.deprecation_reason
262+
if deprecation_reason is None:
262263
return ""
263-
reason = field_or_enum_value.deprecation_reason
264-
reason_ast = ast_from_value(reason, GraphQLString)
265-
if not reason_ast or reason == DEFAULT_DEPRECATION_REASON:
264+
reason_ast = ast_from_value(deprecation_reason, GraphQLString)
265+
if not reason_ast or deprecation_reason == DEFAULT_DEPRECATION_REASON:
266266
return " @deprecated"
267267
return f" @deprecated(reason: {print_ast(reason_ast)})"
268268

0 commit comments

Comments
 (0)