Mutation implementations #5

Merged
BenjaminPalko merged 8 commits from mutation-examples into master 2024-12-11 15:59:02 -05:00
6 changed files with 44 additions and 12 deletions
Showing only changes of commit fec67a55c7 - Show all commits

BIN
bun.lockb

Binary file not shown.

View file

@ -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",

View file

@ -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
}

View 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);
}
});

View file

@ -0,0 +1,10 @@
import type { Dayjs } from 'dayjs';
export * from './Date';
export type Scalars = {
Date: {
Input: Dayjs;
Output: Dayjs;
};
};

View file

@ -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,