-
wonderful, on the subscription, where is the subscription query coming from?, is it using the advanced aspect's resolve function's query or there should be a resolve function in that example in the subscription aspect?
Edited by Emmanuel Mahuni -
The
subscribe
andunsubscribe
functions are pseudo placements for some code at your desire. So this is an example for using thesupply
method with somesubscribe(variables, callback)
andunsubscribe()
function headers where thecallback
should be called whenever new data arrives for the subscription.Another example would be something like this:
export const subscription = new Aspect({ variables({state}) { return {some: state.someData}; }, supply({variables, isInitial}) { // update subscription variables (e.g. re-subscribing) if (isInitial) { mySubscriptionHandler.init(variables); mySubscriptionHandler.on("data", data => this.inject(data)); mySubscriptionHandler.on("error", err => this.inject(null, err)); } else { mySubscriptionHandler.update(variables); } }, disable() { mySubscriptionHandler.close(); }, });
where
mySubscriptionHandler
needs to be implemented according to your needs; vuex-aspect does not know nor force which sort of communication you're using. It could be some GraphQL, HTTP/2, long polling or websocket connection that you utilize to implement the actual subscription. Vuex-aspect just ties the received data onto the vuex store and provides variable reactivity for your subscription code to react to ;-)As I used apollo for the non-subscription examples, I probably should have made a similar example for the subscription o.O But I actually do not have collected any experience with GraphQL subscriptions yet, so any improvements from those who do have are welcome :-)
Please register or sign in to comment