Last active
May 1, 2017 11:21
-
-
Save syrusakbary/6cdb2597daee9922f330a05a7a08413c to your computer and use it in GitHub Desktop.
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 import relay | |
from graphene_sqlalchemy import SQLAlchemyObjectType, SQLAlchemyConnectionField | |
class Employee(SQLAlchemyObjectType): | |
class Meta: | |
model = EmployeeModel | |
interfaces = (relay.Node, ) | |
class Company(SQLAlchemyObjectType): | |
class Meta: | |
model = CompanyModel | |
interfaces = (relay.Node, ) | |
employees = SQLAlchemyConnectionField(Employee, with_name=graphene.String()) | |
def resolve_employees(self, args, context, info): | |
with_name = args.get('with_name') | |
Employee.get_query().filter(EmployeeModel.name.like('{}%'.format(with_name)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
resolve func should be like that python v2.7
def resolve_employees(self, args, context, info):
name = args.get('name')
return Employee.get_query(EmployeeModel).filter(EmployeeModel.name == name)
I hope that users use the example on https://github.com/jamesaxl/graphene-sqlalchemy/tree/master/examples/flask_sqlalchemy