sasakiassociates / speckle

JavaScript client for the Speckle API
15 stars 1 forks source link

Add support for GraphQL subscriptions to support callbacks such as 'userStreamAdded' #3

Open gouldingken opened 1 year ago

gouldingken commented 1 year ago

https://www.apollographql.com/docs/react/data/subscriptions/

Reference TheMain.vue for an example use case we would want to replicate.

apollo: {
    $subscribe: {
      userStreamAdded: {
        query: gql`
          subscription userStreamAdded {
            userStreamAdded
          }
        `,
        result({ data }) {
          if (!data || !data.userStreamAdded) return
          if (this.$route.params.streamId === data.userStreamAdded.id) return
          this.$eventHub.$emit('notification', {
            text: `You've got a new stream!`,
            action: {
              name: 'View Stream',
              to: `/streams/${data.userStreamAdded.id}`
            }
          })
        },
        skip() {
          return !this.isLoggedIn
        }
      }
    }
  },