Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: correct maybe deep promise typing #906

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 12 additions & 11 deletions src/plugins/connectionPlugin.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,9 @@
import { defaultFieldResolver, GraphQLFieldResolver, GraphQLResolveInfo } from 'graphql'
import { ArgsRecord, intArg, stringArg } from '../definitions/args'
import type { CommonFieldConfig, FieldOutConfig } from '../definitions/definitionBlocks'
import { NexusNonNullDef, nonNull } from '../definitions/nonNull'
import { NexusNullDef, nullable } from '../definitions/nullable'
import { ObjectDefinitionBlock, objectType } from '../definitions/objectType'
import {
AllNexusNamedOutputTypeDefs,
AllNexusOutputTypeDefs,
applyNexusWrapping,
} from '../definitions/wrapping'
import type { NonNullConfig } from '../definitions/_types'
import { dynamicOutputMethod } from '../dynamicMethod'
import { completeValue, plugin } from '../plugin'
import { ArgsRecord, intArg, stringArg } from '../definitions/args'
import type {
ArgsValue,
FieldTypeName,
Expand All @@ -21,9 +13,18 @@ import type {
ResultValue,
SourceValue,
} from '../typegenTypeHelpers'
import type { MaybePromiseLike } from '../typeHelpersInternal'
import type { CommonFieldConfig, FieldOutConfig } from '../definitions/definitionBlocks'
import { GraphQLFieldResolver, GraphQLResolveInfo, defaultFieldResolver } from 'graphql'
import { NexusNonNullDef, nonNull } from '../definitions/nonNull'
import { NexusNullDef, nullable } from '../definitions/nullable'
import { ObjectDefinitionBlock, objectType } from '../definitions/objectType'
import { completeValue, plugin } from '../plugin'
import { eachObj, getOwnPackage, isPromiseLike, mapObj, pathToArray, printedGenTypingImport } from '../utils'

import type { MaybePromiseLike } from '../typeHelpersInternal'
import type { NonNullConfig } from '../definitions/_types'
import { dynamicOutputMethod } from '../dynamicMethod'

export interface ConnectionPluginConfig {
/**
* The method name in the objectType definition block
Expand Down Expand Up @@ -309,7 +310,7 @@ export type ConnectionFieldConfig<TypeName extends string = any, FieldName exten
args: ArgsValue<TypeName, FieldName>,
ctx: GetGen<'context'>,
info: GraphQLResolveInfo
) => MaybePromise<ResultValue<TypeName, FieldName>> | MaybePromiseDeep<ResultValue<TypeName, FieldName>>
) => MaybePromiseDeep<ResultValue<TypeName, FieldName>>

// resolve XOR nodes
nodes?: never
Expand Down
24 changes: 9 additions & 15 deletions src/typegenTypeHelpers.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { GraphQLAbstractType, GraphQLResolveInfo } from 'graphql'

import type { NexusInterfaceTypeDef } from './definitions/interfaceType'
import type { NexusObjectTypeDef } from './definitions/objectType'

Expand Down Expand Up @@ -34,27 +35,20 @@ export type MaybePromise<T> = PromiseLike<T> | T
* Because the GraphQL field execution algorithm automatically resolves promises at any level of the tree, we
* use this to help signify that.
*/
export type MaybePromiseDeep<T> = Date extends T
? MaybePromise<T>
: null extends T
export type MaybePromiseDeep<T> = [T] extends [Date]
? MaybePromise<T>
: boolean extends T
: [T] extends [boolean]
? MaybePromise<T>
: number extends T
: [T] extends [number]
? MaybePromise<T>
: string extends T
: [T] extends [string]
? MaybePromise<T>
: T extends Array<infer U>
: [T] extends [Array<infer U>]
? MaybePromise<Array<MaybePromiseDeep<U>>>
: T extends ReadonlyArray<infer Y>
: [T] extends [ReadonlyArray<infer Y>]
? MaybePromise<ReadonlyArray<MaybePromiseDeep<Y>>>
: T extends object
? MaybePromise<
| T
| {
[P in keyof T]: MaybePromiseDeep<T[P]>
}
>
: [T] extends object
? MaybePromise<{ [P in keyof T]: MaybePromiseDeep<T[P]> }>
: MaybePromise<T>

/**
Expand Down