subs-on-ws
This commit is contained in:
parent
c9400f23fb
commit
044bfa5bd4
13
main.py
13
main.py
|
@ -21,7 +21,7 @@ from services.zine.gittask import GitTask
|
|||
from settings import DEV_SERVER_STATUS_FILE_NAME, SENTRY_DSN
|
||||
from ariadne.asgi.handlers import GraphQLTransportWSHandler
|
||||
from services.inbox.presence import on_connect, on_disconnect
|
||||
from services.inbox.sse import sse_messages
|
||||
# from services.inbox.sse import sse_messages
|
||||
|
||||
|
||||
import_module("resolvers")
|
||||
|
@ -68,7 +68,7 @@ routes = [
|
|||
Route("/oauth/{provider}", endpoint=oauth_login),
|
||||
Route("/oauth-authorize", endpoint=oauth_authorize),
|
||||
Route("/confirm/{token}", endpoint=confirm_email_handler),
|
||||
Route("/messages", endpoint=sse_messages)
|
||||
# Route("/messages", endpoint=sse_messages)
|
||||
]
|
||||
|
||||
app = Starlette(
|
||||
|
@ -94,4 +94,11 @@ dev_app = app = Starlette(
|
|||
middleware=middleware,
|
||||
routes=routes,
|
||||
)
|
||||
dev_app.mount("/", GraphQL(schema, debug=True))
|
||||
dev_app.mount("/", GraphQL(
|
||||
schema,
|
||||
debug=True,
|
||||
websocket_handler=GraphQLTransportWSHandler(
|
||||
on_connect=on_connect,
|
||||
on_disconnect=on_disconnect
|
||||
)
|
||||
))
|
||||
|
|
|
@ -6,7 +6,7 @@ PyYAML>=5.4
|
|||
pyjwt>=2.6.0
|
||||
starlette~=0.20.4
|
||||
sqlalchemy>=1.4.41
|
||||
graphql-core
|
||||
graphql-core>=3.0.3
|
||||
gql
|
||||
uvicorn>=0.18.3
|
||||
pydantic>=1.10.2
|
||||
|
@ -28,3 +28,4 @@ beautifulsoup4~=4.11.1
|
|||
lxml
|
||||
sentry-sdk>=0.10.2
|
||||
sse_starlette
|
||||
graphql-ws
|
||||
|
|
|
@ -140,15 +140,12 @@ async def mark_as_read(_, info, chat_id: str, messages: [int]):
|
|||
}
|
||||
|
||||
|
||||
@subscription.source("newMessages")
|
||||
@subscription.source("newMessage")
|
||||
@login_required
|
||||
async def message_generator(obj, info):
|
||||
print(f"[resolvers.messages] generator {info}")
|
||||
auth: AuthCredentials = info.context["request"].auth
|
||||
return await messages_generator_by_user(auth.user_id)
|
||||
|
||||
|
||||
async def messages_generator_by_user(user_id):
|
||||
user_id = auth.user_id
|
||||
try:
|
||||
user_following_chats = await redis.execute("GET", f"chats_by_user/{user_id}")
|
||||
if user_following_chats:
|
||||
|
|
|
@ -305,11 +305,9 @@ type Query {
|
|||
############################################ Subscription
|
||||
|
||||
type Subscription {
|
||||
newMessages: Message
|
||||
onlineUpdated: [User!]!
|
||||
shoutUpdated: Shout!
|
||||
userUpdated: User!
|
||||
reactionUpdated(shout: String!): ReactionUpdating!
|
||||
newMessage: Message # new messages in inbox
|
||||
collabUpdate(collab: Int!): Reaction # new reactions in collaborative editor
|
||||
|
||||
}
|
||||
|
||||
############################################ Entities
|
||||
|
|
Loading…
Reference in New Issue
Block a user