prisma-tools
prisma-tools copied to clipboard
Subscriptions
Would it be possible to add subscriptions ? Would be linked to the mutations (createOne, updateOne)
import { subscriptionField } from '@nexus/schema'
export const PostLatestSubscription = subscriptionField('latestPost', {
type: 'Post',
subscribe(_root, _args, ctx) {
return ctx.pubsub.asyncIterator('latestPost')
},
resolve(payload) {
return payload
},
})
import { mutationField, arg } from '@nexus/schema'
export const PostCreateOneMutation = mutationField('createOnePost', {
type: 'Post',
nullable: false,
args: {
data: arg({
type: 'PostCreateInput',
nullable: false,
}),
},
resolve: async (_parent, { data }, { prisma, select, pubsub }) => {
const newPost = await prisma.post.create({
data,
...select,
})
pubsub.publish('latestPost', newPost)
return newPost
},
})
It's a good idea to make a plugins system to our CLI generator so you can add custom generations.
one way to do this could be to create a _templates folder when a project is created using paljs, then before they run pal g they can modify the templates and then run it. It would be similar to how hygen works. It would be easy then to even generate it with validations or anything else customizable.
Yes, you are right, but it's like a big change