Skip to content

Instantly share code, notes, and snippets.

@bicknest
Created May 7, 2020 18:04
Show Gist options
  • Save bicknest/f1503b31a34cb4bc66bb1eb927d10398 to your computer and use it in GitHub Desktop.
Save bicknest/f1503b31a34cb4bc66bb1eb927d10398 to your computer and use it in GitHub Desktop.
Exposing Django models as GraphQL types
import graphene
from graphene_django.types import DjangoObjectType
import core.models
class Profile(DjangoObjectType):
class Meta:
model = core.models.Profile
interfaces = (graphene.relay.Node,)
class Business(DjangoObjectType):
class Meta:
model = core.models.Business
interfaces = (graphene.relay.Node,)
class Query(object):
profile = graphene.Field(Profile, id=graphene.ID(required=False), pk=graphene.Int(required=False))
business = graphene.Field(Business, id=graphene.ID(required=False), pk=graphene.Int(required=False))
node = graphene.relay.Node.Field()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment