Prisma Client 1.19 and Subscription big problem

prisma

#1

Hi all,

I really think there is a big problem with prisma client and subscription:
First problem, I notice there is actually no way to return directly the full subscription payload like

type PostSubscriptionPayload {
  mutation: MutationType!
  node: Post
  updatedFields: [String!]
  previousValues: PostPreviousValues
}

from a subscription like

type Subscription {
  posts: PostSubscriptionPayload
}

and the resolver

posts: {
  subscribe: async (parent, args, ctx) => {
    return ctx.prisma.$subscribe.post()
  },
  resolve: payload => {
    console.log(payload) // { mutation: 'CREATE', updatedFields: null }
    return payload
  }
}

In the resolve function I get only mutation and updatedFields fields, whatever is the event that trigger the subscription (create, update or delete).

Second problem, and this is a big one because it concerns the DELETE subscription directly. We can’t get back the previous value of the deleted node at all!

type Subscription {
  deletedPost: PostPreviousValues! // I tested with Post! too, same error
}

I get null

Note that I console log the payload in the resolve function of each subscription resolver like

  deletedPost: {
    subscribe: async (parent, args, ctx) => {
      return ctx.prisma.$subscribe.post({ mutation_in: ['DELETED'] }).previousValues()
    },
    resolve: payload => {
      console.log(payload) // null
      return payload
    }
  }

So I’m pretty sure the problem comes from prisma Client :zany_face:

generate:
- generator: javascript-client
  output: ../src/generated/prisma-client/
- generator: graphql-schema
  output: ../src/generated/

#2

How does your subscription query look like?


#3
subscription {
  posts {
    mutation
    node {
      title
    }
    updatedFields
    previousValues {
      title
    }
  }
}

#4

I am having same problem with primsa-client-lib ^1.21.0


#5

I’m having this issue with 1.21.1.

I have a freshly generated prisma client from a GraphQL schema.

I can subscribe to an entity, and then I’ll get the mutation and updatedFields data. I can subscribe to node and just get that, or I can subscribe to previousValues and just get that. But I can’t get it all at once!

Just node:
MySubscription: {
subscribe: (previous, args, context) =>
ctx.prisma.$subscribe.myEntity().node()
}

Just previousValues:
MySubscription: {
subscribe: (previous, args, context) =>
ctx.prisma.$subscribe.myEntity().previousValues()
}

Try get everything:
MySubscription: {
subscribe: (previous, args, context) =>
ctx.prisma.$subscribe.myEntity()
}

But unfortunately this only returns:

{
  mutation: ...,
  updatedFields: [...],
}

@nilan Is this on your radar? Do people use subscriptions with Prisma?


#6

@rajit I posted this issue here https://github.com/prisma/prisma/issues/3603