Skip to content
Open
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
5 changes: 4 additions & 1 deletion gql/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,9 @@ def get_parser(with_examples: bool = False) -> ArgumentParser:
- input_value_deprecation:false to omit deprecated input fields
- specified_by_url:true
- schema_description:true
- directive_is_repeatable:true"""
- directive_is_repeatable:true
- input_object_one_of:true
"""
),
dest="schema_download",
)
Expand Down Expand Up @@ -430,6 +432,7 @@ def get_introspection_args(args: Namespace) -> Dict:
"directive_is_repeatable",
"schema_description",
"input_value_deprecation",
"input_object_one_of",
]

if args.schema_download is not None:
Expand Down
9 changes: 9 additions & 0 deletions gql/utilities/get_introspection_query_ast.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ def get_introspection_query_ast(
directive_is_repeatable: bool = False,
schema_description: bool = False,
input_value_deprecation: bool = True,
input_object_one_of: bool = False,
*,
type_recursion_level: int = 7,
) -> DocumentNode:
"""Get a query for introspection as a document using the DSL module.
Expand Down Expand Up @@ -68,6 +70,13 @@ def get_introspection_query_ast(
)
if descriptions:
fragment_FullType.select(ds.__Type.description)
if input_object_one_of:
try:
fragment_FullType.select(ds.__Type.isOneOf)
except AttributeError: # pragma: no cover
raise NotImplementedError(
"isOneOf is only supported from graphql-core version 3.3.0a7"
)
if specified_by_url:
fragment_FullType.select(ds.__Type.specifiedByURL)

Expand Down
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

tests_requires = [
"parse==1.20.2",
"packaging>=21.0",
"pytest==8.3.4",
"pytest-asyncio==0.25.3",
"pytest-console-scripts==1.4.1",
Expand Down
48 changes: 48 additions & 0 deletions tests/starwars/test_dsl.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,15 @@
NonNullTypeNode,
NullValueNode,
Undefined,
)
from graphql import __version__ as graphql_version
from graphql import (
build_ast_schema,
parse,
print_ast,
)
from graphql.utilities import get_introspection_query
from packaging import version

from gql import Client, gql
from gql.dsl import (
Expand Down Expand Up @@ -1084,6 +1088,50 @@ def test_get_introspection_query_ast(option):
)


@pytest.mark.skipif(
version.parse(graphql_version) < version.parse("3.3.0a7"),
reason="Requires graphql-core >= 3.3.0a7",
)
@pytest.mark.parametrize("option", [True, False])
def test_get_introspection_query_ast_is_one_of(option):

introspection_query = print_ast(
gql(
get_introspection_query(
input_value_deprecation=option,
)
).document
)

# Because the option does not exist yet in graphql-core,
# we add it manually here for now
if option:
introspection_query = introspection_query.replace(
"fields",
"isOneOf\n fields",
)

dsl_introspection_query = get_introspection_query_ast(
input_value_deprecation=option,
input_object_one_of=option,
type_recursion_level=9,
)

assert introspection_query == print_ast(dsl_introspection_query)


@pytest.mark.skipif(
version.parse(graphql_version) >= version.parse("3.3.0a7"),
reason="Test only for older graphql-core versions < 3.3.0a7",
)
def test_get_introspection_query_ast_is_one_of_not_implemented_yet():

with pytest.raises(NotImplementedError):
get_introspection_query_ast(
input_object_one_of=True,
)


def test_typename_aliased(ds):
query = """
hero {
Expand Down
2 changes: 2 additions & 0 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,7 @@ def test_cli_parse_schema_download(parser):
"specified_by_url:True",
"schema_description:true",
"directive_is_repeatable:true",
"input_object_one_of:true",
"--print-schema",
]
)
Expand All @@ -419,6 +420,7 @@ def test_cli_parse_schema_download(parser):
"specified_by_url": True,
"schema_description": True,
"directive_is_repeatable": True,
"input_object_one_of": True,
}

assert introspection_args == expected_args
Expand Down
Loading