diff --git a/graphene-django/examples/starwars/schema.py b/graphene-django/examples/starwars/schema.py index 586142c0..382fec1c 100644 --- a/graphene-django/examples/starwars/schema.py +++ b/graphene-django/examples/starwars/schema.py @@ -1,6 +1,6 @@ import graphene from graphene import relay, resolve_only_args, Schema -from graphene_django import DjangoNode, DjangoObjectType +from graphene_django import DjangoObjectType from .data import (create_ship, get_empire, get_faction, get_rebels, get_ship, get_ships) @@ -15,7 +15,7 @@ class Ship(DjangoObjectType): class Meta: model = ShipModel - interfaces = (DjangoNode, ) + interfaces = (relay.Node, ) @classmethod def get_node(cls, id, context, info): @@ -34,7 +34,7 @@ class Faction(DjangoObjectType): class Meta: model = FactionModel - interfaces = (DjangoNode, ) + interfaces = (relay.Node, ) @classmethod def get_node(cls, id, context, info): @@ -62,7 +62,7 @@ class IntroduceShip(relay.ClientIDMutation): class Query(graphene.ObjectType): rebels = graphene.Field(Faction) empire = graphene.Field(Faction) - node = DjangoNode.Field() + node = relay.Node.Field() ships = relay.ConnectionField(Ship, description='All the ships.') @resolve_only_args diff --git a/graphene-django/graphene_django/__init__.py b/graphene-django/graphene_django/__init__.py index 161f5831..e999888e 100644 --- a/graphene-django/graphene_django/__init__.py +++ b/graphene-django/graphene_django/__init__.py @@ -1,10 +1,9 @@ from .types import ( DjangoObjectType, - DjangoNode ) from .fields import ( DjangoConnectionField, ) -__all__ = ['DjangoObjectType', 'DjangoNode', +__all__ = ['DjangoObjectType', 'DjangoConnectionField'] diff --git a/graphene-django/graphene_django/debug/tests/test_query.py b/graphene-django/graphene_django/debug/tests/test_query.py index 421b2d5d..87e96285 100644 --- a/graphene-django/graphene_django/debug/tests/test_query.py +++ b/graphene-django/graphene_django/debug/tests/test_query.py @@ -1,7 +1,8 @@ import pytest import graphene -from graphene_django import DjangoConnectionField, DjangoNode, DjangoObjectType +from graphene.relay import Node +from graphene_django import DjangoConnectionField, DjangoObjectType from graphene_django.utils import DJANGO_FILTER_INSTALLED from ...tests.models import Reporter @@ -27,7 +28,7 @@ def test_should_query_field(): class Meta: model = Reporter - interfaces = (DjangoNode, ) + interfaces = (Node, ) class Query(graphene.ObjectType): reporter = graphene.Field(ReporterType) @@ -74,7 +75,7 @@ def test_should_query_list(): class Meta: model = Reporter - interfaces = (DjangoNode, ) + interfaces = (Node, ) class Query(graphene.ObjectType): all_reporters = graphene.List(ReporterType) @@ -123,7 +124,7 @@ def test_should_query_connection(): class Meta: model = Reporter - interfaces = (DjangoNode, ) + interfaces = (Node, ) class Query(graphene.ObjectType): all_reporters = DjangoConnectionField(ReporterType) @@ -180,7 +181,7 @@ def test_should_query_connectionfilter(): class Meta: model = Reporter - interfaces = (DjangoNode, ) + interfaces = (Node, ) class Query(graphene.ObjectType): all_reporters = DjangoFilterConnectionField(ReporterType) diff --git a/graphene-django/graphene_django/filter/tests/test_fields.py b/graphene-django/graphene_django/filter/tests/test_fields.py index 502dbbaa..1d2fe078 100644 --- a/graphene-django/graphene_django/filter/tests/test_fields.py +++ b/graphene-django/graphene_django/filter/tests/test_fields.py @@ -3,7 +3,8 @@ from datetime import datetime import pytest from graphene import ObjectType, Schema, Field -from graphene_django import DjangoNode, DjangoObjectType +from graphene.relay import Node +from graphene_django import DjangoObjectType from graphene_django.forms import (GlobalIDFormField, GlobalIDMultipleChoiceField) from graphene_django.tests.models import Article, Pet, Reporter @@ -25,21 +26,21 @@ class ArticleNode(DjangoObjectType): class Meta: model = Article - interfaces = (DjangoNode, ) + interfaces = (Node, ) class ReporterNode(DjangoObjectType): class Meta: model = Reporter - interfaces = (DjangoNode, ) + interfaces = (Node, ) class PetNode(DjangoObjectType): class Meta: model = Pet - interfaces = (DjangoNode, ) + interfaces = (Node, ) # schema = Schema() @@ -138,7 +139,7 @@ def test_filter_filterset_information_on_meta(): class Meta: model = Reporter - interfaces = (DjangoNode, ) + interfaces = (Node, ) filter_fields = ['first_name', 'articles'] filter_order_by = True @@ -152,7 +153,7 @@ def test_filter_filterset_information_on_meta_related(): class Meta: model = Reporter - interfaces = (DjangoNode, ) + interfaces = (Node, ) filter_fields = ['first_name', 'articles'] filter_order_by = True @@ -160,7 +161,7 @@ def test_filter_filterset_information_on_meta_related(): class Meta: model = Article - interfaces = (DjangoNode, ) + interfaces = (Node, ) filter_fields = ['headline', 'reporter'] filter_order_by = True @@ -181,14 +182,14 @@ def test_filter_filterset_related_results(): class Meta: model = Reporter - interfaces = (DjangoNode, ) + interfaces = (Node, ) filter_fields = ['first_name', 'articles'] filter_order_by = True class ArticleFilterNode(DjangoObjectType): class Meta: - interfaces = (DjangoNode, ) + interfaces = (Node, ) model = Article filter_fields = ['headline', 'reporter'] filter_order_by = True diff --git a/graphene-django/graphene_django/tests/schema.py b/graphene-django/graphene_django/tests/schema.py index 1d81da27..55841498 100644 --- a/graphene-django/graphene_django/tests/schema.py +++ b/graphene-django/graphene_django/tests/schema.py @@ -1,6 +1,6 @@ import graphene -from graphene import Schema -from ..types import DjangoNode, DjangoObjectType +from graphene import Schema, relay +from ..types import DjangoObjectType from .models import Article, Reporter @@ -9,7 +9,7 @@ class Character(DjangoObjectType): class Meta: model = Reporter - interfaces = (DjangoNode, ) + interfaces = (relay.Node, ) def get_node(self, id, context, info): pass @@ -20,7 +20,7 @@ class Human(DjangoObjectType): class Meta: model = Article - interfaces = (DjangoNode, ) + interfaces = (relay.Node, ) def resolve_raises(self, *args): raise Exception("This field should raise exception") diff --git a/graphene-django/graphene_django/tests/test_converter.py b/graphene-django/graphene_django/tests/test_converter.py index 67988035..8d84f22f 100644 --- a/graphene-django/graphene_django/tests/test_converter.py +++ b/graphene-django/graphene_django/tests/test_converter.py @@ -14,7 +14,7 @@ from ..compat import (ArrayField, HStoreField, JSONField, MissingType, from ..converter import convert_django_field, convert_django_field_with_choices from ..registry import Registry from .models import Article, Reporter, Film, FilmDetails, Pet -from ..types import DjangoObjectType, DjangoNode +from ..types import DjangoObjectType def assert_conversion(django_field, graphene_field, *args, **kwargs): @@ -179,7 +179,7 @@ def test_should_manytomany_convert_connectionorlist_connection(): class A(DjangoObjectType): class Meta: model = Reporter - interfaces = (DjangoNode, ) + interfaces = (Node, ) graphene_field = convert_django_field(Reporter._meta.local_many_to_many[0], A._meta.registry) assert isinstance(graphene_field, graphene.Dynamic) diff --git a/graphene-django/graphene_django/tests/test_query.py b/graphene-django/graphene_django/tests/test_query.py index b08be7aa..7cb2055c 100644 --- a/graphene-django/graphene_django/tests/test_query.py +++ b/graphene-django/graphene_django/tests/test_query.py @@ -5,9 +5,10 @@ from django.db import models from py.test import raises import graphene +from graphene.relay import Node from ..compat import MissingType, RangeField -from ..types import DjangoNode, DjangoObjectType +from ..types import DjangoObjectType from ..registry import reset_global_registry, get_global_registry from .models import Article, Reporter @@ -119,13 +120,13 @@ def test_should_query_postgres_fields(): def test_should_node(): # reset_global_registry() - # DjangoNode._meta.registry = get_global_registry() + # Node._meta.registry = get_global_registry() class ReporterNode(DjangoObjectType): class Meta: model = Reporter - interfaces = (DjangoNode, ) + interfaces = (Node, ) @classmethod def get_node(cls, id, context, info): @@ -138,14 +139,14 @@ def test_should_node(): class Meta: model = Article - interfaces = (DjangoNode, ) + interfaces = (Node, ) @classmethod def get_node(cls, id, context, info): return Article(id=1, headline='Article node', pub_date=datetime.date(2002, 3, 11)) class Query(graphene.ObjectType): - node = DjangoNode.Field() + node = Node.Field() reporter = graphene.Field(ReporterNode) article = graphene.Field(ArticleNode) diff --git a/graphene-django/graphene_django/tests/test_types.py b/graphene-django/graphene_django/tests/test_types.py index 2c36e9e4..ecc2225b 100644 --- a/graphene-django/graphene_django/tests/test_types.py +++ b/graphene-django/graphene_django/tests/test_types.py @@ -3,7 +3,7 @@ from mock import patch from graphene import ObjectType, Field, Int, ID, Schema, Interface from graphene.relay import Node, ConnectionField -from ..types import DjangoNode, DjangoObjectType +from ..types import DjangoObjectType from .models import Article as ArticleModel, Reporter as ReporterModel from ..registry import reset_global_registry, Registry @@ -21,19 +21,19 @@ class Article(DjangoObjectType): '''Article description''' class Meta: model = ArticleModel - interfaces = (DjangoNode, ) + interfaces = (Node, ) class RootQuery(ObjectType): - node = DjangoNode.Field() + node = Node.Field() schema = Schema(query=RootQuery, types=[Article, Reporter]) def test_django_interface(): - assert issubclass(DjangoNode, Interface) - assert issubclass(DjangoNode, Node) + assert issubclass(Node, Interface) + assert issubclass(Node, Node) @patch('graphene_django.tests.models.Article.objects.get', return_value=Article(id=1)) diff --git a/graphene-django/graphene_django/types.py b/graphene-django/graphene_django/types.py index 0d0e329f..c975a550 100644 --- a/graphene-django/graphene_django/types.py +++ b/graphene-django/graphene_django/types.py @@ -1,12 +1,9 @@ from collections import OrderedDict -from functools import partial import six -from graphene import Field, Interface, ObjectType +from graphene import ObjectType from graphene.types.objecttype import ObjectTypeMeta -from graphene.relay import Node -from graphene.relay.node import NodeMeta from .converter import convert_django_field_with_choices from graphene.types.options import Options from .utils import get_model_fields, is_valid_django_model, DJANGO_FILTER_INSTALLED @@ -74,9 +71,6 @@ class DjangoObjectTypeMeta(ObjectTypeMeta): 'You need to pass a valid Django Model in {}.Meta, received "{}".' ).format(name, options.model) - # interfaces = tuple(options.interfaces) - # fields = get_fields(ObjectType, attrs, bases, interfaces) - # attrs = attrs_without_fields(attrs, fields) cls = ObjectTypeMeta.__new__(cls, name, bases, dict(attrs, _meta=options)) options.registry.register(cls) @@ -106,24 +100,3 @@ class DjangoObjectType(six.with_metaclass(DjangoObjectTypeMeta, ObjectType)): return cls._meta.model.objects.get(id=id) except cls._meta.model.DoesNotExist: return None - -DjangoNode = Node - -# class DjangoNodeMeta(DjangoObjectTypeMeta, NodeMeta): -# pass - - -# class DjangoNode(six.with_metaclass(DjangoNodeMeta, Node)): -# @classmethod -# def get_node(cls, id, context, info): -# try: -# return cls._meta.model.objects.get(id=id) -# except cls._meta.model.DoesNotExist: -# return None - - # @classmethod - # def resolve_type(cls, type, context, info): - # # We get the model from the _meta in the Django class/instance - # model = type._meta.model - # graphene_type = cls._meta.registry.get_type_for_model(model) - # return graphene_type