Mutation implementations #5

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

View file

@ -19,8 +19,8 @@ model User {
email String @unique
name String?
posts Post[]
createdAt DateTime
updatedAt DateTime
createdAt DateTime @default(now())
updatedAt DateTime @default(now()) @updatedAt
}
model Post {
@ -30,6 +30,6 @@ model Post {
published Boolean @default(false)
author User @relation(fields: [authorId], references: [id])
authorId Int
createdAt DateTime
updatedAt DateTime
createdAt DateTime @default(now())
updatedAt DateTime @default(now()) @updatedAt
}

View file

@ -1,15 +1,14 @@
import dayjs from 'dayjs';
import { builder } from '../builder';
export const Date = builder.scalarType('Date', {
export const DateScalar = builder.scalarType('Date', {
description: 'Date Scalar in ISO format',
serialize: (t) => {
return t.toISOString();
serialize: (date) => {
return date.toISOString();
},
parseValue: (date) => {
if (typeof date !== 'string') {
throw new Error('Cyka blyat');
}
return dayjs(date);
return new Date(date);
}
});

View file

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

View file

@ -6,7 +6,13 @@ const User = builder.prismaObject('User', {
id: t.exposeID('id'),
email: t.exposeString('email'),
name: t.exposeString('name'),
posts: t.relation('posts')
posts: t.relation('posts'),
createdAt: t.expose('createdAt', {
type: 'Date'
}),
updatedAt: t.expose('updatedAt', {
type: 'Date'
})
})
});
@ -16,7 +22,13 @@ const Post = builder.prismaObject('Post', {
title: t.exposeString('title'),
content: t.exposeString('content'),
published: t.exposeBoolean('published'),
author: t.relation('author')
author: t.relation('author'),
createdAt: t.expose('createdAt', {
type: 'Date'
}),
updatedAt: t.expose('updatedAt', {
type: 'Date'
})
})
});