mirror of
https://github.com/graphql-python/graphene.git
synced 2024-11-26 03:23:55 +03:00
Removed unused code
This commit is contained in:
parent
46918d3ba0
commit
76ecd895e1
|
@ -1,41 +0,0 @@
|
|||
import copy
|
||||
from .get_graphql_type import get_graphql_type
|
||||
|
||||
from ..types.field import Field, InputField
|
||||
from ..types.unmountedtype import UnmountedType
|
||||
|
||||
|
||||
def extract_fields(cls, attrs):
|
||||
fields = set()
|
||||
_fields = list()
|
||||
for attname, value in list(attrs.items()):
|
||||
is_field = isinstance(value, (Field, InputField))
|
||||
is_field_proxy = isinstance(value, UnmountedType)
|
||||
if not (is_field or is_field_proxy):
|
||||
continue
|
||||
field = value.as_mounted(cls) if is_field_proxy else copy.copy(value)
|
||||
field.attname = attname
|
||||
field.parent = cls
|
||||
fields.add(attname)
|
||||
del attrs[attname]
|
||||
_fields.append(field)
|
||||
|
||||
# All the fields are Graphene Fields or InputFields, so
|
||||
# are orderable
|
||||
return sorted(_fields)
|
||||
|
||||
|
||||
def get_base_fields(cls, bases):
|
||||
fields = set()
|
||||
_fields = list()
|
||||
for _class in bases:
|
||||
for attname, field in get_graphql_type(_class).get_fields().items():
|
||||
if attname in fields:
|
||||
continue
|
||||
field = copy.copy(field)
|
||||
if isinstance(field, (Field, InputField)):
|
||||
field.parent = cls
|
||||
fields.add(attname)
|
||||
_fields.append(field)
|
||||
|
||||
return _fields
|
|
@ -1,11 +1,11 @@
|
|||
from collections import OrderedDict
|
||||
from graphql import GraphQLField, GraphQLString, GraphQLInterfaceType, GraphQLInt, GraphQLFloat
|
||||
from ..extract_fields import extract_fields, get_base_fields
|
||||
from ..get_fields import get_fields_from_attrs, get_fields_from_types
|
||||
|
||||
from ...types import Field, String, Argument, ObjectType
|
||||
|
||||
|
||||
def test_extract_fields_attrs():
|
||||
def test_get_fields_from_attrs():
|
||||
attrs = {
|
||||
'field_string': Field(String),
|
||||
'string': String(),
|
||||
|
@ -13,27 +13,26 @@ def test_extract_fields_attrs():
|
|||
'argument': Argument(String),
|
||||
'graphql_field': GraphQLField(GraphQLString)
|
||||
}
|
||||
extracted_fields = list(extract_fields(ObjectType, attrs))
|
||||
assert [f.name for f in extracted_fields] == ['fieldString', 'string']
|
||||
assert sorted(attrs.keys()) == ['argument', 'graphql_field', 'other']
|
||||
extracted_fields = OrderedDict(get_fields_from_attrs(ObjectType, attrs))
|
||||
assert [f for f in extracted_fields.keys()] == ['field_string', 'string']
|
||||
|
||||
|
||||
def test_extract_fields():
|
||||
def test_get_fields_from_types():
|
||||
int_base = GraphQLInterfaceType('IntInterface', fields=OrderedDict([
|
||||
('int', GraphQLField(GraphQLInt)),
|
||||
('num', GraphQLField(GraphQLInt)),
|
||||
('extra', GraphQLField(GraphQLInt))
|
||||
]))
|
||||
float_base = GraphQLInterfaceType('IntInterface', fields=OrderedDict([
|
||||
float_base = GraphQLInterfaceType('FloatInterface', fields=OrderedDict([
|
||||
('float', GraphQLField(GraphQLFloat)),
|
||||
('num', GraphQLField(GraphQLFloat)),
|
||||
('extra', GraphQLField(GraphQLFloat))
|
||||
]))
|
||||
|
||||
bases = (int_base, float_base)
|
||||
base_fields = list(get_base_fields(ObjectType, bases))
|
||||
assert [f.name for f in base_fields] == ['int', 'num', 'extra', 'float']
|
||||
assert [f.type for f in base_fields] == [
|
||||
base_fields = OrderedDict(get_fields_from_types(bases))
|
||||
assert [f for f in base_fields.keys()] == ['int', 'num', 'extra', 'float']
|
||||
assert [f.type for f in base_fields.values()] == [
|
||||
GraphQLInt,
|
||||
GraphQLInt,
|
||||
GraphQLInt,
|
Loading…
Reference in New Issue
Block a user