From da5d1132d155781e380b6a56ebb38a23bd77960c Mon Sep 17 00:00:00 2001 From: Pujit Mehrotra Date: Thu, 14 Nov 2024 09:47:37 -0500 Subject: [PATCH] chore(web): remove noisy console log in apollo disable link --- web/helpers/create-apollo-client.ts | 55 ++++++++++++----------------- 1 file changed, 23 insertions(+), 32 deletions(-) diff --git a/web/helpers/create-apollo-client.ts b/web/helpers/create-apollo-client.ts index ab4c5afe4..34b48c527 100644 --- a/web/helpers/create-apollo-client.ts +++ b/web/helpers/create-apollo-client.ts @@ -1,22 +1,23 @@ import { - from, ApolloClient, + ApolloLink, createHttpLink, + from, + Observable, split, - ApolloLink, Observable } from "@apollo/client/core/index.js"; - -import { onError } from "@apollo/client/link/error/index.js"; -import { RetryLink } from "@apollo/client/link/retry/index.js"; -import { GraphQLWsLink } from "@apollo/client/link/subscriptions/index.js"; -import { getMainDefinition } from "@apollo/client/utilities/index.js"; -import { provideApolloClient } from "@vue/apollo-composable"; -import { createClient } from "graphql-ws"; -import { WEBGUI_GRAPHQL } from "./urls"; -import { createApolloCache } from "./apollo-cache"; -import { useServerStore } from "~/store/server"; +} from '@apollo/client/core/index.js'; +import { onError } from '@apollo/client/link/error/index.js'; +import { RetryLink } from '@apollo/client/link/retry/index.js'; +import { GraphQLWsLink } from '@apollo/client/link/subscriptions/index.js'; +import { getMainDefinition } from '@apollo/client/utilities/index.js'; +import { provideApolloClient } from '@vue/apollo-composable'; +import { useServerStore } from '~/store/server'; +import { createClient } from 'graphql-ws'; +import { createApolloCache } from './apollo-cache'; +import { WEBGUI_GRAPHQL } from './urls'; const httpEndpoint = WEBGUI_GRAPHQL; -const wsEndpoint = new URL(WEBGUI_GRAPHQL.toString().replace("http", "ws")); +const wsEndpoint = new URL(WEBGUI_GRAPHQL.toString().replace('http', 'ws')); // const headers = { 'x-api-key': serverStore.apiKey }; const headers = {}; @@ -24,7 +25,7 @@ const headers = {}; const httpLink = createHttpLink({ uri: httpEndpoint.toString(), headers, - credentials: "include", + credentials: 'include', }); const wsLink = new GraphQLWsLink( @@ -41,12 +42,9 @@ const errorLink = onError(({ graphQLErrors, networkError }: any) => { if (graphQLErrors) { // eslint-disable-next-line @typescript-eslint/no-explicit-any graphQLErrors.map((error: any) => { - console.error("[GraphQL error]", error); - const errorMsg = - error.error && error.error.message - ? error.error.message - : error.message; - if (errorMsg && errorMsg.includes("offline")) { + console.error('[GraphQL error]', error); + const errorMsg = error.error && error.error.message ? error.error.message : error.message; + if (errorMsg && errorMsg.includes('offline')) { // @todo restart the api } return error.message; @@ -56,11 +54,8 @@ const errorLink = onError(({ graphQLErrors, networkError }: any) => { if (networkError) { console.error(`[Network error]: ${networkError}`); const msg = networkError.message ? networkError.message : networkError; - if ( - typeof msg === "string" && - msg.includes("Unexpected token < in JSON at position 0") - ) { - return "Unraid API • CORS Error"; + if (typeof msg === 'string' && msg.includes('Unexpected token < in JSON at position 0')) { + return 'Unraid API • CORS Error'; } return msg; } @@ -82,11 +77,10 @@ const retryLink = new RetryLink({ const disableClientLink = new ApolloLink((operation, forward) => { const serverStore = useServerStore(); - const { connectPluginInstalled, guid} = toRefs(serverStore); - console.log("serverStore.connectPluginInstalled", connectPluginInstalled?.value, guid?.value); + const { connectPluginInstalled } = toRefs(serverStore); if (!connectPluginInstalled?.value) { return new Observable((observer) => { - console.warn("connectPluginInstalled is false, aborting request"); + console.warn('connectPluginInstalled is false, aborting request'); observer.complete(); }); } @@ -96,10 +90,7 @@ const disableClientLink = new ApolloLink((operation, forward) => { const splitLinks = split( ({ query }) => { const definition = getMainDefinition(query); - return ( - definition.kind === "OperationDefinition" && - definition.operation === "subscription" - ); + return definition.kind === 'OperationDefinition' && definition.operation === 'subscription'; }, wsLink, httpLink