diff --git a/bun.lockb b/bun.lockb index 37b9108..925d1b3 100755 Binary files a/bun.lockb and b/bun.lockb differ diff --git a/package.json b/package.json index 87c7b5f..c7b7b1a 100644 --- a/package.json +++ b/package.json @@ -55,6 +55,7 @@ "@prisma/client": "6.0.1", "@tailwindcss/typography": "^0.5.15", "@types/bun": "^1.1.14", + "dayjs": "^1.11.13", "graphql": "^16.9.0", "graphql-yoga": "^5.10.4", "pino": "^9.5.0", diff --git a/prisma/schema.prisma b/prisma/schema.prisma index 0cd53f5..6449cf2 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -15,17 +15,21 @@ datasource db { } model User { - id Int @id @default(autoincrement()) - email String @unique - name String? - posts Post[] + id Int @id @default(autoincrement()) + email String @unique + name String? + posts Post[] + createdAt DateTime + updatedAt DateTime } model Post { - id Int @id @default(autoincrement()) + id Int @id @default(autoincrement()) title String content String? - published Boolean @default(false) - author User @relation(fields: [authorId], references: [id]) + published Boolean @default(false) + author User @relation(fields: [authorId], references: [id]) authorId Int + createdAt DateTime + updatedAt DateTime } \ No newline at end of file diff --git a/src/lib/pothos/Scalars/Date.ts b/src/lib/pothos/Scalars/Date.ts new file mode 100644 index 0000000..298596f --- /dev/null +++ b/src/lib/pothos/Scalars/Date.ts @@ -0,0 +1,15 @@ +import dayjs from 'dayjs'; +import { builder } from '../builder'; + +export const Date = builder.scalarType('Date', { + description: 'Date Scalar in ISO format', + serialize: (t) => { + return t.toISOString(); + }, + parseValue: (date) => { + if (typeof date !== 'string') { + throw new Error('Cyka blyat'); + } + return dayjs(date); + } +}); \ No newline at end of file diff --git a/src/lib/pothos/Scalars/index.ts b/src/lib/pothos/Scalars/index.ts new file mode 100644 index 0000000..521b166 --- /dev/null +++ b/src/lib/pothos/Scalars/index.ts @@ -0,0 +1,10 @@ +import type { Dayjs } from 'dayjs'; + +export * from './Date'; + +export type Scalars = { + Date: { + Input: Dayjs; + Output: Dayjs; + }; +}; \ No newline at end of file diff --git a/src/lib/pothos/builder.ts b/src/lib/pothos/builder.ts index 1428ea6..c8e2d3c 100644 --- a/src/lib/pothos/builder.ts +++ b/src/lib/pothos/builder.ts @@ -2,13 +2,15 @@ import { prisma } from '$lib/prisma'; import type { Context } from '$lib/yoga'; import SchemaBuilder from '@pothos/core'; import PrismaPlugin, { type PrismaTypesFromClient } from '@pothos/plugin-prisma'; +import type { Scalars } from './Scalars'; -type ContextType = ReturnType; - -export const builder = new SchemaBuilder<{ - Context: ContextType; +type PothosType = { + Context: ReturnType; PrismaTypes: PrismaTypesFromClient; -}>({ + Scalars: Scalars; +}; + +export const builder = new SchemaBuilder({ plugins: [PrismaPlugin], prisma: { client: prisma,