RestoreArrays<Result, FlatModel>: {
    [K in keyof NonNullable<Result>]: K extends keyof NonNullable<FlatModel>
        ? any[] extends NonNullable<FlatModel>[K]
            ? HandleArrayNullability<NonNullable<Result>[K], NonNullable<FlatModel>[K]>
            : NonNullable<FlatModel>[K] extends Record<string, any>
                ? RestoreArrays<NonNullable<Result>[K], NonNullable<FlatModel>[K]>
                : NonNullable<Result>[K]
        : never
}

This mapped type traverses the SelectionSetReturnValue result and the original FlatModel, restoring array types that were flattened in DeepPickFromPath

Type Parameters

  • Result

    this is the result of applying the selection set path to FlatModel; return type of UnionToIntersection<DeepPickFromPath<FlatModel, Paths>>

  • FlatModel

    the reference model shape; return type of ResolvedModel

    Note: we wrap Result and FlatModel in NonNullable, because recursive invocations of this mapped type can result in the type arguments containing {} | null | undefined which breaks indexed access, e.g. Result[K]

    Using NonNullable<> directly inside the mapped type is significantly more performant here than attempting to pre-compute in the type params, e.g., type RestoreArrays<Result, FlatModel, NonNullableResult = NonNullable<Result>, NonNullableFlatModel = NonNullable<FlatModel>> = {...}