chore: refactor pub/sub iterator usage across schema files
- Updated pub/sub iterator methods from `asyncIterableIterator` to `asyncIterator` in multiple schema files for improved compatibility with the latest GraphQL subscriptions. - Refactored subscription logic in CollaborationSession, Document, Message, User, and other schema files to enhance readability and maintainability. - Adjusted imports in GraphQL builder to utilize RedisPubSub for better performance in subscription handling.
This commit is contained in:
@@ -12,8 +12,8 @@ import { User } from '@prisma/client'
|
||||
import { JsonValue } from '@prisma/client/runtime/library'
|
||||
import { Request, Response } from 'express'
|
||||
import { Kind, ValueNode } from 'graphql'
|
||||
import { RedisPubSub } from 'graphql-redis-subscriptions'
|
||||
import { JSONObjectResolver } from 'graphql-scalars'
|
||||
import { PubSub } from 'graphql-subscriptions'
|
||||
// @ts-expect-error
|
||||
import GraphQLUpload from 'graphql-upload/GraphQLUpload.mjs'
|
||||
// @ts-expect-error
|
||||
@@ -30,7 +30,7 @@ export type SchemaContext =
|
||||
isSubscription: true
|
||||
websocket: {
|
||||
req: Request
|
||||
pubSub: PubSub
|
||||
pubSub: RedisPubSub
|
||||
sessionId: string
|
||||
me: User
|
||||
generator: PrismaCrudGenerator<BuilderTypes>
|
||||
@@ -42,7 +42,7 @@ export type SchemaContext =
|
||||
req: Request
|
||||
res: Response
|
||||
me: User | null
|
||||
pubSub: PubSub
|
||||
pubSub: RedisPubSub
|
||||
invalidateCache: () => Promise<void>
|
||||
generator: PrismaCrudGenerator<BuilderTypes>
|
||||
}
|
||||
@@ -101,8 +101,8 @@ export class Builder extends SchemaBuilder<SchemaBuilderOption> {
|
||||
debounceDelay: 1000,
|
||||
...subscribeOptionsFromIterator((name, context) => {
|
||||
return context.isSubscription
|
||||
? context.websocket.pubSub.asyncIterableIterator(name)
|
||||
: context.http.pubSub.asyncIterableIterator(name)
|
||||
? context.websocket.pubSub.asyncIterator(name)
|
||||
: context.http.pubSub.asyncIterator(name)
|
||||
}),
|
||||
},
|
||||
zod: {
|
||||
|
||||
Reference in New Issue
Block a user