* fix(#2200): handle NotFound GraphQL errors in async renderer * fix(#2200): data provider filter apollo graphQL not found error * fix(#2200): update apollo-client to not report not found error link * fix(#2200): fix log on not found error link * fix(#2200): fix set error in data provider * fix(#2200): extensions type access via index signature * fix(#2200): log gql errors that are not NotFound and still throw error in data provider * fix: remove unused import
This commit is contained in:
parent
02a8a8d9ec
commit
fe447167ca
@ -1,4 +1,4 @@
|
|||||||
import type { InMemoryCacheConfig } from '@apollo/client';
|
import type { ApolloError, InMemoryCacheConfig } from '@apollo/client';
|
||||||
import {
|
import {
|
||||||
ApolloClient,
|
ApolloClient,
|
||||||
from,
|
from,
|
||||||
@ -13,9 +13,12 @@ import { createClient as createWSClient } from 'graphql-ws';
|
|||||||
import { onError } from '@apollo/client/link/error';
|
import { onError } from '@apollo/client/link/error';
|
||||||
import { RetryLink } from '@apollo/client/link/retry';
|
import { RetryLink } from '@apollo/client/link/retry';
|
||||||
import ApolloLinkTimeout from 'apollo-link-timeout';
|
import ApolloLinkTimeout from 'apollo-link-timeout';
|
||||||
|
import type { GraphQLErrors } from '@apollo/client/errors';
|
||||||
|
|
||||||
const isBrowser = typeof window !== 'undefined';
|
const isBrowser = typeof window !== 'undefined';
|
||||||
|
|
||||||
|
const NOT_FOUND = 'NotFound';
|
||||||
|
|
||||||
export function createClient(base?: string, cacheConfig?: InMemoryCacheConfig) {
|
export function createClient(base?: string, cacheConfig?: InMemoryCacheConfig) {
|
||||||
if (!base) {
|
if (!base) {
|
||||||
throw new Error('Base must be passed into createClient!');
|
throw new Error('Base must be passed into createClient!');
|
||||||
@ -61,8 +64,16 @@ export function createClient(base?: string, cacheConfig?: InMemoryCacheConfig) {
|
|||||||
: httpLink;
|
: httpLink;
|
||||||
|
|
||||||
const errorLink = onError(({ graphQLErrors, networkError }) => {
|
const errorLink = onError(({ graphQLErrors, networkError }) => {
|
||||||
if (graphQLErrors) console.log(graphQLErrors);
|
if (graphQLErrors) {
|
||||||
if (networkError) console.log(networkError);
|
graphQLErrors.forEach((e) => {
|
||||||
|
if (e.extensions && e.extensions['type'] !== NOT_FOUND) {
|
||||||
|
console.log(e);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
if (networkError) {
|
||||||
|
console.log(networkError);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
return new ApolloClient({
|
return new ApolloClient({
|
||||||
@ -70,3 +81,21 @@ export function createClient(base?: string, cacheConfig?: InMemoryCacheConfig) {
|
|||||||
cache: new InMemoryCache(cacheConfig),
|
cache: new InMemoryCache(cacheConfig),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const isApolloGraphQLError = (
|
||||||
|
error: ApolloError | Error | undefined
|
||||||
|
): error is ApolloError => {
|
||||||
|
return !!error && !!(error as ApolloError).graphQLErrors;
|
||||||
|
};
|
||||||
|
|
||||||
|
const hasNotFoundGraphQLErrors = (errors: GraphQLErrors) => {
|
||||||
|
return errors.some((e) => e.extensions && e.extensions['type'] === NOT_FOUND);
|
||||||
|
};
|
||||||
|
|
||||||
|
export const isNotFoundGraphQLError = (
|
||||||
|
error: Error | ApolloError | undefined
|
||||||
|
) => {
|
||||||
|
return (
|
||||||
|
isApolloGraphQLError(error) && hasNotFoundGraphQLErrors(error.graphQLErrors)
|
||||||
|
);
|
||||||
|
};
|
||||||
|
@ -46,7 +46,7 @@ export const DealTicketMarketAmount = ({
|
|||||||
<div className="flex items-end gap-4 mb-2">
|
<div className="flex items-end gap-4 mb-2">
|
||||||
<div className="flex-1 text-sm">Size</div>
|
<div className="flex-1 text-sm">Size</div>
|
||||||
<div />
|
<div />
|
||||||
<div className="flex-1 text-sm text-right">
|
<div className="flex-2 text-sm text-right">
|
||||||
{isMarketInAuction(market) && (
|
{isMarketInAuction(market) && (
|
||||||
<Tooltip
|
<Tooltip
|
||||||
description={t(
|
description={t(
|
||||||
|
@ -29,7 +29,12 @@ export const FillsManager = ({ partyId }: FillsManagerProps) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<AsyncRenderer loading={loading} error={error} data={data}>
|
<AsyncRenderer
|
||||||
|
loading={loading}
|
||||||
|
error={error}
|
||||||
|
data={data}
|
||||||
|
noDataCondition={() => false}
|
||||||
|
>
|
||||||
<FillsTable
|
<FillsTable
|
||||||
ref={gridRef}
|
ref={gridRef}
|
||||||
partyId={partyId}
|
partyId={partyId}
|
||||||
|
@ -25,7 +25,13 @@ export const PositionsManager = ({ partyId }: PositionsManagerProps) => {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<AsyncRenderer loading={loading} error={error} data={data}>
|
<AsyncRenderer
|
||||||
|
loading={loading}
|
||||||
|
error={error}
|
||||||
|
data={data}
|
||||||
|
noDataMessage={t('No positions')}
|
||||||
|
noDataCondition={(data) => !(data && data.length)}
|
||||||
|
>
|
||||||
<PositionsTable
|
<PositionsTable
|
||||||
ref={gridRef}
|
ref={gridRef}
|
||||||
rowData={data}
|
rowData={data}
|
||||||
|
@ -136,7 +136,15 @@ export const useDataProvider = <
|
|||||||
return unsubscribe();
|
return unsubscribe();
|
||||||
};
|
};
|
||||||
}, [client, initialized, dataProvider, callback, variables, skip, update]);
|
}, [client, initialized, dataProvider, callback, variables, skip, update]);
|
||||||
return { data, loading, error, flush, reload, load, totalCount };
|
return {
|
||||||
|
data,
|
||||||
|
loading,
|
||||||
|
error,
|
||||||
|
flush,
|
||||||
|
reload,
|
||||||
|
load,
|
||||||
|
totalCount,
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
export const useThrottledDataProvider = <Data, Delta>(
|
export const useThrottledDataProvider = <Data, Delta>(
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
import { Splash } from '../splash';
|
import { Splash } from '../splash';
|
||||||
import type { ReactNode } from 'react';
|
import type { ReactNode } from 'react';
|
||||||
import { t } from '@vegaprotocol/react-helpers';
|
import { t } from '@vegaprotocol/react-helpers';
|
||||||
|
import { isNotFoundGraphQLError } from '@vegaprotocol/apollo-client';
|
||||||
|
|
||||||
interface AsyncRendererProps<T> {
|
interface AsyncRendererProps<T> {
|
||||||
loading: boolean;
|
loading: boolean;
|
||||||
@ -25,7 +26,7 @@ export function AsyncRenderer<T = object>({
|
|||||||
children,
|
children,
|
||||||
render,
|
render,
|
||||||
}: AsyncRendererProps<T>) {
|
}: AsyncRendererProps<T>) {
|
||||||
if (error) {
|
if (error && !isNotFoundGraphQLError(error)) {
|
||||||
return (
|
return (
|
||||||
<Splash>
|
<Splash>
|
||||||
{errorMessage
|
{errorMessage
|
||||||
|
@ -7,7 +7,7 @@ export interface SplashProps {
|
|||||||
|
|
||||||
export const Splash = ({ children }: SplashProps) => {
|
export const Splash = ({ children }: SplashProps) => {
|
||||||
const splashClasses = classNames(
|
const splashClasses = classNames(
|
||||||
'w-full h-full',
|
'w-full h-full text-xs text-center text-gray-200',
|
||||||
'flex items-center justify-center'
|
'flex items-center justify-center'
|
||||||
);
|
);
|
||||||
return <div className={splashClasses}>{children}</div>;
|
return <div className={splashClasses}>{children}</div>;
|
||||||
|
Loading…
Reference in New Issue
Block a user