Update to RW 8.3.0 + Project CRUD complete

This commit is contained in:
Ahmed Al-Taiar
2024-09-27 22:52:41 -04:00
parent 430a2da835
commit 5c41588249
21 changed files with 1395 additions and 1170 deletions

View File

@ -1,33 +0,0 @@
export const schema = gql`
type ProjectImage {
id: Int!
fileId: URL!
Project: Project
projectId: Int
}
type Query {
projectImages: [ProjectImage!]! @requireAuth
projectImage(id: Int!): ProjectImage @requireAuth
}
input CreateProjectImageInput {
fileId: URL!
projectId: Int
}
input UpdateProjectImageInput {
fileId: URL
projectId: Int
}
type Mutation {
createProjectImage(input: CreateProjectImageInput!): ProjectImage!
@requireAuth
updateProjectImage(
id: Int!
input: UpdateProjectImageInput!
): ProjectImage! @requireAuth
deleteProjectImage(id: Int!): ProjectImage! @requireAuth
}
`

View File

@ -3,7 +3,7 @@ export const schema = gql`
id: Int!
title: String!
description: String!
images: [ProjectImage]!
images: [String]!
date: DateTime!
links: [URL]!
tags: [Tag]!
@ -19,6 +19,8 @@ export const schema = gql`
description: String!
date: DateTime!
links: [URL]!
images: [URL]!
tags: [Int!]
}
input UpdateProjectInput {
@ -26,6 +28,9 @@ export const schema = gql`
description: String
date: DateTime
links: [URL]!
images: [URL]!
tags: [Int!]
removeTags: [Int!]
}
type Mutation {

View File

@ -1,49 +0,0 @@
import type {
QueryResolvers,
MutationResolvers,
ProjectImageRelationResolvers,
} from 'types/graphql'
import { db } from 'src/lib/db'
export const projectImages: QueryResolvers['projectImages'] = () => {
return db.projectImage.findMany()
}
export const projectImage: QueryResolvers['projectImage'] = ({ id }) => {
return db.projectImage.findUnique({
where: { id },
})
}
export const createProjectImage: MutationResolvers['createProjectImage'] = ({
input,
}) => {
return db.projectImage.create({
data: input,
})
}
export const updateProjectImage: MutationResolvers['updateProjectImage'] = ({
id,
input,
}) => {
return db.projectImage.update({
data: input,
where: { id },
})
}
export const deleteProjectImage: MutationResolvers['deleteProjectImage'] = ({
id,
}) => {
return db.projectImage.delete({
where: { id },
})
}
export const ProjectImage: ProjectImageRelationResolvers = {
Project: (_obj, { root }) => {
return db.projectImage.findUnique({ where: { id: root?.id } }).Project()
},
}

View File

@ -15,15 +15,34 @@ export const project: QueryResolvers['project'] = ({ id }) =>
export const createProject: MutationResolvers['createProject'] = ({ input }) =>
db.project.create({
data: input,
data: {
title: input.title,
description: input.description,
date: input.date,
links: input.links,
images: input.images,
tags: {
connect: input.tags.map((tagId) => ({ id: tagId })),
},
},
})
export const updateProject: MutationResolvers['updateProject'] = ({
export const updateProject: MutationResolvers['updateProject'] = async ({
id,
input,
}) =>
db.project.update({
data: input,
data: {
title: input.title,
description: input.description,
date: input.date,
links: input.links,
images: input.images,
tags: {
disconnect: input.removeTags?.map((tagId) => ({ id: tagId })),
connect: input.tags?.map((tagId) => ({ id: tagId })),
},
},
where: { id },
})
@ -33,8 +52,6 @@ export const deleteProject: MutationResolvers['deleteProject'] = ({ id }) =>
})
export const Project: ProjectRelationResolvers = {
images: (_obj, { root }) =>
db.project.findUnique({ where: { id: root?.id } }).images(),
tags: (_obj, { root }) =>
db.project.findUnique({ where: { id: root?.id } }).tags(),
}