Propagate arguments of relay.NodeField to Field (#1036)

* Propagate name, deprecation_reason arguments of relay.NodeField to Field

* Allow custom description in Node.Field and move ID description to ID argument

* Add test for Node.Field with custom name

* Add tests for description, deprecation_reason arguments of NodeField

* Pass all kwargs from NodeField to Field
This commit is contained in:
Theodore Diamantidis 2019-09-27 11:54:46 +03:00 committed by Jonathan Kim
parent a3b215d891
commit 7c7876d37c
2 changed files with 14 additions and 3 deletions

View File

@ -47,7 +47,7 @@ class GlobalID(Field):
class NodeField(Field):
def __init__(self, node, type=False, deprecation_reason=None, name=None, **kwargs):
def __init__(self, node, type=False, **kwargs):
assert issubclass(node, Node), "NodeField can only operate in Nodes"
self.node_type = node
self.field_type = type
@ -56,8 +56,8 @@ class NodeField(Field):
# If we don's specify a type, the field type will be the node
# interface
type or node,
description="The ID of the object",
id=ID(required=True),
id=ID(required=True, description="The ID of the object"),
**kwargs
)
def get_resolver(self, parent_resolver):

View File

@ -106,6 +106,17 @@ def test_node_field_custom():
assert node_field.node_type == Node
def test_node_field_args():
field_args = {
"name": "my_custom_name",
"description": "my_custom_description",
"deprecation_reason": "my_custom_deprecation_reason",
}
node_field = Node.Field(**field_args)
for field_arg, value in field_args.items():
assert getattr(node_field, field_arg) == value
def test_node_field_only_type():
executed = schema.execute(
'{ onlyNode(id:"%s") { __typename, name } } ' % Node.to_global_id("MyNode", 1)