timestamps, scalars and dayjs
This commit is contained in:
parent
be2e559602
commit
fec67a55c7
6 changed files with 44 additions and 12 deletions
BIN
bun.lockb
BIN
bun.lockb
Binary file not shown.
|
|
@ -55,6 +55,7 @@
|
||||||
"@prisma/client": "6.0.1",
|
"@prisma/client": "6.0.1",
|
||||||
"@tailwindcss/typography": "^0.5.15",
|
"@tailwindcss/typography": "^0.5.15",
|
||||||
"@types/bun": "^1.1.14",
|
"@types/bun": "^1.1.14",
|
||||||
|
"dayjs": "^1.11.13",
|
||||||
"graphql": "^16.9.0",
|
"graphql": "^16.9.0",
|
||||||
"graphql-yoga": "^5.10.4",
|
"graphql-yoga": "^5.10.4",
|
||||||
"pino": "^9.5.0",
|
"pino": "^9.5.0",
|
||||||
|
|
|
||||||
|
|
@ -15,17 +15,21 @@ datasource db {
|
||||||
}
|
}
|
||||||
|
|
||||||
model User {
|
model User {
|
||||||
id Int @id @default(autoincrement())
|
id Int @id @default(autoincrement())
|
||||||
email String @unique
|
email String @unique
|
||||||
name String?
|
name String?
|
||||||
posts Post[]
|
posts Post[]
|
||||||
|
createdAt DateTime
|
||||||
|
updatedAt DateTime
|
||||||
}
|
}
|
||||||
|
|
||||||
model Post {
|
model Post {
|
||||||
id Int @id @default(autoincrement())
|
id Int @id @default(autoincrement())
|
||||||
title String
|
title String
|
||||||
content String?
|
content String?
|
||||||
published Boolean @default(false)
|
published Boolean @default(false)
|
||||||
author User @relation(fields: [authorId], references: [id])
|
author User @relation(fields: [authorId], references: [id])
|
||||||
authorId Int
|
authorId Int
|
||||||
|
createdAt DateTime
|
||||||
|
updatedAt DateTime
|
||||||
}
|
}
|
||||||
15
src/lib/pothos/Scalars/Date.ts
Normal file
15
src/lib/pothos/Scalars/Date.ts
Normal file
|
|
@ -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);
|
||||||
|
}
|
||||||
|
});
|
||||||
10
src/lib/pothos/Scalars/index.ts
Normal file
10
src/lib/pothos/Scalars/index.ts
Normal file
|
|
@ -0,0 +1,10 @@
|
||||||
|
import type { Dayjs } from 'dayjs';
|
||||||
|
|
||||||
|
export * from './Date';
|
||||||
|
|
||||||
|
export type Scalars = {
|
||||||
|
Date: {
|
||||||
|
Input: Dayjs;
|
||||||
|
Output: Dayjs;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
@ -2,13 +2,15 @@ import { prisma } from '$lib/prisma';
|
||||||
import type { Context } from '$lib/yoga';
|
import type { Context } from '$lib/yoga';
|
||||||
import SchemaBuilder from '@pothos/core';
|
import SchemaBuilder from '@pothos/core';
|
||||||
import PrismaPlugin, { type PrismaTypesFromClient } from '@pothos/plugin-prisma';
|
import PrismaPlugin, { type PrismaTypesFromClient } from '@pothos/plugin-prisma';
|
||||||
|
import type { Scalars } from './Scalars';
|
||||||
|
|
||||||
type ContextType = ReturnType<typeof Context>;
|
type PothosType = {
|
||||||
|
Context: ReturnType<typeof Context>;
|
||||||
export const builder = new SchemaBuilder<{
|
|
||||||
Context: ContextType;
|
|
||||||
PrismaTypes: PrismaTypesFromClient<typeof prisma>;
|
PrismaTypes: PrismaTypesFromClient<typeof prisma>;
|
||||||
}>({
|
Scalars: Scalars;
|
||||||
|
};
|
||||||
|
|
||||||
|
export const builder = new SchemaBuilder<PothosType>({
|
||||||
plugins: [PrismaPlugin],
|
plugins: [PrismaPlugin],
|
||||||
prisma: {
|
prisma: {
|
||||||
client: prisma,
|
client: prisma,
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue