Skip to content
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

Silencing scope error for ariadne #180

Open
Lilja opened this issue Apr 14, 2021 · 1 comment
Open

Silencing scope error for ariadne #180

Lilja opened this issue Apr 14, 2021 · 1 comment
Labels
bug Something isn't working

Comments

@Lilja
Copy link

Lilja commented Apr 14, 2021

Hi! Thank you for creating this framework. I'm currently using ariadne to manage a graphql lambda.

For every execution I get a stack trace:

ERROR:mangum.lifespan:Exception in 'lifespan' protocol.
Traceback (most recent call last):
  File "/Users/lilja/Library/Caches/pypoetry/virtualenvs/backend-dmp__8h8-py3.8/lib/python3.8/site-packages/mangum/protocols/lifespan.py", line 93, in run
    await self.app({"type": "lifespan"}, self.receive, self.send)
  File "/Users/lilja/Library/Caches/pypoetry/virtualenvs/backend-dmp__8h8-py3.8/lib/python3.8/site-packages/ariadne/asgi.py", line 94, in __call__
    raise ValueError("Unknown scope type: %r" % (scope["type"],))
ValueError: Unknown scope type: 'lifespan'

However, the lambda/mangum executes as the rest of the code as usual and I have correct graphql output.

I'm not up-to-speed with asgi stuff and don't really know what this means, is there a way to silence this error? Should I create a github issue with the other framework in question?

raised error in question: https://github.com/mirumee/ariadne/blob/master/ariadne/asgi.py#L113

How I use mangum

async def setup() -> GraphQL:
    session = ClientSession()
    schema_file = os.environ.get("SCHEMA_FILE", "../schema.graphql")

    async with session:
        engine = await setup_graphql(session, schema_file)
        return GraphQL(engine, debug=production)


def lambda_handler(event: Dict[str, Any], context: Any):
    graphql_app = asyncio.get_event_loop().run_until_complete(setup())
    handler_fn = Mangum(graphql_app)
    return add_cors_headers(handler_fn(event, context))


def add_cors_headers(ret_value: Dict[str, Dict]) -> Dict[str, Dict]:
    ret_value["headers"]["Access-Control-Allow-Origin"] = "*"

    return ret_value
@jordaneremieff
Copy link
Collaborator

jordaneremieff commented Apr 15, 2021

Hello, thanks for the issue report!

This is due to the default lifespan behavior of Mangum. You can set the Mangum(graphql_app, lifespan="off") setting to explicitly disable lifespan to avoid this, though Mangum should probably be catching exceptions generally in these cases instead of raising.

@jordaneremieff jordaneremieff added the bug Something isn't working label Apr 15, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants