I have set up a project using Prisma for handling the communication/storage/retrieval of data to and from the server. It is essentially the same architecture as here example. The only major difference is that my resolvers aren't separated into different files they are all resident in the index.js.
Now, I am trying to implement subscriptions which will catch all changes to my models. But for the life of me I cannot get the subscription to fire for anything other than DELETE actions. I have read multiple forum posts and examples but still the problem persists.
My index.js Subscription resolvers look as below:
Subscription: {
userChanges: {
subscribe: (_, args, context, info) => {
console.log("CHECKCHECK");
return context.prisma.subscription.user(
{ where: { mutation_in: ['CREATED'] } },
info
)
}
},
taskChanges: {
subscribe: async (_, args, context, info) => {
return await context.prisma.subscription.task({}, info)
}
}
}
My schema.graphql looks like this:
# import Task, User from '../generated/prisma.graphql'
# import TaskSubscriptionPayload, UserSubscriptionPayload from '../generated/prisma.graphql'
type Query {
task(id: ID!): Task
tasks: [Task]!
user(id: ID!): User
users: [User!]
getUserTasks(id:ID!): [Task]!
}
type Mutation {
addTask(
name: String!,
priority: Float!,
weight: Int!,
best: Float!,
expected: Float!,
worst: Float!,
calculated: Float!,
stdDev: Float!,
actualTime: Float,
tags: [String!]!,
ownedBy: ID!
): Task!
updateTask(
id: ID!,
name: String!,
priority: Float!,
weight: Int!,
best: Float!,
expected: Float!,
worst: Float!,
calculated: Float!,
stdDev: Float!,
actualTime: Float,
tags: [String!]!,
ownedBy: ID!
): Task!
deleteTask(id: ID!): Task!
addNewUser(name: String!): User!
deleteUser(id:ID!): User!
}
type Subscription {
taskChanges: TaskSubscriptionPayload
userChanges: UserSubscriptionPayload
}
I must be missing something because any/all issues I find on the Prisma forums were resolved by fixes way back in March. I suspect it may be something to do with an Async prisma binding but that is just intuition.
Any help would be much appreciated.
Thanks,
A
Ok, so I fixed this after much trial and error. It would seem that the initial tutorial I followed used an older version of the primsagraphql/prisma image which needed to be updated.
To fix the issue do the following:
Edit your docker-compose.yml with a newer version (for me I upgraded from 1.12 to 1.14)
services:
prisma:
image: prismagraphql/prisma:1.14
Take your docker images offline then redeploy them. For me I was happy to kill them entirely using the following commands but if you want to save your data you may want to find a different set of commands to do this.
docker-compose kill
docker-compose down
docker-compose up -d
Let your newly deployed Docker images warm-up a bit. Mine needed a couple of seconds to wake up for some reason :P. After that you should find your subscriptions will work again as expected.
Hope this helps others, it really took me a while to figure out that I needed to update my Docker image not my prisma npm version.
Cheers,
A