From 2dc0209a84d9c6863513eb8b4c6c8e70ee18ba7e Mon Sep 17 00:00:00 2001 From: Vicary A Date: Sat, 22 Jul 2023 15:36:40 +0800 Subject: [PATCH] feat(gqty): remove default return from resolve() --- packages/gqty/src/Client/resolvers.ts | 20 ++++++-------------- 1 file changed, 6 insertions(+), 14 deletions(-) diff --git a/packages/gqty/src/Client/resolvers.ts b/packages/gqty/src/Client/resolvers.ts index 8134b784e..eda76635f 100644 --- a/packages/gqty/src/Client/resolvers.ts +++ b/packages/gqty/src/Client/resolvers.ts @@ -4,7 +4,6 @@ import { type Cache } from '../Cache'; import { type GQtyError, type RetryOptions } from '../Error'; import { type ScalarsEnumsHash, type Schema } from '../Schema'; import { type Selection } from '../Selection'; -import { pick } from '../Utils/pick'; import { addSelections, delSelectionsSet, getSelectionsSet } from './batching'; import { createContext, type SchemaContext } from './context'; import { type Debugger } from './debugger'; @@ -85,7 +84,7 @@ export type ResolveFn = < >( fn: DataFn, options?: ResolveOptions -) => Promise>; +) => Promise; const asyncItDoneMessage = { done: true } as IteratorResult; @@ -94,18 +93,12 @@ export type SubscribeFn = < >( fn: DataFn, options?: SubscribeOptions -) => AsyncGenerator, void, unknown> & { +) => AsyncGenerator & { unsubscribe: Unsubscribe; }; export type DataFn = (schema: TSchema) => TResult; -export type DataResult = TData extends undefined - ? TData - : TData extends void - ? unknown - : TData; - export type CreateResolverOptions = { /** * Defines how a query should fetch from the cache and network. @@ -410,12 +403,11 @@ export const createResolvers = ({ createResolver, resolve: async (fn, options) => { - const { accessor, resolve, selections } = createResolver(options); - - fn(accessor) as unknown; + const { accessor, resolve } = createResolver(options); + const dataFn = () => fn(accessor); - const dataFn = () => - ((fn(accessor) as unknown) ?? pick(accessor, selections)) as any; + // Run once to trigger selections + dataFn(); const fetchPromise = resolve().then(dataFn);