Projects CRUD (todo: project images)

This commit is contained in:
Ahmed Al-Taiar
2024-09-08 23:36:30 -04:00
parent 1c5a8d026a
commit e080e6b222
17 changed files with 386 additions and 251 deletions

View File

@ -5,7 +5,7 @@ export const schema = gql`
description: String!
images: [ProjectImage]!
date: DateTime!
links: [String]!
links: [URL]!
tags: [Tag]!
}
@ -18,14 +18,14 @@ export const schema = gql`
title: String!
description: String!
date: DateTime!
links: [String]!
links: [URL]!
}
input UpdateProjectInput {
title: String
description: String
date: DateTime
links: [String]!
links: [URL]!
}
type Mutation {

View File

@ -6,45 +6,35 @@ import type {
import { db } from 'src/lib/db'
export const projects: QueryResolvers['projects'] = () => {
return db.project.findMany()
}
export const projects: QueryResolvers['projects'] = () => db.project.findMany()
export const project: QueryResolvers['project'] = ({ id }) => {
return db.project.findUnique({
export const project: QueryResolvers['project'] = ({ id }) =>
db.project.findUnique({
where: { id },
})
}
export const createProject: MutationResolvers['createProject'] = ({
input,
}) => {
return db.project.create({
export const createProject: MutationResolvers['createProject'] = ({ input }) =>
db.project.create({
data: input,
})
}
export const updateProject: MutationResolvers['updateProject'] = ({
id,
input,
}) => {
return db.project.update({
}) =>
db.project.update({
data: input,
where: { id },
})
}
export const deleteProject: MutationResolvers['deleteProject'] = ({ id }) => {
return db.project.delete({
export const deleteProject: MutationResolvers['deleteProject'] = ({ id }) =>
db.project.delete({
where: { id },
})
}
export const Project: ProjectRelationResolvers = {
images: (_obj, { root }) => {
return db.project.findUnique({ where: { id: root?.id } }).images()
},
tags: (_obj, { root }) => {
return db.project.findUnique({ where: { id: root?.id } }).tags()
},
images: (_obj, { root }) =>
db.project.findUnique({ where: { id: root?.id } }).images(),
tags: (_obj, { root }) =>
db.project.findUnique({ where: { id: root?.id } }).tags(),
}