prisma-tools icon indicating copy to clipboard operation
prisma-tools copied to clipboard

Subscriptions

Open DregondRahl opened this issue 4 years ago • 3 comments

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
  },
})

DregondRahl avatar Oct 28 '20 05:10 DregondRahl

It's a good idea to make a plugins system to our CLI generator so you can add custom generations.

AhmedElywa avatar Oct 29 '20 23:10 AhmedElywa

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.

DregondRahl avatar Nov 02 '20 07:11 DregondRahl

Yes, you are right, but it's like a big change

AhmedElywa avatar Nov 10 '20 10:11 AhmedElywa