Improved Field args

This commit is contained in:
Syrus Akbary 2016-09-18 13:21:02 -07:00
parent 2ed800bae3
commit 8fb4214809

View File

@ -3,8 +3,9 @@ from collections import Mapping, OrderedDict
from functools import partial from functools import partial
from ..utils.orderedtype import OrderedType from ..utils.orderedtype import OrderedType
from .argument import to_arguments from .argument import Argument, to_arguments
from .structures import NonNull from .structures import NonNull
from .unmountedtype import UnmountedType
def source_resolver(source, root, args, context, info): def source_resolver(source, root, args, context, info):
@ -30,6 +31,16 @@ class Field(OrderedType):
if required: if required:
type = NonNull(type) type = NonNull(type)
# Check if name is actually an argument of the field
if isinstance(name, (Argument, UnmountedType)):
extra_args['name'] = name
name = None
# Check if source is actually an argument of the field
if isinstance(source, (Argument, UnmountedType)):
extra_args['source'] = source
source = None
self.name = name self.name = name
self._type = type self._type = type
self.args = to_arguments(args or OrderedDict(), extra_args) self.args = to_arguments(args or OrderedDict(), extra_args)