Mutation implementations #5
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",
|
||||
"@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",
|
||||
|
|
|
|||
|
|
@ -19,6 +19,8 @@ model User {
|
|||
email String @unique
|
||||
name String?
|
||||
posts Post[]
|
||||
createdAt DateTime
|
||||
updatedAt DateTime
|
||||
}
|
||||
|
||||
model Post {
|
||||
|
|
@ -28,4 +30,6 @@ model Post {
|
|||
published Boolean @default(false)
|
||||
author User @relation(fields: [authorId], references: [id])
|
||||
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 SchemaBuilder from '@pothos/core';
|
||||
import PrismaPlugin, { type PrismaTypesFromClient } from '@pothos/plugin-prisma';
|
||||
import type { Scalars } from './Scalars';
|
||||
|
||||
type ContextType = ReturnType<typeof Context>;
|
||||
|
||||
export const builder = new SchemaBuilder<{
|
||||
Context: ContextType;
|
||||
type PothosType = {
|
||||
Context: ReturnType<typeof Context>;
|
||||
PrismaTypes: PrismaTypesFromClient<typeof prisma>;
|
||||
}>({
|
||||
Scalars: Scalars;
|
||||
};
|
||||
|
||||
export const builder = new SchemaBuilder<PothosType>({
|
||||
plugins: [PrismaPlugin],
|
||||
prisma: {
|
||||
client: prisma,
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue