Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 6c92a65

Browse files
Add @oneOf support to introspection query (#241)
Replicates graphql/graphql-js@7df786e
1 parent eda2d30 commit 6c92a65

File tree

4 files changed

+12
-4
lines changed

4 files changed

+12
-4
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: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import re
44
from typing import Pattern
5-
65
from graphql.language import parse
76
from graphql.utilities import build_schema, get_introspection_query
87
from graphql.validation import validate
@@ -80,6 +79,11 @@ def includes_deprecation_reason_field_on_input_values():
8079
"deprecationReason", 2
8180
)
8281

82+
def includes_input_object_one_of_field():
83+
ExcpectIntrospectionQuery().to_not_match("isOneOf")
84+
ExcpectIntrospectionQuery(input_object_one_of=True).to_match("isOneOf")
85+
ExcpectIntrospectionQuery(input_object_one_of=False).to_not_match("isOneOf")
86+
8387
def includes_deprecated_input_field_and_args():
8488
ExcpectIntrospectionQuery().to_match("includeDeprecated: true", 2)
8589
ExcpectIntrospectionQuery(input_value_deprecation=True).to_match(

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /