diff --git a/libs/positions/src/lib/positions-data-providers.ts b/libs/positions/src/lib/positions-data-providers.ts index 69ddf8239..99aaa9efb 100644 --- a/libs/positions/src/lib/positions-data-providers.ts +++ b/libs/positions/src/lib/positions-data-providers.ts @@ -150,7 +150,7 @@ export const getMetrics = ( ) && generalAccountBalance.isLessThan(marginInitial.minus(marginSearch)); metrics.push({ - marketName: market.tradableInstrument.instrument.name + ' ' + market.id, + marketName: market.tradableInstrument.instrument.name, averageEntryPrice: position.averageEntryPrice, marginAccountBalance: marginAccount.balance, capitalUtilisation: Math.round(capitalUtilisation.toNumber()), diff --git a/libs/react-helpers/src/lib/apollo-client.ts b/libs/react-helpers/src/lib/apollo-client.ts index 20bb254b8..bf7dda2fa 100644 --- a/libs/react-helpers/src/lib/apollo-client.ts +++ b/libs/react-helpers/src/lib/apollo-client.ts @@ -2,6 +2,7 @@ import type { ApolloError } from '@apollo/client'; import type { GraphQLErrors } from '@apollo/client/errors'; const NOT_FOUND = 'NotFound'; +const INTERNAL = 'Internal'; const isApolloGraphQLError = ( error: ApolloError | Error | undefined @@ -9,21 +10,33 @@ const isApolloGraphQLError = ( return !!error && !!(error as ApolloError).graphQLErrors; }; -const hasNotFoundGraphQLErrors = (errors: GraphQLErrors, path?: string) => { +const hasNotFoundGraphQLErrors = (errors: GraphQLErrors, path?: string[]) => { return errors.some( (e) => e.extensions && e.extensions['type'] === NOT_FOUND && - (!path || e.path?.[0] === path) + (!path || path.every((item, i) => item === e?.path?.[i])) ); }; export const isNotFoundGraphQLError = ( error: Error | ApolloError | undefined, - path?: string + path?: string[] ) => { return ( isApolloGraphQLError(error) && hasNotFoundGraphQLErrors(error.graphQLErrors, path) ); }; + +export const isOnlyMarketDataNotFoundErrors = ( + errors: GraphQLErrors, + path?: string[] +) => { + return errors.every( + (e) => + e.extensions && + e.extensions['type'] === INTERNAL && + (!path || path.every((item, i) => item === e?.path?.[i])) + ); +}; diff --git a/libs/react-helpers/src/lib/generic-data-provider.ts b/libs/react-helpers/src/lib/generic-data-provider.ts index b45024858..f1d831ff5 100644 --- a/libs/react-helpers/src/lib/generic-data-provider.ts +++ b/libs/react-helpers/src/lib/generic-data-provider.ts @@ -5,10 +5,14 @@ import type { OperationVariables, TypedDocumentNode, FetchResult, + ErrorPolicy, } from '@apollo/client'; import type { Subscription } from 'zen-observable-ts'; import isEqual from 'lodash/isEqual'; -import { isNotFoundGraphQLError } from './apollo-client'; +import { + isNotFoundGraphQLError, + isOnlyMarketDataNotFoundErrors, +} from './apollo-client'; import type * as Schema from '@vegaprotocol/types'; interface UpdateData { delta?: Delta; @@ -313,15 +317,29 @@ function makeDataProviderInternal< if (!client) { return; } - try { - const res = await client.query({ + + const call = (policy?: ErrorPolicy) => + client.query({ query, variables: pagination ? { ...variables, pagination: { first: pagination.first } } : variables, fetchPolicy: fetchPolicy || 'no-cache', context: additionalContext, + errorPolicy: policy || 'none', }); + + try { + const res = (await call().catch((err) => { + if ( + err.graphQLErrors && + isOnlyMarketDataNotFoundErrors(err.graphQLErrors, ['market', 'data']) + ) { + return call('ignore'); + } else { + throw err; + } + })); data = getData(res.data, variables); if (data && pagination) { if (!(data instanceof Array)) { @@ -355,7 +373,7 @@ function makeDataProviderInternal< } loaded = true; } catch (e) { - if (isNotFoundGraphQLError(e as Error, 'party')) { + if (isNotFoundGraphQLError(e as Error, ['party'])) { data = getData(null, variables); loaded = true; return;