From 619b0d1e6256ff2c0b67ba7dd263f787fcba6b36 Mon Sep 17 00:00:00 2001 From: Caleb Cox Date: Sun, 4 Jul 2021 16:42:21 -0500 Subject: [PATCH 1/2] types: Single key result with __typename still counts as single key (#1163) Previously, a response with a single key and a __typename field would not be considered as having a single key and could not be automatically extracted by useQuery. --- packages/vue-apollo-composable/src/util/ExtractSingleKey.ts | 2 +- .../tests/fixtures/graphql-example-types.ts | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/vue-apollo-composable/src/util/ExtractSingleKey.ts b/packages/vue-apollo-composable/src/util/ExtractSingleKey.ts index 2f20fb8..ff98ca8 100644 --- a/packages/vue-apollo-composable/src/util/ExtractSingleKey.ts +++ b/packages/vue-apollo-composable/src/util/ExtractSingleKey.ts @@ -6,4 +6,4 @@ export type IsUnion = U extends any ? ([T] extends [U] ? false : true) /** * Extracts an inner type if T has a single key K, otherwise it returns T. */ -export type ExtractSingleKey = IsUnion extends true ? T : T[K] +export type ExtractSingleKey> = IsUnion extends true ? T : T[KWithoutTypename] diff --git a/packages/vue-apollo-composable/tests/fixtures/graphql-example-types.ts b/packages/vue-apollo-composable/tests/fixtures/graphql-example-types.ts index e20b7b6..5a7ae69 100644 --- a/packages/vue-apollo-composable/tests/fixtures/graphql-example-types.ts +++ b/packages/vue-apollo-composable/tests/fixtures/graphql-example-types.ts @@ -71,12 +71,14 @@ export interface ExampleUpdatedSubscriptionVariables { } export interface SingleKeyExampleQuery { + __typename?: 'Root' example?: { __typename?: 'Example' } } export interface MultiKeyExampleQuery { + __typename?: 'Root' example?: { __typename?: 'Example' } From 689c2842075922390366adc0e2f471a87e6eb17f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yannik=20R=C3=B6del?= Date: Sun, 4 Jul 2021 23:43:15 +0200 Subject: [PATCH 2/2] fix(composable): Clear previous error when recieving a result (#1120) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Yannik Rödel --- packages/vue-apollo-composable/src/useQuery.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/packages/vue-apollo-composable/src/useQuery.ts b/packages/vue-apollo-composable/src/useQuery.ts index 67da52c..da28335 100644 --- a/packages/vue-apollo-composable/src/useQuery.ts +++ b/packages/vue-apollo-composable/src/useQuery.ts @@ -250,6 +250,10 @@ export function useQueryImpl< } function onNextResult (queryResult: ApolloQueryResult) { + // Remove any previous error that may still be present from the last fetch (so result handlers + // don't receive old errors that may not even be applicable anymore). + error.value = null + processNextResult(queryResult) // Result errors