Created
January 8, 2016 23:41
-
-
Save syrusakbary/65fbce1860ef204ee908 to your computer and use it in GitHub Desktop.
Gevent executor example with Graphene
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
from collections import OrderedDict | |
from graphql.core.execution.executor import Executor | |
from graphql.core.execution.middlewares.gevent import GeventExecutionMiddleware, run_in_greenlet | |
import graphene | |
class Patron(graphene.ObjectType): | |
id = graphene.ID() | |
name = graphene.String() | |
age = graphene.ID() | |
class Query(graphene.ObjectType): | |
patron = graphene.Field(Patron) | |
@run_in_greenlet | |
def resolve_patron(self, args, info): | |
return Patron(id=1, name='Demo') | |
gevent_executor = Executor([GeventExecutionMiddleware()], map_type=OrderedDict) | |
schema = graphene.Schema(query=Query, executor=gevent_executor) | |
query = ''' | |
query something{ | |
patron { | |
id | |
name | |
} | |
} | |
''' | |
result = schema.execute(query) | |
print(result.data['patron']) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment