keyan 18910fa2ed Revert "shield your eyes; massive, squashed refactor; nextjs/react/react-dom/apollo upgrades"
This reverts commit d0314ab73c42ebf85fe2f418dddd681af45dbc55.
2023-07-23 09:16:12 -05:00

30 lines
818 B
JavaScript

import { UserInputError } from 'apollo-server-micro'
export default {
Query: {
messages: async (parent, args, { models }) =>
await models.message.findMany(),
message: async (parent, { id }, { models }) =>
await models.message.findUnique({ where: { id } })
},
Mutation: {
createMessage: async (parent, { text }, { me, models }) => {
if (!text) {
throw new UserInputError('Must have text', { argumentName: 'text' })
}
return await models.message.create({
data: { text, userId: me.id }
})
},
deleteMessage: async (parent, { id }, { models }) =>
await models.message.delete({ where: { id } })
},
Message: {
user: async (message, args, { models }) =>
await models.user.findUnique({ where: { id: message.userId } })
}
}