Skip to content

Instantly share code, notes, and snippets.

@Yeboster
Forked from ssomnoremac/schema.py
Created May 1, 2018 14:43
Show Gist options
  • Save Yeboster/7ef9e79e13eb73ae4f79278c68a8debd to your computer and use it in GitHub Desktop.
Save Yeboster/7ef9e79e13eb73ae4f79278c68a8debd to your computer and use it in GitHub Desktop.
schema.py for graphene and sqlalchemy
import graphene
from graphene_sqlalchemy import SQLAlchemyConnectionField, SQLAlchemyObjectType
from models import *
class Person(SQLAlchemyObjectType):
class Meta:
model = PersonModel
interfaces = (graphene.relay.Node, )
class Article(SQLAlchemyObjectType):
class Meta:
model = ArticleModel
interfaces = (graphene.relay.Node, )
class Query(graphene.ObjectType):
node = graphene.relay.Node.Field()
person = graphene.Field(Person, uuid = graphene.Int())
def resolve_person(self, args, context, info):
query = Person.get_query(context)
uuid = args.get('uuid')
return query.get(uuid)
schema = graphene.Schema(query=Query, types=[Person])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment