complete delta??
This commit is contained in:
@@ -10,6 +10,7 @@ import { PrismaService } from '../Prisma/prisma.service'
|
|||||||
import { DocumentEvent } from './document.event'
|
import { DocumentEvent } from './document.event'
|
||||||
import { Document } from '@prisma/client'
|
import { Document } from '@prisma/client'
|
||||||
import { DocumentDelta } from './document.type'
|
import { DocumentDelta } from './document.type'
|
||||||
|
import Delta from 'quill-delta'
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class DocumentSchema extends PothosSchema {
|
export class DocumentSchema extends PothosSchema {
|
||||||
constructor(
|
constructor(
|
||||||
@@ -40,8 +41,8 @@ export class DocumentSchema extends PothosSchema {
|
|||||||
documentDelta() {
|
documentDelta() {
|
||||||
return this.builder.simpleObject('DocumentDelta', {
|
return this.builder.simpleObject('DocumentDelta', {
|
||||||
fields: (t) => ({
|
fields: (t) => ({
|
||||||
pageIndex: t.int(),
|
|
||||||
documentId: t.string(),
|
documentId: t.string(),
|
||||||
|
pageIndex: t.int(),
|
||||||
delta: t.field({
|
delta: t.field({
|
||||||
type: 'Delta',
|
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()
|
@Pothos()
|
||||||
init(): void {
|
init(): void {
|
||||||
this.builder.queryFields((t) => ({
|
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) => ({
|
this.builder.subscriptionFields((t) => ({
|
||||||
|
|||||||
Reference in New Issue
Block a user