Skip to content

Resolver Tagging #6

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
jhgg opened this issue Oct 9, 2015 · 2 comments
Closed

Resolver Tagging #6

jhgg opened this issue Oct 9, 2015 · 2 comments

Comments

@jhgg
Copy link
Member

jhgg commented Oct 9, 2015

graphql-core supports "tagging" a resolver (via core.execution.middlewares.utils) as a way to signal special handling of the resolver in an ExecutionMiddleware.

The main example is that we have GeventExecutionMiddleware. By default, this middleware does nothing when processing resolvers. But when it is given a resolver that is tagged with (@run_in_greenlet) it will spawn a greenlet to execute the resolver, and allow the executor to continue to resolve other fields concurrently.

From the tests, here's a good example (not using Graphene):

@run_in_greenlet
def resolve_a(context, *_):
    gevent.sleep(3)
    return 'resolved a'

@run_in_greenlet
def resolve_b(context, *_):
    gevent.sleep(3)
    return 'resolved b'

Type = GraphQLObjectType('Type', {
    'a': GraphQLField(GraphQLString, resolver=resolver),
    'b': GraphQLField(GraphQLString, resolver=resolver_2)
})

executor = Executor(GraphQLSchema(Type), [GeventExecutionMiddleware()])

doc = 'query Example { a, b }'
result = executor.execute(doc)
assert result.data == {'a': 'resolved a', 'b': 'resolved b'}

In this example, if each function was not tagged with @run_in_greenlet, then the execution time would be 6 seconds, as they have to run serially. However, since they are tagged, the middleware will run them concurrently, executing the query in only 3 seconds.

@jhgg
Copy link
Member Author

jhgg commented Oct 9, 2015

graphql-core also supports py3.5 asyncio, graphene's resolve functions should also support async/await in py35.

class Human(Character):
    pet = Field(Pet)

    async def resolve_pet(self, *args):
        pet = await queryPetFromSomewhereWithOwner(self.instance.id)
        return Pet(pet)

@jhgg
Copy link
Member Author

jhgg commented Oct 14, 2015

I have more testing to do with 40b88bc. I'll have an answer for you tomorrow. Was just super busy today.

p0123n pushed a commit to p0123n/graphene that referenced this issue Aug 26, 2017
…column

Convert int label column for SQLAlchemy column_property
ronachong pushed a commit to ronachong/graphene that referenced this issue Nov 3, 2017
Fixed a bug that was causing graphql_schmea command to not import properly
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant