Skip to content

Commit 5af2895

Browse files
committed
Provide default implementation of out_type as static method.
1 parent 7bb0103 commit 5af2895

File tree

3 files changed

+18
-11
lines changed

3 files changed

+18
-11
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ a query language for APIs created by Facebook.
1313
[![Code Style](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/ambv/black)
1414

1515
The current version 1.0.5 of GraphQL-core-next is up-to-date with GraphQL.js version
16-
14.3.1. All parts of the API are covered by an extensive test suite of currently 1814
16+
14.3.1. All parts of the API are covered by an extensive test suite of currently 1817
1717
unit tests.
1818

1919

graphql/type/definition.py

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
UnionTypeExtensionNode,
4343
ValueNode,
4444
)
45-
from ..pyutils import AwaitableOrValue, cached_property, identity_func, inspect
45+
from ..pyutils import AwaitableOrValue, cached_property, inspect
4646
from ..utilities.value_from_ast_untyped import value_from_ast_untyped
4747

4848
if TYPE_CHECKING: # pragma: no cover
@@ -360,7 +360,7 @@ def __str__(self):
360360
return self.name
361361

362362
@staticmethod
363-
def serialize(value: Any):
363+
def serialize(value: Any) -> Any:
364364
"""Serializes an internal value to include in a response.
365365
366366
This default method just passes the value through and should be replaced
@@ -369,7 +369,7 @@ def serialize(value: Any):
369369
return value
370370

371371
@staticmethod
372-
def parse_value(value: Any):
372+
def parse_value(value: Any) -> Any:
373373
"""Parses an externally provided value to use as an input.
374374
375375
This default method just passes the value through and should be replaced
@@ -379,7 +379,7 @@ def parse_value(value: Any):
379379

380380
def parse_literal( # type: ignore
381381
self, node: ValueNode, _variables: Dict[str, Any] = None
382-
):
382+
) -> Any:
383383
"""Parses an externally provided literal value to use as an input.
384384
385385
This default method uses the parse_value method and should be replaced
@@ -1158,7 +1158,6 @@ class GeoPoint(GraphQLInputObjectType):
11581158
converted to other types by specifying an `out_type` function or class.
11591159
"""
11601160

1161-
out_type: GraphQLInputFieldOutType # transforms values (extension of GraphQL.js)
11621161
ast_node: Optional[InputObjectTypeDefinitionNode]
11631162
extension_ast_nodes: Optional[Tuple[InputObjectTypeExtensionNode]]
11641163

@@ -1191,15 +1190,24 @@ def __init__(
11911190
f"{name} extension AST nodes must be InputObjectTypeExtensionNode."
11921191
)
11931192
self._fields = fields
1194-
self.out_type = out_type or identity_func # type: ignore
1193+
if out_type is not None:
1194+
self.out_type = out_type
1195+
1196+
@staticmethod
1197+
def out_type(value: Dict[str, Any]) -> Any:
1198+
"""Transform outbound values (this is an extension of GraphQL.js).
1199+
1200+
This default implementation passes values unaltered as dictionaries.
1201+
"""
1202+
return value
11951203

11961204
def to_kwargs(self) -> Dict[str, Any]:
11971205
return dict(
11981206
**super().to_kwargs(),
11991207
fields=self.fields.copy(),
12001208
out_type=None
1201-
if self.out_type is identity_func # type: ignore
1202-
else self.out_type, # type: ignore
1209+
if self.out_type is GraphQLInputObjectType.out_type
1210+
else self.out_type,
12031211
)
12041212

12051213
@cached_property

tests/type/test_definition.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
from graphql.error import INVALID
66
from graphql.language import parse_value, Node, InputValueDefinitionNode
7-
from graphql.pyutils import identity_func
87
from graphql.type import (
98
GraphQLArgument,
109
GraphQLEnumValue,
@@ -489,7 +488,7 @@ def accepts_an_input_object_type_with_an_out_type_function():
489488
def provides_default_out_type_if_omitted():
490489
# This is an extension of GraphQL.js.
491490
input_obj_type = GraphQLInputObjectType("SomeInputObject", {})
492-
assert input_obj_type.out_type is identity_func
491+
assert input_obj_type.out_type is GraphQLInputObjectType.out_type
493492
assert input_obj_type.to_kwargs()["out_type"] is None
494493

495494
def rejects_an_input_object_type_with_incorrect_fields():

0 commit comments

Comments
 (0)