fix some bug and produce many problem to solve later
This commit is contained in:
@@ -22,6 +22,9 @@ import SchemaBuilder from '@pothos/core'
|
||||
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 { DateTimeUtils } from '../common/utils/datetime.utils'
|
||||
|
||||
// import { rules } from '../common/graphql/common.graphql.auth-rule';
|
||||
|
||||
@@ -29,6 +32,7 @@ export type SchemaContext =
|
||||
| {
|
||||
isSubscription: true
|
||||
websocket: {
|
||||
req: Request
|
||||
pubSub: PubSub
|
||||
me: User
|
||||
generator: PrismaCrudGenerator<BuilderTypes>
|
||||
@@ -57,8 +61,8 @@ export interface SchemaBuilderOption {
|
||||
// AuthZRule: keyof typeof rules;
|
||||
Scalars: {
|
||||
DateTime: {
|
||||
Input: Date
|
||||
Output: Date
|
||||
Input: string | DateTime | Date
|
||||
Output: string | DateTime | Date
|
||||
}
|
||||
Json: {
|
||||
Input: JSON
|
||||
@@ -112,7 +116,36 @@ export class Builder extends SchemaBuilder<SchemaBuilderOption> {
|
||||
},
|
||||
})
|
||||
this.generator = new PrismaCrudGenerator<BuilderTypes>(this)
|
||||
this.addScalarType('DateTime', DateTimeResolver)
|
||||
this.scalarType('DateTime', {
|
||||
serialize: (value) => {
|
||||
// Serialize outgoing DateTime to ISO string
|
||||
if (typeof value === 'string') {
|
||||
return value
|
||||
}
|
||||
if (typeof value === 'object' && value !== null && 'toISO' in value) {
|
||||
return value
|
||||
}
|
||||
// if value = Date, convert to DateTime
|
||||
if (value instanceof Date) {
|
||||
return DateTimeUtils.toIsoString(DateTimeUtils.fromDate(value))
|
||||
}
|
||||
throw new Error('Invalid DateTime')
|
||||
},
|
||||
parseValue: (value) => {
|
||||
// Parse incoming ISO string to Luxon DateTime
|
||||
if (typeof value === 'string') {
|
||||
return DateTimeUtils.fromIsoString(value)
|
||||
}
|
||||
throw new Error('Invalid DateTime')
|
||||
},
|
||||
parseLiteral: (ast) => {
|
||||
// parse string to DateTime
|
||||
if (ast.kind === Kind.STRING) {
|
||||
return DateTimeUtils.fromIsoString(ast.value)
|
||||
}
|
||||
throw new Error('Invalid DateTime')
|
||||
},
|
||||
})
|
||||
this.addScalarType('Json', JSONObjectResolver)
|
||||
this.addScalarType('Upload', GraphQLUpload)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user