diff --git a/graphene/core/types/field.py b/graphene/core/types/field.py index f6c55edb..17fc9fa2 100644 --- a/graphene/core/types/field.py +++ b/graphene/core/types/field.py @@ -8,8 +8,8 @@ from ..classtypes.base import FieldsClassType from ..classtypes.inputobjecttype import InputObjectType from ..classtypes.mutation import Mutation from ..exceptions import SkipField -from .argument import ArgumentsGroup, snake_case_args -from .base import GroupNamedType, LazyType, MountType, NamedType, OrderedType +from .argument import Argument, ArgumentsGroup, snake_case_args +from .base import GroupNamedType, LazyType, MountType, NamedType, ArgumentType, OrderedType from .definitions import NonNull @@ -19,6 +19,9 @@ class Field(NamedType, OrderedType): self, type, description=None, args=None, name=None, resolver=None, required=False, default=None, *args_list, **kwargs): _creation_counter = kwargs.pop('_creation_counter', None) + if isinstance(name, (Argument, ArgumentType)): + kwargs['name'] = name + name = None super(Field, self).__init__(name=name, _creation_counter=_creation_counter) if isinstance(type, six.string_types): type = LazyType(type) diff --git a/graphene/core/types/tests/test_field.py b/graphene/core/types/tests/test_field.py index dd30e556..2b1f7e40 100644 --- a/graphene/core/types/tests/test_field.py +++ b/graphene/core/types/tests/test_field.py @@ -104,6 +104,14 @@ def test_field_custom_arguments(): assert 'p' in schema.T(args) +def test_field_name_as_argument(): + field = Field(None, name=String()) + schema = Schema() + + args = field.arguments + assert 'name' in schema.T(args) + + def test_inputfield_internal_type(): field = InputField(String, description='My input field', default='3')