1

I have a SubscribeToMore subscription and I want it to update my query. I see the result of my subscription, but the query isn't updated after the return statement and the app is tucked in the loading state. Here is my query with the subscription:

cartProducts: {
  query: GET_CART_PRODUCTS,
  loadingKey: "loading",
  subscribeToMore: {
    document: ON_TRANSACTION_CHANGED,
    updateQuery(previousResult: any, { subscriptionData }: any) {
      const oldTransactions = previousResult.cartProducts.items;
      const newTransaction = subscriptionData.data.onTransactionChanged;
      const concatItems = [...oldTransactions, newTransaction];
      console.log("concatItems:", concatItems);
      return {
        cartProducts: {
          items: concatItems,
          __typename: "PaginatedTransaction",
        },
        __typename: "PaginatedTransaction",
      };
    },
    variables() {
      return {
        profileId: this.profile.profileId,
      };
    },
    skip() {
      return !this.profile?.profileId;
    },
  },
},

concatItems variable has correct data, but if I remove loadingKey and try to log cartProducts after making a subscription call, it's not updated. What am I doing wrong? Thanx in advance! Let me know if you need more info about my setup to understand the case.

Dvdgld
  • 1,984
  • 2
  • 15
  • 41

0 Answers0