Skip to content

Commit

Permalink
Merge pull request #24 from simonsobs/egraphql
Browse files Browse the repository at this point in the history
Avoid overriding the strawberry GraphQL app's `__init__()`
  • Loading branch information
TaiSakuma authored Jan 10, 2024
2 parents 2ab774c + cda5733 commit b7fc7eb
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions nextlinegraphql/plugins/graphql/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def update_strawberry_context(self, context: MutableMapping[str, Any]) -> None:

def _create_app(hook: PluginManager) -> ASGIApp:
schema = _compose_schema(hook=hook)
app = _EGraphQL(schema=schema, hook=hook)
app = _EGraphQL(schema).set_hook(hook)
return app


Expand Down Expand Up @@ -66,14 +66,15 @@ def _compose_schema(hook: PluginManager) -> BaseSchema:


class _EGraphQL(GraphQL):
"""Extend the strawberry GraphQL app
'''Extend the strawberry GraphQL app to override the `get_context` method
This class is implemented in the way described in the strawberry document:
https://strawberry.rocks/docs/integrations/asgi
"""
'''

def __init__(self, schema: BaseSchema, hook: PluginManager):
super().__init__(schema)
def set_hook(self, hook: PluginManager) -> '_EGraphQL':
self._hook = hook
return self

async def get_context(self, request, response=None) -> Optional[Any]:
context = {'request': request, 'response': response}
Expand Down

0 comments on commit b7fc7eb

Please sign in to comment.