From b1b58e7ce38ce5ac627db2d4c2c52486f2c30bda Mon Sep 17 00:00:00 2001 From: Tai Sakuma Date: Wed, 10 Jan 2024 14:37:23 -0500 Subject: [PATCH 1/2] Replace __init__() with set_hook() to avoid overriding __init__() --- nextlinegraphql/plugins/graphql/plugin.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/nextlinegraphql/plugins/graphql/plugin.py b/nextlinegraphql/plugins/graphql/plugin.py index 63463ce..ad2787c 100644 --- a/nextlinegraphql/plugins/graphql/plugin.py +++ b/nextlinegraphql/plugins/graphql/plugin.py @@ -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 @@ -71,9 +71,9 @@ class _EGraphQL(GraphQL): 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} From cda5733ec7e9186f5333b173356297d33eba10e2 Mon Sep 17 00:00:00 2001 From: Tai Sakuma Date: Wed, 10 Jan 2024 14:40:28 -0500 Subject: [PATCH 2/2] Update docstring --- nextlinegraphql/plugins/graphql/plugin.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/nextlinegraphql/plugins/graphql/plugin.py b/nextlinegraphql/plugins/graphql/plugin.py index ad2787c..4701262 100644 --- a/nextlinegraphql/plugins/graphql/plugin.py +++ b/nextlinegraphql/plugins/graphql/plugin.py @@ -66,10 +66,11 @@ 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 set_hook(self, hook: PluginManager) -> '_EGraphQL': self._hook = hook