Created
May 7, 2020 18:04
-
-
Save bicknest/f1503b31a34cb4bc66bb1eb927d10398 to your computer and use it in GitHub Desktop.
Exposing Django models as GraphQL types
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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