Get rid of memoize in all field definitions. Improved #15

This commit is contained in:
Syrus Akbary 2015-10-25 20:09:53 -07:00
parent 842103d8f7
commit 7d5987742a
4 changed files with 2 additions and 18 deletions

View File

@ -4,9 +4,7 @@ from graphene.core.fields import (
from graphene import relay
from graphene.core.fields import Field, LazyField
from graphene.utils import cached_property, memoize, LazyMap
from graphene.relay.types import BaseNode
from graphene.relay.utils import is_node
from graphene.contrib.django.utils import get_type_for_model, lazy_map
@ -25,7 +23,6 @@ class LazyListField(ListField):
class ConnectionOrListField(LazyField):
@memoize
def get_field(self, schema):
model_field = self.field_type
field_object_type = model_field.get_object_type(schema)
@ -52,7 +49,6 @@ class DjangoModelField(Field):
))
return _type(resolved)
@memoize
def internal_type(self, schema):
_type = self.get_object_type(schema)
if not _type and self.object_type._meta.only_fields:

View File

@ -2,10 +2,9 @@ from django.db import models
from django.db.models.query import QuerySet
from django.db.models.manager import Manager
from graphene.utils import memoize, LazyMap
from graphene.utils import LazyMap
# @memoize
def get_type_for_model(schema, model):
schema = schema
types = schema.types.values()

View File

@ -12,7 +12,7 @@ from graphql.core.type import (
GraphQLArgument,
GraphQLFloat,
)
from graphene.utils import memoize, to_camel_case
from graphene.utils import to_camel_case
from graphene.core.types import BaseObjectType
from graphene.core.scalars import GraphQLSkipField
@ -57,7 +57,6 @@ class Field(object):
else:
return getattr(instance, self.field_name, None)
@memoize
def get_resolve_fn(self):
if self.resolve_fn:
return self.resolve_fn
@ -103,7 +102,6 @@ class Field(object):
field_type = self.type_wrapper(field_type)
return field_type
@memoize
def internal_field(self, schema):
if not self.object_type:
raise Exception(
@ -193,18 +191,15 @@ class NativeField(Field):
def get_field(self, schema):
return self.field
@memoize
def internal_field(self, schema):
return self.get_field(schema)
@memoize
def internal_type(self, schema):
return self.internal_field(schema).type
class LazyField(Field):
@memoize
def inner_field(self, schema):
return self.get_field(schema)
@ -224,11 +219,9 @@ class LazyNativeField(NativeField):
raise NotImplementedError(
"get_field function not implemented for %s LazyField" % self.__class__)
@memoize
def internal_field(self, schema):
return self.get_field(schema)
@memoize
def internal_type(self, schema):
return self.internal_field(schema).type

View File

@ -16,7 +16,6 @@ from graphql.core.type import (
)
from graphene.core.fields import Field, IDField
from graphene.utils import memoize
class ConnectionField(Field):
@ -51,17 +50,14 @@ class ConnectionField(Field):
connection.set_connection_data(resolved)
return connection
@memoize
def get_connection_type(self, node):
connection_type = self.connection_type or node.get_connection_type()
edge_type = self.get_edge_type(node)
return connection_type.for_node(node, edge_type=edge_type)
@memoize
def get_edge_type(self, node):
return self.edge_type or node.get_edge_type()
@memoize
def internal_type(self, schema):
from graphene.relay.utils import is_node
node = self.get_object_type(schema)