How can I subscribe user for model with his id? F...
# orm-help
g
How can I subscribe user for model with his id? For example, I have a model `task`:
Copy code
type Task {
  id: ID! @unique
  title: String!
  user: User!
}
Now my subscription looks like this:
Copy code
const taskCreated = {
  subscribe: (_, args, context, info) => {
    return context.prisma.subscription.task({ where: { mutation_in: ['CREATED'] } }, info);
  },
};
Now ALL my users get task when somebody created a task, but only 1 user should get it (the user who created it). How can I do it?
n
Could you post this question in the Forum? https://www.prisma.io/forum/c/questions
g
@nilan so there is nothing u can help me here? 😞 it is an emergency and I need to fix it ASAP 😞
n
from my experience, coding questions are best discussed in the Forum 🙂 you can also check the docs: https://docs-beta.prisma.io/1.14/use-prisma-api/api-reference/subscriptions-qwe3/#filtering-for-specific-events
g
@nilan but it doesn't seem like it works with objects, only with strings...
c
@Gorodov Maksim you have to specify the user id. Because in your subscription example you're subscribing to all Task changes.
You have to either pass user_id as arg or in context.
Copy code
return context.prisma.subscription.task({ 
    where: { mutation_in: ['CREATED'], 
    node: { user: {id: desired_user_id} } } 
}, info);
g
@catalinmiron or like this?
Copy code
const taskCreated = {
  subscribe: (_, args, context, info) => {
    const userId = getUserId(context);

    return context.prisma.subscription.task({
      where: { mutation_in: ['CREATED'], },
      node: { user: { id: userId } },
    }, info);
  },
};
nope, it doesn't work... it works like it used to be :(((