10000 Adding the input_value_deprecation option to get_introspection_query_ast by leszekhanusz · Pull Request #524 · graphql-python/gql · GitHub
[go: up one dir, main page]

Skip to content

Adding the input_value_deprecation option to get_introspection_query_ast #524

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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),
8000 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
Loading
0