graphene/graphene/utils/copy_fields.py
2016-06-14 23:48:25 -07:00

16 lines
533 B
Python

from collections import OrderedDict
from ..types.field import Field, InputField
def copy_fields(like, fields, **extra):
_fields = []
for attname, field in fields.items():
if isinstance(field, (Field, InputField)):
copy_and_extend = field.copy_and_extend
else:
copy_and_extend = like.copy_and_extend
field = copy_and_extend(field, attname=getattr(field, 'attname', None) or attname, **extra)
_fields.append(field)
return OrderedDict((f.name, f) for f in _fields)