Skip to content

Async schema does not return observable #452

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
japrogramer opened this issue Jun 10, 2018 · 6 comments
Closed

Async schema does not return observable #452

japrogramer opened this issue Jun 10, 2018 · 6 comments

Comments

@japrogramer
Copy link

japrogramer commented Jun 10, 2018

Here i am trying to run an async schema

            # stream is an rx.Subject
            result = graphql(schema,
                    payload['query'],
                    variable_values=payload['variables'],
                    root_value=stream.share(),
                    allow_subscriptions=True,
                    executor=AsyncioExecutor(loop=asyncio.get_event_loop()),
                    **{'context_value': message})

Here is the schema

class ProductSubscritption(object):

    """test"""
    sub_product = graphene.Field(
        ProductType,
        description='subscribe to updated product',
        product=graphene.ID())

    async def resolve_sub_product(self, info, **input):
        def next(message, info, **input):
            # here the message comes from the stream but the info and **input come frome
            # subscribing to the next method to the stream
            __import__('pdb').set_trace()
            inst = relay.Node.get_node_from_global_id(info, input.get('product'))
            return inst

        await make_sub(info, input.get('product'))
        name = ProductType._meta.model.__class__.__name__

        stream = info.root_value
        obv = stream.map(lambda message: next(message, info, **input))
        register = info.context['register']
        if register:
            __import__('pdb').set_trace()
            register(obv)
        return obv

And here is the value of result

(Pdb) result
<graphql.execution.base.ExecutionResult object at 0x7f1f08114168>
(Pdb) result.errors
[RuntimeError('This event loop is already running',)]
(Pdb) result.data
(Pdb)

I know that despite the error in result the schema continues in the background because of the brake points I have set.

@colanconnon
Copy link

colanconnon commented Jun 10, 2018

Are you using the django channels backend for subscriptions? If so what version of django channels are you using?

@japrogramer
Copy link
Author

japrogramer commented Jun 10, 2018

@colanconnon yes I am,
channels==2.1.1
channels-redis==2.2.1

Django==2.1a1
django-allauth==0.32.0
django-appconf==1.0.2
django-braces==1.11.0
django-channels-panel==0.0.5
django-coverage-plugin==1.5.0
django-crispy-forms==1.7.2
django-debug-toolbar==1.8
django-extensions==1.7.9
django-model-utils==3.0.0
django-redis==4.9.0
django-test-plus==1.0.22
graphene-django==2.1rc1
pytest-django==3.1.2

@japrogramer
Copy link
Author

I don't think it's channels related, I believe that the async await section raizes a non fatal error that graphene captures than return that as a result while the query continues to execute in the background

@japrogramer
Copy link
Author

I managed to hack my way around it .. its not ideal since i don't actually get back the fields I queried .. but at least i get a response back to the browser, which Im planning on pairing with a regular query that actually gets the fields I want ..

@japrogramer
Copy link
Author

@syrusakbary any ideas?

@dopeboy
Copy link

dopeboy commented May 13, 2019

@japrogramer, I'm going to close this down since you found a solution. I'd also turn you to #120.

@dopeboy dopeboy closed this as completed May 13, 2019
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

3 participants