Skip to content

relay.NodeField does not propagate arguments to Field #1035

Closed
@tdiam

Description

@tdiam

The current implementation of NodeField's constructor does not propagate name, deprecation_reason or **kwargs to its parent Field constructor.
This would be useful, for example, when the field has a name that is reserved in Python:

klass = Node.Field(name='class', ...)

Is this expected behavior or is a fix needed?

Test code
from graphene import Node, ObjectType, Schema, String

droids = {1: {'name': 'R2-D2'}}

class DroidNode(ObjectType):
    class Meta:
        interfaces = (Node,)

    name = String()

    @classmethod
    def get_node(cls, info, id):
        return DroidNode(**droids[id])

class Query(ObjectType):
    droid = Node.Field(DroidNode, name='robot')

schema = Schema(query=Query)


def test_field_name_is_robot():
    r = schema.execute(
        """
        {
            __type(name: "Query") {
                fields { name }
            }
        }
        """
    )
    assert r.data['__type']['fields'][0]['name'] == 'robot'

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions