Skip to content
  • 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
  • Author

    The subscribe and unsubscribe functions are pseudo placements for some code at your desire. So this is an example for using the supply method with some subscribe(variables, callback) and unsubscribe() function headers where the callback 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 :-)

  • Yah I got it eventually, sorry didn't update this. Thanks.

0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment