Skip to content

Commit

Permalink
Adding the input_value_deprecation argument to get_introspection_quer…
Browse files Browse the repository at this point in the history
…y_ast (#524)
  • Loading branch information
leszekhanusz authored Jan 27, 2025
1 parent 8dd458c commit 38e64b2
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
20 changes: 17 additions & 3 deletions gql/utilities/get_introspection_query_ast.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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)
Expand All @@ -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,
Expand All @@ -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),
Expand All @@ -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,
Expand Down
2 changes: 2 additions & 0 deletions tests/starwars/test_dsl.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 38e64b2

Please sign in to comment.