backend cung da bi lac
This commit is contained in:
@@ -9,6 +9,7 @@ import { Builder, SchemaContext } from '../Graphql/graphql.builder'
|
||||
import { PrismaService } from '../Prisma/prisma.service'
|
||||
import { DocumentEvent } from './document.event'
|
||||
import { Document } from '@prisma/client'
|
||||
import { DocumentDelta } from './document.type'
|
||||
@Injectable()
|
||||
export class DocumentSchema extends PothosSchema {
|
||||
constructor(
|
||||
@@ -35,6 +36,19 @@ export class DocumentSchema extends PothosSchema {
|
||||
})
|
||||
}
|
||||
|
||||
@PothosRef()
|
||||
documentDelta() {
|
||||
return this.builder.simpleObject('DocumentDelta', {
|
||||
fields: (t) => ({
|
||||
pageIndex: t.int(),
|
||||
documentId: t.string(),
|
||||
delta: t.field({
|
||||
type: 'Delta',
|
||||
}),
|
||||
}),
|
||||
})
|
||||
}
|
||||
|
||||
@Pothos()
|
||||
init(): void {
|
||||
this.builder.queryFields((t) => ({
|
||||
@@ -84,7 +98,7 @@ export class DocumentSchema extends PothosSchema {
|
||||
|
||||
this.builder.subscriptionFields((t) => ({
|
||||
document: t.field({
|
||||
type: this.document(),
|
||||
type: this.documentDelta(),
|
||||
args: {
|
||||
documentId: t.arg({
|
||||
type: 'String',
|
||||
@@ -101,9 +115,9 @@ export class DocumentSchema extends PothosSchema {
|
||||
`${DocumentEvent.CREATED}.${args.documentId}`,
|
||||
`${DocumentEvent.DELETED}.${args.documentId}`,
|
||||
`${DocumentEvent.SAVED}.${args.documentId}`,
|
||||
]) as unknown as AsyncIterable<Document>
|
||||
]) as unknown as AsyncIterable<DocumentDelta>
|
||||
},
|
||||
resolve: async (payload: Document) => payload,
|
||||
resolve: async (payload: DocumentDelta) => payload,
|
||||
}),
|
||||
}))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user