From 35bbd6d9d8ffdc5d4602b6eb435ac7f2164fcbb1 Mon Sep 17 00:00:00 2001 From: mizdra Date: Tue, 3 Oct 2023 00:35:36 +0900 Subject: [PATCH 1/2] merge DefaultFieldsResolver and InputFieldsResolver --- README.md | 4 ++-- e2e/index.e2e.ts | 4 ++-- src/__snapshots__/code-generator.test.ts.snap | 18 +++++++-------- src/code-generator.ts | 10 ++++----- src/helper/factory.ts | 22 +++++++------------ src/helper/field-resolver.test.ts | 19 +++------------- src/helper/field-resolver.ts | 12 +++++----- src/helper/index.ts | 2 +- 8 files changed, 35 insertions(+), 56 deletions(-) diff --git a/README.md b/README.md index 6e12d43..48e6cc2 100644 --- a/README.md +++ b/README.md @@ -260,7 +260,7 @@ However, you must prepare a custom `defineFactory` to use Transient Fields import { defineAuthorFactoryInternal, dynamic, - DefaultFieldsResolver, + FieldsResolver, Traits, AuthorFactoryDefineOptions, AuthorFactoryInterface, @@ -272,7 +272,7 @@ type AuthorTransientFields = { bookCount: number; }; function defineAuthorFactoryWithTransientFields< - _DefaultFieldsResolver extends DefaultFieldsResolver, + _DefaultFieldsResolver extends FieldsResolver, _Traits extends Traits, >( options: AuthorFactoryDefineOptions, diff --git a/e2e/index.e2e.ts b/e2e/index.e2e.ts index bfdb2ad..1e0b819 100644 --- a/e2e/index.e2e.ts +++ b/e2e/index.e2e.ts @@ -2,7 +2,7 @@ import { expect, it, describe, assertType, expectTypeOf, vi } from 'vitest'; import { AuthorFactoryDefineOptions, AuthorFactoryInterface, - DefaultFieldsResolver, + FieldsResolver, Traits, defineAuthorFactory, defineAuthorFactoryInternal, @@ -516,7 +516,7 @@ describe('defineTypeFactory', () => { bookCount: number; }; function defineAuthorFactoryWithTransientFields< - _DefaultFieldsResolver extends DefaultFieldsResolver, + _DefaultFieldsResolver extends FieldsResolver, _Traits extends Traits, >( options: AuthorFactoryDefineOptions, diff --git a/src/__snapshots__/code-generator.test.ts.snap b/src/__snapshots__/code-generator.test.ts.snap index 2b20dbb..a826e5d 100644 --- a/src/__snapshots__/code-generator.test.ts.snap +++ b/src/__snapshots__/code-generator.test.ts.snap @@ -5,7 +5,7 @@ exports[`generateCode > generates code 1`] = ` type Traits, type TypeFactoryDefineOptions, type TypeFactoryInterface, - type DefaultFieldsResolver, + type FieldsResolver, defineTypeFactoryInternal, } from '@mizdra/graphql-codegen-typescript-fabbrica/helper'; import type { Maybe, Book, Author } from './types'; @@ -21,19 +21,19 @@ const BookFieldNames = ['id', 'title', 'author'] as const; export type BookFactoryDefineOptions< TransientFields extends Record, - _DefaultFieldsResolver extends DefaultFieldsResolver, + _DefaultFieldsResolver extends FieldsResolver, _Traits extends Traits, > = TypeFactoryDefineOptions; export type BookFactoryInterface< TransientFields extends Record, - _DefaultFieldsResolver extends DefaultFieldsResolver, + _DefaultFieldsResolver extends FieldsResolver, _Traits extends Traits, > = TypeFactoryInterface; export function defineBookFactoryInternal< TransientFields extends Record, - _DefaultFieldsResolver extends DefaultFieldsResolver, + _DefaultFieldsResolver extends FieldsResolver, _Traits extends Traits, >( options: BookFactoryDefineOptions, @@ -48,7 +48,7 @@ export function defineBookFactoryInternal< * @returns factory {@link BookFactoryInterface} */ export function defineBookFactory< - _DefaultFieldsResolver extends DefaultFieldsResolver, + _DefaultFieldsResolver extends FieldsResolver, _Traits extends Traits, >( options: BookFactoryDefineOptions<{}, _DefaultFieldsResolver, _Traits>, @@ -66,19 +66,19 @@ const AuthorFieldNames = ['id', 'name', 'books'] as const; export type AuthorFactoryDefineOptions< TransientFields extends Record, - _DefaultFieldsResolver extends DefaultFieldsResolver, + _DefaultFieldsResolver extends FieldsResolver, _Traits extends Traits, > = TypeFactoryDefineOptions; export type AuthorFactoryInterface< TransientFields extends Record, - _DefaultFieldsResolver extends DefaultFieldsResolver, + _DefaultFieldsResolver extends FieldsResolver, _Traits extends Traits, > = TypeFactoryInterface; export function defineAuthorFactoryInternal< TransientFields extends Record, - _DefaultFieldsResolver extends DefaultFieldsResolver, + _DefaultFieldsResolver extends FieldsResolver, _Traits extends Traits, >( options: AuthorFactoryDefineOptions, @@ -93,7 +93,7 @@ export function defineAuthorFactoryInternal< * @returns factory {@link AuthorFactoryInterface} */ export function defineAuthorFactory< - _DefaultFieldsResolver extends DefaultFieldsResolver, + _DefaultFieldsResolver extends FieldsResolver, _Traits extends Traits, >( options: AuthorFactoryDefineOptions<{}, _DefaultFieldsResolver, _Traits>, diff --git a/src/code-generator.ts b/src/code-generator.ts index f8b8492..e2d496c 100644 --- a/src/code-generator.ts +++ b/src/code-generator.ts @@ -8,7 +8,7 @@ import { type Traits, type TypeFactoryDefineOptions, type TypeFactoryInterface, - type DefaultFieldsResolver, + type FieldsResolver, defineTypeFactoryInternal, } from '@mizdra/graphql-codegen-typescript-fabbrica/helper'; import type { Maybe, ${joinedTypeNames} } from '${config.typesFile}'; @@ -48,19 +48,19 @@ function generateTypeFactoryCode(config: Config, typeInfo: TypeInfo): string { return ` export type ${name}FactoryDefineOptions< TransientFields extends Record, - _DefaultFieldsResolver extends DefaultFieldsResolver, + _DefaultFieldsResolver extends FieldsResolver, _Traits extends Traits, > = TypeFactoryDefineOptions; export type ${name}FactoryInterface< TransientFields extends Record, - _DefaultFieldsResolver extends DefaultFieldsResolver, + _DefaultFieldsResolver extends FieldsResolver, _Traits extends Traits, > = TypeFactoryInterface; export function define${name}FactoryInternal< TransientFields extends Record, - _DefaultFieldsResolver extends ${wrapRequired(`DefaultFieldsResolver`)}, + _DefaultFieldsResolver extends ${wrapRequired(`FieldsResolver`)}, _Traits extends Traits, >( options: ${name}FactoryDefineOptions, @@ -75,7 +75,7 @@ export function define${name}FactoryInternal< * @returns factory {@link ${name}FactoryInterface} */ export function define${name}Factory< - _DefaultFieldsResolver extends ${wrapRequired(`DefaultFieldsResolver`)}, + _DefaultFieldsResolver extends ${wrapRequired(`FieldsResolver`)}, _Traits extends Traits, >( options: ${name}FactoryDefineOptions<{}, _DefaultFieldsResolver, _Traits>, diff --git a/src/helper/factory.ts b/src/helper/factory.ts index 5a450bf..d08c2ab 100644 --- a/src/helper/factory.ts +++ b/src/helper/factory.ts @@ -1,25 +1,19 @@ // MEMO: The tests for this module are covered by `e2e/*.e2e.ts`. -import { - ResolvedFields, - DefaultFieldsResolver, - InputFieldsResolver, - resolveFields, - FieldResolver, -} from './field-resolver.js'; +import { ResolvedFields, FieldsResolver, resolveFields, FieldResolver } from './field-resolver.js'; import { getSequenceCounter, resetSequence } from './sequence.js'; import { Merge, StrictlyPick } from './util.js'; export type Traits, TransientFields extends Record> = { [traitName: string]: { - defaultFields: InputFieldsResolver; + defaultFields: FieldsResolver; }; }; export interface TypeFactoryDefineOptions< OptionalType extends Record, TransientFields extends Record, - _DefaultFieldsResolver extends DefaultFieldsResolver, + _DefaultFieldsResolver extends FieldsResolver, _Traits extends Traits, > { defaultFields: _DefaultFieldsResolver; @@ -36,13 +30,13 @@ export interface TypeFactoryInterface< _Traits extends Traits, > { build(): Promise, ResolvedFields<{}>>, keyof OptionalType>>; - build>( + build>( inputFieldsResolver: T, ): Promise, ResolvedFields>, keyof OptionalType>>; buildList( count: number, ): Promise, ResolvedFields<{}>>, keyof OptionalType>[]>; - buildList>( + buildList>( count: number, inputFieldsResolver: T, ): Promise, ResolvedFields>, keyof OptionalType>[]>; @@ -60,7 +54,7 @@ export interface TypeFactoryInterface< export function defineTypeFactoryInternal< OptionalType extends Record, TransientFields extends Record, - _DefaultFieldsResolver extends DefaultFieldsResolver, + _DefaultFieldsResolver extends FieldsResolver, _Traits extends Traits, >( typeFieldNames: readonly (keyof OptionalType)[], @@ -72,7 +66,7 @@ export function defineTypeFactoryInternal< const seqKey = {}; const getSeq = () => getSequenceCounter(seqKey); return { - async build>( + async build>( inputFieldsResolver?: T, ): Promise, ResolvedFields>, keyof OptionalType>> { const seq = getSeq(); @@ -83,7 +77,7 @@ export function defineTypeFactoryInternal< inputFieldsResolver ?? ({} as T), ); }, - async buildList>( + async buildList>( count: number, inputFieldsResolver?: T, ): Promise, ResolvedFields>, keyof OptionalType>[]> { diff --git a/src/helper/field-resolver.test.ts b/src/helper/field-resolver.test.ts index c70296f..5aa3c8a 100644 --- a/src/helper/field-resolver.test.ts +++ b/src/helper/field-resolver.test.ts @@ -5,8 +5,7 @@ import { type ResolvedField, Dynamic, dynamic, - InputFieldsResolver, - DefaultFieldsResolver, + FieldsResolver, } from './field-resolver.js'; import { DeepOptional, DeepReadonly } from './util.js'; @@ -53,22 +52,10 @@ it('FieldResolver', () => { >(); }); -it('DefaultFieldsResolver', () => { +it('FieldsResolver', () => { type OptionalTypeWithTransientFields = { a: number | undefined; b: OptionalSubType[] | undefined }; type OptionalSubType = { c: number | undefined }; - expectTypeOf>().toEqualTypeOf<{ - a?: number | undefined | Dynamic; - b?: - | readonly { readonly c: number | undefined }[] - | undefined - | Dynamic; - }>(); -}); - -it('InputFieldsResolver', () => { - type OptionalTypeWithTransientFields = { a: number | undefined; b: OptionalSubType[] | undefined }; - type OptionalSubType = { c: number | undefined }; - expectTypeOf>().toEqualTypeOf<{ + expectTypeOf>().toEqualTypeOf<{ a?: number | undefined | Dynamic; b?: | readonly { readonly c: number | undefined }[] diff --git a/src/helper/field-resolver.ts b/src/helper/field-resolver.ts index 76affbd..d0446df 100644 --- a/src/helper/field-resolver.ts +++ b/src/helper/field-resolver.ts @@ -27,16 +27,14 @@ export function dynamic( export type FieldResolver = | Field | Dynamic; -/** The type of `defaultFields` option of `defineFactory` function. */ -export type DefaultFieldsResolver = { + +/** The type of `defaultFields` or `inputFields` option. */ +export type FieldsResolver = { [FieldName in keyof OptionalTypeWithTransientFields]?: FieldResolver< OptionalTypeWithTransientFields, DeepReadonly >; }; -/** The type of `inputFields` option of `build` method. */ -export type InputFieldsResolver = - DefaultFieldsResolver; // eslint-disable-next-line @typescript-eslint/no-unused-vars export type ResolvedField> = T extends FieldResolver @@ -50,8 +48,8 @@ export type ResolvedFields, TransientFields extends Record, - _DefaultFieldsResolver extends DefaultFieldsResolver, - _InputFieldsResolver extends InputFieldsResolver, + _DefaultFieldsResolver extends FieldsResolver, + _InputFieldsResolver extends FieldsResolver, >( fieldNames: readonly (keyof OptionalType)[], seq: number, diff --git a/src/helper/index.ts b/src/helper/index.ts index bb6f8c1..fe97123 100644 --- a/src/helper/index.ts +++ b/src/helper/index.ts @@ -1,3 +1,3 @@ -export { DefaultFieldsResolver, dynamic } from './field-resolver.js'; +export { FieldsResolver, dynamic } from './field-resolver.js'; export { resetAllSequence, resetSequence } from './sequence.js'; export { Traits, TypeFactoryDefineOptions, TypeFactoryInterface, defineTypeFactoryInternal } from './factory.js'; From 077a10bf0df0c8a04c78d2009085dd403ae4612f Mon Sep 17 00:00:00 2001 From: mizdra Date: Tue, 3 Oct 2023 00:38:29 +0900 Subject: [PATCH 2/2] OptionalType => Type --- src/helper/factory.ts | 66 +++++++++++++------------------ src/helper/field-resolver.test.ts | 50 +++++++++++------------ src/helper/field-resolver.ts | 56 ++++++++++++-------------- 3 files changed, 79 insertions(+), 93 deletions(-) diff --git a/src/helper/factory.ts b/src/helper/factory.ts index d08c2ab..d08750a 100644 --- a/src/helper/factory.ts +++ b/src/helper/factory.ts @@ -4,87 +4,77 @@ import { ResolvedFields, FieldsResolver, resolveFields, FieldResolver } from './ import { getSequenceCounter, resetSequence } from './sequence.js'; import { Merge, StrictlyPick } from './util.js'; -export type Traits, TransientFields extends Record> = { +export type Traits, TransientFields extends Record> = { [traitName: string]: { - defaultFields: FieldsResolver; + defaultFields: FieldsResolver; }; }; export interface TypeFactoryDefineOptions< - OptionalType extends Record, + Type extends Record, TransientFields extends Record, - _DefaultFieldsResolver extends FieldsResolver, - _Traits extends Traits, + _DefaultFieldsResolver extends FieldsResolver, + _Traits extends Traits, > { defaultFields: _DefaultFieldsResolver; traits?: _Traits; } export interface TypeFactoryInterface< - OptionalType extends Record, + Type extends Record, TransientFields extends Record, // NOTE: The constraints of _DefaultFieldsResolver are loose so that `Merge<_DefaultFieldsResolver, _Traits[T]['defaultFields']>` is accepted. - _DefaultFieldsResolver extends Partial< - Record> - >, - _Traits extends Traits, + _DefaultFieldsResolver extends Partial>>, + _Traits extends Traits, > { - build(): Promise, ResolvedFields<{}>>, keyof OptionalType>>; - build>( + build(): Promise, ResolvedFields<{}>>, keyof Type>>; + build>( inputFieldsResolver: T, - ): Promise, ResolvedFields>, keyof OptionalType>>; + ): Promise, ResolvedFields>, keyof Type>>; buildList( count: number, - ): Promise, ResolvedFields<{}>>, keyof OptionalType>[]>; - buildList>( + ): Promise, ResolvedFields<{}>>, keyof Type>[]>; + buildList>( count: number, inputFieldsResolver: T, - ): Promise, ResolvedFields>, keyof OptionalType>[]>; + ): Promise, ResolvedFields>, keyof Type>[]>; use( traitName: T, - ): TypeFactoryInterface< - OptionalType, - TransientFields, - Merge<_DefaultFieldsResolver, _Traits[T]['defaultFields']>, - _Traits - >; + ): TypeFactoryInterface, _Traits>; resetSequence(): void; } export function defineTypeFactoryInternal< - OptionalType extends Record, + Type extends Record, TransientFields extends Record, - _DefaultFieldsResolver extends FieldsResolver, - _Traits extends Traits, + _DefaultFieldsResolver extends FieldsResolver, + _Traits extends Traits, >( - typeFieldNames: readonly (keyof OptionalType)[], + typeFieldNames: readonly (keyof Type)[], { defaultFields: defaultFieldsResolver, traits, - }: TypeFactoryDefineOptions, -): TypeFactoryInterface { + }: TypeFactoryDefineOptions, +): TypeFactoryInterface { const seqKey = {}; const getSeq = () => getSequenceCounter(seqKey); return { - async build>( + async build>( inputFieldsResolver?: T, - ): Promise, ResolvedFields>, keyof OptionalType>> { + ): Promise, ResolvedFields>, keyof Type>> { const seq = getSeq(); - return resolveFields( + return resolveFields( typeFieldNames, seq, defaultFieldsResolver, inputFieldsResolver ?? ({} as T), ); }, - async buildList>( + async buildList>( count: number, inputFieldsResolver?: T, - ): Promise, ResolvedFields>, keyof OptionalType>[]> { - const array: StrictlyPick< - Merge, ResolvedFields>, - keyof OptionalType - >[] = []; + ): Promise, ResolvedFields>, keyof Type>[]> { + const array: StrictlyPick, ResolvedFields>, keyof Type>[] = []; for (let i = 0; i < count; i++) { if (inputFieldsResolver) { // eslint-disable-next-line no-await-in-loop, @typescript-eslint/no-explicit-any @@ -99,7 +89,7 @@ export function defineTypeFactoryInternal< use( traitName: T, ): TypeFactoryInterface< - OptionalType, + Type, TransientFields, Merge<_DefaultFieldsResolver, _Traits[T]['defaultFields']>, _Traits diff --git a/src/helper/field-resolver.test.ts b/src/helper/field-resolver.test.ts index 5aa3c8a..d545f1b 100644 --- a/src/helper/field-resolver.test.ts +++ b/src/helper/field-resolver.test.ts @@ -10,16 +10,16 @@ import { import { DeepOptional, DeepReadonly } from './util.js'; it('Dynamic', async () => { - type OptionalTypeWithTransientFields = { id: string | undefined; a: number | undefined }; + type TypeWithTransientFields = { id: string | undefined; a: number | undefined }; type Field = string; - const readonlyOptionalType: DeepReadonly> = { + const readonlyType: DeepReadonly> = { id: '', a: 1, }; - const get = async (fieldName: FieldName) => - Promise.resolve(readonlyOptionalType[fieldName]); + const get = async (fieldName: FieldName) => + Promise.resolve(readonlyType[fieldName]); - const dynamic1 = new Dynamic(({ seq }) => `Book-${seq}`); + const dynamic1 = new Dynamic(({ seq }) => `Book-${seq}`); expect(await dynamic1.get({ seq: 0, get })).toBe('Book-0'); const dynamic2 = new Dynamic(async ({ seq }) => Promise.resolve(`Book-${seq}`)); @@ -27,58 +27,58 @@ it('Dynamic', async () => { }); it('dynamic', async () => { - type OptionalTypeWithTransientFields = { id: string | undefined; a: number | undefined }; + type TypeWithTransientFields = { id: string | undefined; a: number | undefined }; type Field = string; - const readonlyOptionalType: DeepReadonly> = { + const readonlyType: DeepReadonly> = { id: '', a: 1, }; - const get = async (fieldName: FieldName) => - Promise.resolve(readonlyOptionalType[fieldName]); + const get = async (fieldName: FieldName) => + Promise.resolve(readonlyType[fieldName]); - const l1 = dynamic(({ seq }) => `Book-${seq}`); + const l1 = dynamic(({ seq }) => `Book-${seq}`); expect(l1).instanceOf(Dynamic); expect(await l1.get({ seq: 0, get })).toBe('Book-0'); - const l2 = dynamic(async ({ seq }) => Promise.resolve(`Book-${seq}`)); + const l2 = dynamic(async ({ seq }) => Promise.resolve(`Book-${seq}`)); expect(l2).instanceOf(Dynamic); expect(await l2.get({ seq: 0, get })).toBe('Book-0'); }); it('FieldResolver', () => { - type OptionalTypeWithTransientFields = { a: number }; - expectTypeOf>().toEqualTypeOf< + type TypeWithTransientFields = { a: number }; + expectTypeOf>().toEqualTypeOf< number | Dynamic<{ a: number }, number> >(); }); it('FieldsResolver', () => { - type OptionalTypeWithTransientFields = { a: number | undefined; b: OptionalSubType[] | undefined }; + type TypeWithTransientFields = { a: number | undefined; b: OptionalSubType[] | undefined }; type OptionalSubType = { c: number | undefined }; - expectTypeOf>().toEqualTypeOf<{ - a?: number | undefined | Dynamic; + expectTypeOf>().toEqualTypeOf<{ + a?: number | undefined | Dynamic; b?: | readonly { readonly c: number | undefined }[] | undefined - | Dynamic; + | Dynamic; }>(); }); it('ResolvedField', () => { - type OptionalTypeWithTransientFields = { a: number | undefined }; + type TypeWithTransientFields = { a: number | undefined }; expectTypeOf>().toEqualTypeOf(); - expectTypeOf< - ResolvedField> - >().toEqualTypeOf(); + expectTypeOf>>().toEqualTypeOf< + number | undefined + >(); }); it('ResolvedFields', () => { - type OptionalTypeWithTransientFields = { a: number | undefined }; + type TypeWithTransientFields = { a: number | undefined }; expectTypeOf< ResolvedFields<{ - a: FieldResolver; - b: FieldResolver; - c: FieldResolver; + a: FieldResolver; + b: FieldResolver; + c: FieldResolver; }> >().toEqualTypeOf<{ a: number; diff --git a/src/helper/field-resolver.ts b/src/helper/field-resolver.ts index d0446df..8c135d2 100644 --- a/src/helper/field-resolver.ts +++ b/src/helper/field-resolver.ts @@ -1,38 +1,34 @@ import { DeepReadonly, Merge, StrictlyPick } from './util.js'; -export type FieldResolverOptions = { +export type FieldResolverOptions = { seq: number; - get: ( + get: ( fieldName: FieldName, - ) => Promise | undefined>; + ) => Promise | undefined>; }; -export class Dynamic { +export class Dynamic { constructor( - private readonly factory: ( - options: FieldResolverOptions, - ) => Field | Promise, + private readonly factory: (options: FieldResolverOptions) => Field | Promise, ) {} - async get(options: FieldResolverOptions): Promise { + async get(options: FieldResolverOptions): Promise { return this.factory(options); } } /** Wrapper to delay field generation until needed. */ -export function dynamic( - factory: (options: FieldResolverOptions) => Field | Promise, -): Dynamic { +export function dynamic( + factory: (options: FieldResolverOptions) => Field | Promise, +): Dynamic { return new Dynamic(factory); } -export type FieldResolver = - | Field - | Dynamic; +export type FieldResolver = Field | Dynamic; /** The type of `defaultFields` or `inputFields` option. */ -export type FieldsResolver = { - [FieldName in keyof OptionalTypeWithTransientFields]?: FieldResolver< - OptionalTypeWithTransientFields, - DeepReadonly +export type FieldsResolver = { + [FieldName in keyof TypeWithTransientFields]?: FieldResolver< + TypeWithTransientFields, + DeepReadonly >; }; @@ -46,26 +42,26 @@ export type ResolvedFields, + Type extends Record, TransientFields extends Record, - _DefaultFieldsResolver extends FieldsResolver, - _InputFieldsResolver extends FieldsResolver, + _DefaultFieldsResolver extends FieldsResolver, + _InputFieldsResolver extends FieldsResolver, >( - fieldNames: readonly (keyof OptionalType)[], + fieldNames: readonly (keyof Type)[], seq: number, defaultFieldsResolver: _DefaultFieldsResolver, inputFieldsResolver: _InputFieldsResolver, ): Promise< - StrictlyPick, ResolvedFields<_InputFieldsResolver>>, keyof OptionalType> + StrictlyPick, ResolvedFields<_InputFieldsResolver>>, keyof Type> > { - type OptionalTypeWithTransientFields = OptionalType & TransientFields; + type TypeWithTransientFields = Type & TransientFields; // eslint-disable-next-line @typescript-eslint/no-explicit-any -- Use any type as it is impossible to match types. const fields = {} as any; async function resolveField< - _FieldResolverOptions extends FieldResolverOptions, - _FieldResolver extends FieldResolver, + _FieldResolverOptions extends FieldResolverOptions, + _FieldResolver extends FieldResolver, >(options: _FieldResolverOptions, fieldResolver: _FieldResolver): Promise> { if (fieldResolver instanceof Dynamic) { return fieldResolver.get(options); @@ -74,12 +70,12 @@ export async function resolveFields< } } - async function resolveFieldAndUpdateCache( + async function resolveFieldAndUpdateCache( fieldName: FieldName, - ): Promise | undefined> { + ): Promise | undefined> { if (fieldName in fields) return fields[fieldName]; - let fieldResolver: FieldResolver; + let fieldResolver: FieldResolver; if (fieldName in inputFieldsResolver) { fieldResolver = inputFieldsResolver[fieldName as keyof _InputFieldsResolver]; } else if (fieldName in defaultFieldsResolver) { @@ -93,7 +89,7 @@ export async function resolveFields< return fields[fieldName]; } - const options: FieldResolverOptions = { + const options: FieldResolverOptions = { seq, get: resolveFieldAndUpdateCache, };