mirror of
https://github.com/graphql-python/graphene.git
synced 2025-02-02 12:44:15 +03:00
Improved field overwriting in Django mapped models
This commit is contained in:
parent
cafcd89e57
commit
440a981750
|
@ -30,10 +30,12 @@ class DjangoObjectTypeMeta(ObjectTypeMeta):
|
|||
all_fields = sorted(list(cls._meta.model._meta.fields) +
|
||||
list(cls._meta.model._meta.local_many_to_many))
|
||||
all_fields += list(reverse_fields)
|
||||
already_created_fields = {f.field_name for f in cls._meta.local_fields}
|
||||
|
||||
for field in all_fields:
|
||||
is_not_in_only = only_fields and field.name not in only_fields
|
||||
is_excluded = field.name in cls._meta.exclude_fields
|
||||
is_already_created = field.name in already_created_fields
|
||||
is_excluded = field.name in cls._meta.exclude_fields or is_already_created
|
||||
if is_not_in_only or is_excluded:
|
||||
# We skip this field if we specify only_fields and is not
|
||||
# in there. Or when we excldue this field in exclude_fields
|
||||
|
|
|
@ -7,6 +7,7 @@ from graphene.relay.fields import (
|
|||
from graphene.core.fields import (
|
||||
Field,
|
||||
StringField,
|
||||
IntField
|
||||
)
|
||||
from graphql.core.type import (
|
||||
GraphQLObjectType,
|
||||
|
@ -25,16 +26,16 @@ from tests.utils import assert_equal_lists
|
|||
|
||||
|
||||
class Character(DjangoInterface):
|
||||
|
||||
'''Character description'''
|
||||
class Meta:
|
||||
model = Reporter
|
||||
|
||||
|
||||
class Human(DjangoNode):
|
||||
|
||||
'''Human description'''
|
||||
|
||||
pub_date = IntField()
|
||||
|
||||
def get_node(self, id):
|
||||
pass
|
||||
|
||||
|
@ -69,6 +70,11 @@ def test_node_idfield():
|
|||
assert isinstance(idfield, NodeIDField)
|
||||
|
||||
|
||||
def test_node_replacedfield():
|
||||
idfield = Human._meta.fields_map['pub_date']
|
||||
assert isinstance(idfield, IntField)
|
||||
|
||||
|
||||
def test_interface_resolve_type():
|
||||
resolve_type = Character.resolve_type(schema, Human(object()))
|
||||
assert isinstance(resolve_type, GraphQLObjectType)
|
||||
|
|
Loading…
Reference in New Issue
Block a user