complete delta??

This commit is contained in:
2024-11-15 20:30:24 +07:00
parent 270d185f18
commit bb0eed1851

View File

@@ -10,6 +10,7 @@ import { PrismaService } from '../Prisma/prisma.service'
import { DocumentEvent } from './document.event'
import { Document } from '@prisma/client'
import { DocumentDelta } from './document.type'
import Delta from 'quill-delta'
@Injectable()
export class DocumentSchema extends PothosSchema {
constructor(
@@ -40,8 +41,8 @@ export class DocumentSchema extends PothosSchema {
documentDelta() {
return this.builder.simpleObject('DocumentDelta', {
fields: (t) => ({
pageIndex: t.int(),
documentId: t.string(),
pageIndex: t.int(),
delta: t.field({
type: 'Delta',
}),
@@ -49,6 +50,17 @@ export class DocumentSchema extends PothosSchema {
})
}
@PothosRef()
documentDeltaInput() {
return this.builder.inputType('DocumentDeltaInput', {
fields: (t) => ({
documentId: t.string(),
pageIndex: t.int(),
delta: t.field({ type: 'Delta' }),
}),
})
}
@Pothos()
init(): void {
this.builder.queryFields((t) => ({
@@ -94,6 +106,49 @@ export class DocumentSchema extends PothosSchema {
})
},
}),
testUpdateDocument: t.field({
type: this.documentDelta(),
args: {
documentId: t.arg({ type: 'String', required: true }),
pageIndex: t.arg({ type: 'Int', required: true }),
},
resolve: async (_root, args, ctx: SchemaContext) => {
if (ctx.isSubscription) throw new Error('Not allowed')
const delta = new Delta().insert('test')
const documentDelta = {
documentId: args.documentId,
pageIndex: args.pageIndex,
delta,
}
ctx.http.pubSub.publish(
`${DocumentEvent.CHANGED}.${args.documentId}`,
documentDelta,
)
return documentDelta
},
}),
updateDocument: t.field({
type: this.documentDelta(),
args: {
data: t.arg({
type: this.documentDeltaInput(),
required: true,
}),
},
resolve: async (_, args, ctx: SchemaContext) => {
if (ctx.isSubscription) throw new Error('Not allowed')
const {
http: { pubSub },
} = ctx
pubSub.publish(
`${DocumentEvent.CHANGED}.${args.data.documentId}`,
args.data,
)
return args.data
},
}),
}))
this.builder.subscriptionFields((t) => ({