backend cung da bi lac
This commit is contained in:
Submodule epess-database updated: c4d2551a83...63a9ad306d
@@ -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,
|
||||
}),
|
||||
}))
|
||||
}
|
||||
|
||||
@@ -23,9 +23,10 @@ import SimpleObjectPlugin from '@pothos/plugin-simple-objects'
|
||||
import { User } from '@prisma/client'
|
||||
import { getDatamodel } from '../types/pothos.generated'
|
||||
import { DateTime } from 'luxon'
|
||||
import { Kind } from 'graphql'
|
||||
import { Kind, ValueNode } from 'graphql'
|
||||
import { DateTimeUtils } from '../common/utils/datetime.utils'
|
||||
import { JsonValue } from '@prisma/client/runtime/library'
|
||||
import Delta from 'quill-delta'
|
||||
|
||||
export type SchemaContext =
|
||||
| {
|
||||
@@ -75,6 +76,10 @@ export interface SchemaBuilderOption {
|
||||
Input: number
|
||||
Output: number | bigint | string
|
||||
}
|
||||
Delta: {
|
||||
Input: Delta
|
||||
Output: Delta
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -96,11 +101,10 @@ export class Builder extends SchemaBuilder<SchemaBuilderOption> {
|
||||
],
|
||||
smartSubscriptions: {
|
||||
debounceDelay: 1000,
|
||||
...subscribeOptionsFromIterator((name, ctx) => {
|
||||
if (ctx.isSubscription) {
|
||||
return ctx.websocket.pubSub.asyncIterator(name)
|
||||
}
|
||||
return ctx.http.pubSub.asyncIterator(name)
|
||||
...subscribeOptionsFromIterator((name, context) => {
|
||||
return context.isSubscription
|
||||
? context.websocket.pubSub.asyncIterator(name)
|
||||
: context.http.pubSub.asyncIterator(name)
|
||||
}),
|
||||
},
|
||||
zod: {
|
||||
@@ -154,6 +158,12 @@ export class Builder extends SchemaBuilder<SchemaBuilderOption> {
|
||||
throw new Error('Invalid DateTime')
|
||||
},
|
||||
})
|
||||
this.scalarType('Delta', {
|
||||
serialize: (value) => value.toString(),
|
||||
parseValue: (value: unknown) => value as unknown as Delta,
|
||||
parseLiteral: (ast: ValueNode) => ast as unknown as Delta,
|
||||
})
|
||||
|
||||
this.addScalarType('Json', JSONObjectResolver)
|
||||
this.addScalarType('Upload', GraphQLUpload)
|
||||
|
||||
|
||||
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user