diff --git a/gql/utilities/get_introspection_query_ast.py b/gql/utilities/get_introspection_query_ast.py index d35a2a75..975ccc83 100644 --- a/gql/utilities/get_introspection_query_ast.py +++ b/gql/utilities/get_introspection_query_ast.py @@ -10,6 +10,7 @@ def get_introspection_query_ast( specified_by_url: bool = False, directive_is_repeatable: bool = False, schema_description: bool = False, + input_value_deprecation: bool = False, type_recursion_level: int = 7, ) -> DocumentNode: """Get a query for introspection as a document using the DSL module. @@ -43,13 +44,20 @@ def get_introspection_query_ast( directives = ds.__Schema.directives.select(ds.__Directive.name) + deprecated_expand = {} + + if input_value_deprecation: + deprecated_expand = { + "includeDeprecated": True, + } + if descriptions: directives.select(ds.__Directive.description) if directive_is_repeatable: directives.select(ds.__Directive.isRepeatable) directives.select( ds.__Directive.locations, - ds.__Directive.args.select(fragment_InputValue), + ds.__Directive.args(**deprecated_expand).select(fragment_InputValue), ) schema.select(directives) @@ -69,7 +77,7 @@ def get_introspection_query_ast( fields.select(ds.__Field.description) fields.select( - ds.__Field.args.select(fragment_InputValue), + ds.__Field.args(**deprecated_expand).select(fragment_InputValue), ds.__Field.type.select(fragment_TypeRef), ds.__Field.isDeprecated, ds.__Field.deprecationReason, @@ -89,7 +97,7 @@ def get_introspection_query_ast( fragment_FullType.select( fields, - ds.__Type.inputFields.select(fragment_InputValue), + ds.__Type.inputFields(**deprecated_expand).select(fragment_InputValue), ds.__Type.interfaces.select(fragment_TypeRef), enum_values, ds.__Type.possibleTypes.select(fragment_TypeRef), @@ -105,6 +113,12 @@ def get_introspection_query_ast( ds.__InputValue.defaultValue, ) + if input_value_deprecation: + fragment_InputValue.select( + ds.__InputValue.isDeprecated, + ds.__InputValue.deprecationReason, + ) + fragment_TypeRef.select( ds.__Type.kind, ds.__Type.name, diff --git a/tests/starwars/test_dsl.py b/tests/starwars/test_dsl.py index 2aadf92f..1aa1efa2 100644 --- a/tests/starwars/test_dsl.py +++ b/tests/starwars/test_dsl.py @@ -984,12 +984,14 @@ def test_get_introspection_query_ast(option): specified_by_url=option, directive_is_repeatable=option, schema_description=option, + input_value_deprecation=option, ) dsl_introspection_query = get_introspection_query_ast( descriptions=option, specified_by_url=option, directive_is_repeatable=option, schema_description=option, + input_value_deprecation=option, ) assert print_ast(gql(introspection_query)) == print_ast(dsl_introspection_query)