Skip to content

Commit

Permalink
fix(document-builder): alias does not inject index type
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonkuhrt committed Nov 18, 2024
1 parent 1dd9ffa commit 829fdc4
Show file tree
Hide file tree
Showing 17 changed files with 328 additions and 415 deletions.
11 changes: 6 additions & 5 deletions src/documentBuilder/requestMethods/requestMethods.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,19 @@ import { DateScalar } from '../../../tests/_/fixtures/scalars.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'

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

const x = await graffle.query.id({ $include: false })
// const pokemons = await Pokemon.create().query.pokemons({id:true})

// dprint-ignore
test(`query`, async () => {
expectTypeOf(await graffle.query.object({id:['id2',true]})).toEqualTypeOf<{id2:null|string} | null>()
// scalar
expectTypeOf(await graffle.query.id()).toEqualTypeOf<string | null>()
// scalar none-nullable
expectTypeOf(await graffle.query.idNonNull()).toEqualTypeOf<null | string>()
expectTypeOf(await graffle.query.idNonNull()).toEqualTypeOf<string>()
// scalar with optional arguments
expectTypeOf<Parameters<typeof graffle.query.stringWithArgs>>().toEqualTypeOf<[input?: Graffle.SelectionSets.Query.stringWithArgs]>()
// scalar with required arguments
Expand All @@ -23,16 +26,14 @@ test(`query`, async () => {

// scalar with explicit indicators
// positive indicator
expectTypeOf(await graffle.query.idNonNull(true)).toEqualTypeOf<null |string>()
expectTypeOf(await graffle.query.idNonNull(true)).toEqualTypeOf<string>()
// negative indicator
// todo
// expectTypeOf(await graffle.query.idNonNull(false)).toEqualTypeOf<null>()
// negative indicator via directive
// todo
// expectTypeOf(await graffle.query.idNonNull({ $skip: false })).toEqualTypeOf<null>()

const x = await graffle.query.dateObject1({ $scalars: true })

// object
expectTypeOf(graffle.query.dateObject1({ date1: true })).resolves.toEqualTypeOf<{ date1: Date | null } | null>()
expectTypeOf(graffle.query.unionFooBar({ ___on_Foo: { id: true }})).resolves.toEqualTypeOf<{} | { id: string | null } | null>()
Expand Down
8 changes: 7 additions & 1 deletion src/entrypoints/utilities-for-generated.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,13 @@ export type { ConfigGetOutputError, HandleOutput, HandleOutputGraffleRootField }
export type { Config } from '../client/Settings/Config.js'
export { type DocumentRunner } from '../documentBuilder/requestMethods/document.js'
export * from '../documentBuilder/Select/__.js'
export { type Exact, type ExactNonEmpty, type SimplifyExcept, type UnionExpanded } from '../lib/prelude.js'
export {
type AssertExtendsObject,
type Exact,
type ExactNonEmpty,
type SimplifyExcept,
type UnionExpanded,
} from '../lib/prelude.js'
export { TypeFunction } from '../lib/type-function/__.js'
export { type GlobalRegistry } from '../types/GlobalRegistry/GlobalRegistry.js'
export { Schema } from '../types/Schema/__.js'
Expand Down
Loading

0 comments on commit 829fdc4

Please sign in to comment.