Comments (3)
+1
from graphql-ws.
Our team also have the same problem when clients try to subscribe on multiple levels of graphql objects. We're using aiohttp and we made a simple workaround to solve the problem.
import asyncio
import inspect
from typing import Union, Awaitable, Any, List, Tuple, Dict
from graphql_ws.aiohttp import AiohttpSubscriptionServer
class SubscriptionServer(AiohttpSubscriptionServer):
async def send_execution_result(self, connection_context, op_id, execution_result) -> None:
resolving_items: List[Awaitable[Any]] = []
queue: List[Tuple[Union[List[Any], Dict[Union[int, str], Any]], Union[int, str], Any]] = [
(
None,
None,
execution_result.data,
),
]
while queue:
container, key, item = queue.pop(0)
if isinstance(item, list):
self.__extend_list_item(queue, item)
elif isinstance(item, dict):
self.__extend_dict_item(queue, item)
elif inspect.isawaitable(item):
container = container if container is not None else queue
key = key if key is not None else 0
resolving_items.append(self.__resolve_container_item(container, key, item))
await asyncio.gather(*resolving_items)
await super().send_execution_result(connection_context, op_id, execution_result)
return None
async def __resolve_container_item(
self,
container: Union[List[Any], Dict[Union[int, str], Any]],
key: Union[int, str],
item: Awaitable[Any],
) -> None:
container[key] = await item
def __extend_list_item(
self,
queue: List[Tuple[Union[List[Any], Dict[Union[int, str], Any]], Union[int, str], Any]],
item: List[Any],
) -> None:
queue.extend(
(
item,
index,
value,
)
for index, value in enumerate(item)
)
def __extend_dict_item(
self,
queue: List[Tuple[Union[List[Any], Dict[Union[int, str], Any]], Union[int, str], Any]],
item: Dict[Union[int, str], Any],
) -> None:
queue.extend(
(
item,
key,
value,
)
for key, value in item.items()
)
The main idea is to walk through the containers' objects and await for awaitable objects
from graphql-ws.
Hopefully fixed. Reopen if you can still reproduce using code on master
from graphql-ws.
Related Issues (20)
- Unbreakable flask_gevent subscription resolving HOT 4
- graphql-core v3? HOT 2
- Flask SocketIO Implementation
- test graphql-ws subscription HOT 1
- GeventSubscriptionServer ignore schema validation errors
- detect disconnect
- Django Channels Instructions/Support is Outdated HOT 5
- Is graphql-ws dead? HOT 2
- Release current master branch to pypi HOT 2
- Update to graphene v3 ? HOT 8
- Error running Django with graphql-ws HOT 3
- Using Django's GenericForeignKey with Async Graphene Subscription
- channels 3 compatibility HOT 1
- Deep nested objects in django won't work due to async HOT 6
- [Question] How to get payload on connect in aiohttp
- Impossible to use HTTP Headers with GraphIQL when using graphql-ws
- graphql-ws-next HOT 4
- No module named 'graphql.execution.executors' using graphql-ws HOT 2
- 403 error (failing WebSocket opening handshake ('Access denied'))
- using this with signals
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from graphql-ws.