Project tags CRUD + fix page metadata
This commit is contained in:
@ -1,4 +1,9 @@
|
||||
import { URLTypeDefinition, URLResolver } from 'graphql-scalars'
|
||||
import {
|
||||
URLTypeDefinition,
|
||||
URLResolver,
|
||||
HexColorCodeDefinition,
|
||||
HexColorCodeResolver,
|
||||
} from 'graphql-scalars'
|
||||
|
||||
import { createAuthDecoder } from '@redwoodjs/auth-dbauth-api'
|
||||
import { createGraphQLHandler } from '@redwoodjs/graphql-server'
|
||||
@ -21,13 +26,11 @@ export const handler = createGraphQLHandler({
|
||||
sdls,
|
||||
services,
|
||||
schemaOptions: {
|
||||
typeDefs: [URLTypeDefinition],
|
||||
typeDefs: [URLTypeDefinition, HexColorCodeDefinition],
|
||||
resolvers: {
|
||||
URL: URLResolver,
|
||||
HexColorCode: HexColorCodeResolver,
|
||||
},
|
||||
},
|
||||
onException: () => {
|
||||
// Disconnect from your database with an unhandled exception.
|
||||
db.$disconnect()
|
||||
},
|
||||
onException: () => db.$disconnect(),
|
||||
})
|
||||
|
@ -1,3 +1,4 @@
|
||||
export const schema = gql`
|
||||
scalar URL
|
||||
scalar HexColorCode
|
||||
`
|
||||
|
@ -2,7 +2,7 @@ export const schema = gql`
|
||||
type Tag {
|
||||
id: Int!
|
||||
tag: String!
|
||||
color: String!
|
||||
color: HexColorCode!
|
||||
projects: [Project]!
|
||||
}
|
||||
|
||||
@ -13,12 +13,12 @@ export const schema = gql`
|
||||
|
||||
input CreateTagInput {
|
||||
tag: String!
|
||||
color: String!
|
||||
color: HexColorCode!
|
||||
}
|
||||
|
||||
input UpdateTagInput {
|
||||
tag: String
|
||||
color: String
|
||||
color: HexColorCode
|
||||
}
|
||||
|
||||
type Mutation {
|
||||
|
@ -6,37 +6,30 @@ import type {
|
||||
|
||||
import { db } from 'src/lib/db'
|
||||
|
||||
export const tags: QueryResolvers['tags'] = () => {
|
||||
return db.tag.findMany()
|
||||
}
|
||||
export const tags: QueryResolvers['tags'] = () => db.tag.findMany()
|
||||
|
||||
export const tag: QueryResolvers['tag'] = ({ id }) => {
|
||||
return db.tag.findUnique({
|
||||
export const tag: QueryResolvers['tag'] = ({ id }) =>
|
||||
db.tag.findUnique({
|
||||
where: { id },
|
||||
})
|
||||
}
|
||||
|
||||
export const createTag: MutationResolvers['createTag'] = ({ input }) => {
|
||||
return db.tag.create({
|
||||
export const createTag: MutationResolvers['createTag'] = ({ input }) =>
|
||||
db.tag.create({
|
||||
data: input,
|
||||
})
|
||||
}
|
||||
|
||||
export const updateTag: MutationResolvers['updateTag'] = ({ id, input }) => {
|
||||
return db.tag.update({
|
||||
export const updateTag: MutationResolvers['updateTag'] = ({ id, input }) =>
|
||||
db.tag.update({
|
||||
data: input,
|
||||
where: { id },
|
||||
})
|
||||
}
|
||||
|
||||
export const deleteTag: MutationResolvers['deleteTag'] = ({ id }) => {
|
||||
return db.tag.delete({
|
||||
export const deleteTag: MutationResolvers['deleteTag'] = ({ id }) =>
|
||||
db.tag.delete({
|
||||
where: { id },
|
||||
})
|
||||
}
|
||||
|
||||
export const Tag: TagRelationResolvers = {
|
||||
projects: (_obj, { root }) => {
|
||||
return db.tag.findUnique({ where: { id: root?.id } }).projects()
|
||||
},
|
||||
projects: (_obj, { root }) =>
|
||||
db.tag.findUnique({ where: { id: root?.id } }).projects(),
|
||||
}
|
||||
|
Reference in New Issue
Block a user