Hello there,
I am trying to work with apollo and a mysql database. I have a table “systems” from which i can already get the data and update it (with pubsub working). So if I make a change to a system-item, I can see the changes live.
Now I cannot get the app to show live changes for when adding a system-item. The mutation works (so the item gets added to the DB), but I have to refresh the app to show the changes.
I basically followed this guide: https://medium.com/@michaelcbrook/how-to-get-apollo-2-0-working-with-graphql-subscriptions-321388be030c
My relevant parts look as follow (only for adding):
RESOLVERS
Mutation:
addSystemMutation(obj, args, context) {
System.create({ args });
pubsub.publish("addSystemSub", { addSystemSub: args });
return args;
},
Subscription:
addSystemSub: {
subscribe: () => pubsub.asyncIterator('addSystemSub'),
},
SCHEMA
type System {
id: ID
description: String
}
type Query {
systems: [System]
}
type Subscription {
addSystemSub: System
}
type Mutation {
addSystemMutation(id: ID!, description:String): System
}
schema {
query: Query
mutation: Mutation
subscription: Subscription
}
Now in my Body ONCREATED Template i subscribe like this:
this.gqlSubscribe({ query: GET_ALL_SYSTEMS_SUBSCRIPTION, });
Where “GET_ALL_SYSTEMS_SUBSCRIPTION” is:
subscription addSystemSub { addSystemSub { id description } }
I hope this is understandable and someone can help me out. I will gladly provide more info if needed.
Thanks in Advance
Chris