From 1f50c1b8902fd16082593b8b360094c87c77fbd2 Mon Sep 17 00:00:00 2001 From: DarkSky <25152247+darkskygit@users.noreply.github.com> Date: Mon, 15 Jul 2024 17:24:43 +0800 Subject: [PATCH] fix: handle gql error correctly (#7507) --- .../frontend/core/src/providers/swr-config-provider.tsx | 2 +- packages/frontend/graphql/src/error.ts | 7 ++++++- packages/frontend/graphql/src/fetcher.ts | 2 +- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/packages/frontend/core/src/providers/swr-config-provider.tsx b/packages/frontend/core/src/providers/swr-config-provider.tsx index 3bdae875f8..4abffaf6ac 100644 --- a/packages/frontend/core/src/providers/swr-config-provider.tsx +++ b/packages/frontend/core/src/providers/swr-config-provider.tsx @@ -1,6 +1,6 @@ import { notify } from '@affine/component'; +import { GraphQLError } from '@affine/graphql'; import { assertExists } from '@blocksuite/global/utils'; -import { GraphQLError } from 'graphql'; import type { PropsWithChildren, ReactNode } from 'react'; import { useCallback } from 'react'; import type { SWRConfiguration } from 'swr'; diff --git a/packages/frontend/graphql/src/error.ts b/packages/frontend/graphql/src/error.ts index aee5571e67..6358d43939 100644 --- a/packages/frontend/graphql/src/error.ts +++ b/packages/frontend/graphql/src/error.ts @@ -26,7 +26,12 @@ export class UserFriendlyError implements UserFriendlyErrorResponse { return new UserFriendlyError(response.extensions); } - if (typeof response === 'object' && response.type && response.name) { + if ( + response && + typeof response === 'object' && + response.type && + response.name + ) { return new UserFriendlyError(response); } diff --git a/packages/frontend/graphql/src/fetcher.ts b/packages/frontend/graphql/src/fetcher.ts index 0e721a98bd..b44e46dd04 100644 --- a/packages/frontend/graphql/src/fetcher.ts +++ b/packages/frontend/graphql/src/fetcher.ts @@ -1,7 +1,7 @@ import type { ExecutionResult } from 'graphql'; -import { GraphQLError } from 'graphql'; import { isNil, isObject, merge } from 'lodash-es'; +import { GraphQLError } from './error'; import type { GraphQLQuery } from './graphql'; import type { Mutations, Queries } from './schema';