From fcdf68ea153e5d524b964ce23b114805b7201eec Mon Sep 17 00:00:00 2001 From: Andrew Bastin Date: Sat, 18 Sep 2021 23:53:45 +0530 Subject: [PATCH] fix: teams list not properly showing --- .../hoppscotch-app/components/teams/index.vue | 148 ++++++++---------- packages/hoppscotch-app/helpers/apollo.ts | 41 +++++ 2 files changed, 105 insertions(+), 84 deletions(-) diff --git a/packages/hoppscotch-app/components/teams/index.vue b/packages/hoppscotch-app/components/teams/index.vue index 347204085..9b39f03d7 100644 --- a/packages/hoppscotch-app/components/teams/index.vue +++ b/packages/hoppscotch-app/components/teams/index.vue @@ -5,7 +5,7 @@
-

+

{{ $t("state.loading") }}

-
+
help_outline {{ $t("empty.teams") }}
-
+
+ - diff --git a/packages/hoppscotch-app/helpers/apollo.ts b/packages/hoppscotch-app/helpers/apollo.ts index 3e9084fa0..5724bd67d 100644 --- a/packages/hoppscotch-app/helpers/apollo.ts +++ b/packages/hoppscotch-app/helpers/apollo.ts @@ -2,11 +2,16 @@ import { ApolloClient, HttpLink, InMemoryCache, + QueryOptions, + OperationVariables, split, + ApolloError, + isApolloError as _isApolloError } from "@apollo/client/core" import { WebSocketLink } from "@apollo/client/link/ws" import { setContext } from "@apollo/client/link/context" import { getMainDefinition } from "@apollo/client/utilities" +import { ref, onMounted, onBeforeUnmount, Ref } from "@nuxtjs/composition-api" import { authIdToken$ } from "./fb/auth" let authToken: String | null = null @@ -84,3 +89,39 @@ export const apolloClient = new ApolloClient({ }, }, }) + +export function isApolloError(x: any): x is ApolloError { + return _isApolloError(x) +} + +export function useGQLQuery( + options: QueryOptions +): { loading: Ref; data: Ref } { + const loading = ref(true) + const data = ref() + + let subscription: ZenObservable.Subscription | null = null + + onMounted(() => { + subscription = apolloClient.watchQuery(options).subscribe((result) => { + if (result.error) { + data.value = result.error + } else { + data.value = result.data + } + + loading.value = false + }) + }) + + onBeforeUnmount(() => { + if (subscription) { + subscription.unsubscribe() + } + }) + + return { + loading, + data, + } +}