From 900354837e28dac73aeeeccb2c6fccbcacedfd5e Mon Sep 17 00:00:00 2001 From: Morgante Pell Date: Thu, 13 Oct 2016 02:52:58 -0400 Subject: [PATCH] Fix id lookup to handle cases where the primary key of the Django model is not called ID --- graphene_django/types.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/graphene_django/types.py b/graphene_django/types.py index ef464d1..190088a 100644 --- a/graphene_django/types.py +++ b/graphene_django/types.py @@ -98,6 +98,9 @@ class DjangoObjectTypeMeta(ObjectTypeMeta): class DjangoObjectType(six.with_metaclass(DjangoObjectTypeMeta, ObjectType)): + def resolve_id(self, args, context, info): + return self.pk + @classmethod def is_type_of(cls, root, context, info): if isinstance(root, cls): @@ -112,6 +115,6 @@ class DjangoObjectType(six.with_metaclass(DjangoObjectTypeMeta, ObjectType)): @classmethod def get_node(cls, id, context, info): try: - return cls._meta.model.objects.get(id=id) + return cls._meta.model.objects.get(pk=id) except cls._meta.model.DoesNotExist: return None