Skip to content

Commit

Permalink
feat(gqty): remove default return from resolve()
Browse files Browse the repository at this point in the history
  • Loading branch information
vicary committed Aug 26, 2023
1 parent 50e2117 commit 2dc0209
Showing 1 changed file with 6 additions and 14 deletions.
20 changes: 6 additions & 14 deletions packages/gqty/src/Client/resolvers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -85,7 +84,7 @@ export type ResolveFn<TSchema extends BaseGeneratedSchema> = <
>(
fn: DataFn<TSchema, TData>,
options?: ResolveOptions
) => Promise<DataResult<TData>>;
) => Promise<TData>;

const asyncItDoneMessage = { done: true } as IteratorResult<never>;

Expand All @@ -94,18 +93,12 @@ export type SubscribeFn<TSchema extends BaseGeneratedSchema> = <
>(
fn: DataFn<TSchema, TData>,
options?: SubscribeOptions
) => AsyncGenerator<DataResult<TData>, void, unknown> & {
) => AsyncGenerator<TData, void, unknown> & {
unsubscribe: Unsubscribe;
};

export type DataFn<TSchema, TResult = unknown> = (schema: TSchema) => TResult;

export type DataResult<TData = unknown> = TData extends undefined
? TData
: TData extends void
? unknown
: TData;

export type CreateResolverOptions = {
/**
* Defines how a query should fetch from the cache and network.
Expand Down Expand Up @@ -410,12 +403,11 @@ export const createResolvers = <TSchema extends BaseGeneratedSchema>({
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);

Expand Down

0 comments on commit 2dc0209

Please sign in to comment.