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);