Skip to content

Commit 04496e1

Browse files
committed
feat: show @oneOf in introspection query
1 parent fa8f9b5 commit 04496e1

File tree

4 files changed

+14
-3
lines changed

4 files changed

+14
-3
lines changed

src/graphql/utilities/build_client_schema.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,7 @@ def build_input_object_def(
256256
fields=lambda: build_input_value_def_map(
257257
input_object_introspection["inputFields"]
258258
),
259+
is_one_of= input_object_introspection.get("isOneOf"),
259260
)
260261

261262
type_builders: dict[str, Callable[[IntrospectionType], GraphQLNamedType]] = {

src/graphql/utilities/get_introspection_query.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
except ImportError: # Python < 3.10
1818
from typing_extensions import TypeAlias
1919

20-
2120
__all__ = [
2221
"IntrospectionDirective",
2322
"IntrospectionEnumType",
@@ -44,6 +43,7 @@ def get_introspection_query(
4443
directive_is_repeatable: bool = False,
4544
schema_description: bool = False,
4645
input_value_deprecation: bool = False,
46+
input_object_one_of: bool = False,
4747
) -> str:
4848
"""Get a query for introspection.
4949
@@ -55,6 +55,7 @@ def get_introspection_query(
5555
maybe_specified_by_url = "specifiedByURL" if specified_by_url else ""
5656
maybe_directive_is_repeatable = "isRepeatable" if directive_is_repeatable else ""
5757
maybe_schema_description = maybe_description if schema_description else ""
58+
maybe_input_object_one_of = 'isOneOf' if input_object_one_of else "";
5859

5960
def input_deprecation(string: str) -> str | None:
6061
return string if input_value_deprecation else ""
@@ -87,6 +88,7 @@ def input_deprecation(string: str) -> str | None:
8788
name
8889
{maybe_description}
8990
{maybe_specified_by_url}
91+
{maybe_input_object_one_of}
9092
fields(includeDeprecated: true) {{
9193
name
9294
{maybe_description}
@@ -253,6 +255,7 @@ class IntrospectionEnumType(WithName):
253255
class IntrospectionInputObjectType(WithName):
254256
kind: Literal["input_object"]
255257
inputFields: list[IntrospectionInputValue]
258+
isOneOf: bool
256259

257260

258261
IntrospectionType: TypeAlias = Union[
@@ -264,7 +267,6 @@ class IntrospectionInputObjectType(WithName):
264267
IntrospectionInputObjectType,
265268
]
266269

267-
268270
IntrospectionOutputType: TypeAlias = Union[
269271
IntrospectionScalarType,
270272
IntrospectionObjectType,
@@ -273,7 +275,6 @@ class IntrospectionInputObjectType(WithName):
273275
IntrospectionEnumType,
274276
]
275277

276-
277278
IntrospectionInputType: TypeAlias = Union[
278279
IntrospectionScalarType, IntrospectionEnumType, IntrospectionInputObjectType
279280
]

src/graphql/utilities/introspection_from_schema.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ def introspection_from_schema(
2121
directive_is_repeatable: bool = True,
2222
schema_description: bool = True,
2323
input_value_deprecation: bool = True,
24+
input_object_one_of: bool = True,
2425
) -> IntrospectionQuery:
2526
"""Build an IntrospectionQuery from a GraphQLSchema
2627
@@ -37,6 +38,7 @@ def introspection_from_schema(
3738
directive_is_repeatable,
3839
schema_description,
3940
input_value_deprecation,
41+
input_object_one_of,
4042
)
4143
)
4244

tests/utilities/test_get_introspection_query.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
import re
44
from typing import Pattern
55

6+
from wheel.macosx_libfile import version_min_command_fields
7+
68
from graphql.language import parse
79
from graphql.utilities import build_schema, get_introspection_query
810
from graphql.validation import validate
@@ -80,6 +82,11 @@ def includes_deprecation_reason_field_on_input_values():
8082
"deprecationReason", 2
8183
)
8284

85+
def includes_input_object_one_of_field():
86+
ExcpectIntrospectionQuery().to_not_match("isOneOf")
87+
ExcpectIntrospectionQuery(input_object_one_of=True).to_match("isOneOf")
88+
ExcpectIntrospectionQuery(input_object_one_of=False).to_not_match("isOneOf")
89+
8390
def includes_deprecated_input_field_and_args():
8491
ExcpectIntrospectionQuery().to_match("includeDeprecated: true", 2)
8592
ExcpectIntrospectionQuery(input_value_deprecation=True).to_match(

0 commit comments

Comments
 (0)