Skip to content

Commit

Permalink
fix(document-builder): inline fragment always case
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonkuhrt committed Nov 19, 2024
1 parent f73aecd commit 8bf1621
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 12 deletions.
4 changes: 2 additions & 2 deletions src/documentBuilder/InferResult/OutputObject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import type { TSErrorDescriptive } from '../../lib/ts-error.js'
import type { Schema } from '../../types/Schema/__.js'
import type { Select } from '../Select/__.js'
import type { Alias } from './Alias.js'
import type { IsNeverViaDirective, IsNullableViaDirective, OmitDirectiveAndArgumentKeys } from './directive.js'
import type { IsNeverViaDirective, IsOptionalViaDirective, OmitDirectiveAndArgumentKeys } from './directive.js'
import type { OutputField } from './OutputField.js'
import type { ScalarsWildcard } from './ScalarsWildcard.js'

Expand Down Expand Up @@ -61,7 +61,7 @@ type InlineFragmentKey_<$SelectionSet extends object, $Schema extends Schema, $N
? {}
: IsNeverViaDirective<$SelectionSet> extends true
? {}
: IsNullableViaDirective<$SelectionSet> extends true
: IsOptionalViaDirective<$SelectionSet> extends true
? Partial<
OutputObject_<OmitDirectiveAndArgumentKeys<$SelectionSet>, $Schema, $Node>
>
Expand Down
2 changes: 2 additions & 0 deletions src/documentBuilder/InferResult/__.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,8 @@ assertEqual<$<{ ___: { $include: false; id: true }}>
assertEqual<$<{ ___: { $skip: true; id: true }}> , {}>()
assertEqual<$<{ ___: { $skip: boolean; id: true; listIntNonNull:true }}> , { id?: string | null; listIntNonNull?: number[] }>()
assertEqual<$<{ ___: { $include: boolean; id: true; listIntNonNull:true }}> , { id?: string | null; listIntNonNull?: number[] }>()
assertEqual<$<{ ___: { $include: true; id: true }}> , { id: string | null }>()
assertEqual<$<{ ___: { $skip: false; id: true }}> , { id: string | null }>()

// Errors
// @ts-expect-error invalid query
Expand Down
26 changes: 18 additions & 8 deletions src/documentBuilder/InferResult/directive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,24 @@ export type IsNeverViaDirective<$SelectionSet> =
: false

// dprint-ignore
export type IsNullableViaDirective<$SelectionSet> =
$SelectionSet extends NullableSelection
? true
: false

type NeverSelection = Select.Directive.Include.FieldStates.Negative | Select.Directive.Skip.FieldStates.Positive

type NullableSelection =
export type IsOptionalViaDirective<$SelectionSet> =
$SelectionSet extends AlwaysSelection
? false
: $SelectionSet extends NeverSelection
? false
: $SelectionSet extends OptionalSelection
? true
: false

type AlwaysSelection =
| Select.Directive.Include.FieldStates.Positive
| Select.Directive.Skip.FieldStates.Negative

type NeverSelection =
| Select.Directive.Include.FieldStates.Negative
| Select.Directive.Skip.FieldStates.Positive

type OptionalSelection =
| Select.Directive.Include.FieldStates.Variable
| Select.Directive.Skip.FieldStates.Variable

Expand Down
4 changes: 2 additions & 2 deletions src/documentBuilder/requestMethods/requestMethods.test-d.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
/* eslint-disable */
import { expectTypeOf, test } from 'vitest'
import { DateScalar } from '../../../tests/_/fixtures/scalars.js'
import type { db } from '../../../tests/_/schemas/db.js'
// import type { db } from '../../../tests/_/schemas/db.js'
import { Graffle } from '../../../tests/_/schemas/kitchen-sink/graffle/__.js'
import * as Schema from '../../../tests/_/schemas/kitchen-sink/schema.js'
import { Graffle as Pokemon } from '../../../tests/_/schemas/pokemon/graffle/__.js'
// import { Graffle as Pokemon } from '../../../tests/_/schemas/pokemon/graffle/__.js'

const graffle = Graffle.create({ schema: Schema.schema }).scalar(DateScalar)

Expand Down
4 changes: 4 additions & 0 deletions src/lib/prelude.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ import { type OmitKeysWithPrefix, type ToParameters, type Tuple } from './prelud
// dprint-ignore
{

// assertEqual<IsAnyUnionMemberExtends<1|2, 1>, true>()
// assertEqual<IsAnyUnionMemberExtends<1|2, 2>, true>()
// assertEqual<IsAnyUnionMemberExtends<3, 2> , false>()

assertEqual<OmitKeysWithPrefix<{ a: 1; b: 2 }, 'a'> , { a: 1; b: 2 }>()
assertEqual<OmitKeysWithPrefix<{ foo_a: 1; b: 2 }, 'foo'> , { b: 2 }>()

Expand Down
15 changes: 15 additions & 0 deletions src/lib/prelude.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { HasRequiredKeys, IsAny, IsEmptyObject, IsNever, IsUnknown, Simplify } from 'type-fest'

import type { ConfigManager } from './config-manager/__.js'

/* eslint-disable */
Expand Down Expand Up @@ -751,3 +752,17 @@ type UnionKeys<U> = U extends any ? keyof U : never
type UnionValue<U, K extends PropertyKey> = U extends any ? K extends keyof U ? U[K]
: never
: never

// // dprint-ignore
// export type IsAnyUnionMemberExtends<T, U> =
// true extends IsAnyUnionMemberExtends_<T, U>
// ? true
// : false

// // dprint-ignore
// type IsAnyUnionMemberExtends_<T, U> =
// T extends any
// ? T extends U
// ? true
// : never
// : never

0 comments on commit 8bf1621

Please sign in to comment.