Skip to content

Commit

Permalink
various fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonkuhrt committed Feb 11, 2025
1 parent c248254 commit 9358234
Show file tree
Hide file tree
Showing 12 changed files with 251 additions and 208 deletions.
7 changes: 5 additions & 2 deletions src/client/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -182,8 +182,10 @@ export const createWithContext = <$Context extends Context>(
}

const initialInput = {
transportType: context.transports.current,
transport: context.transports.configurations[context.transports.current],
[context.transports.registry[context.transports.current]!.discriminant[`name`]]:
context.transports.registry[context.transports.current]!.discriminant[`value`],
[context.transports.registry[context.transports.current]!.configurationMount]:
context.transports.configurations[context.transports.current],
state: context,
request: analyzedRequest,
} as RequestPipeline.Base['input']
Expand Down Expand Up @@ -219,6 +221,7 @@ export const createWithContext = <$Context extends Context>(
// const configurationIndexEntry = configurationIndex[_.name]
// if (!configurationIndexEntry && _.configurator) throw new Error(`Configuration entry for ${_.name} not found`)

_
const propertiesComputed = _.propertiesComputed.reduce((acc, propertiesComputer) => {
return {
...acc,
Expand Down
2 changes: 1 addition & 1 deletion src/client/properties/extensions/dataType/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export interface Data<
readonly propertiesComputed: ReadonlyArray<Properties.PropertiesComputer>
readonly propertiesComputedTypeFunctions$: $PropertiesComputersTypeFunctions
// todo support for multiple transports in one extension
readonly transport?: $Transport
readonly transport: $Transport
readonly static: $Static
// typeHooks: $TypeHooks
}
Expand Down
12 changes: 6 additions & 6 deletions src/client/properties/extensions/extensions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ import { type ContextFragmentAddProperties, contextFragmentPropertiesAdd } from
import { RequestInterceptors } from '../requestInterceptors/__.js'
import { Transports } from '../transports/__.js'
import type { Transport } from '../transports/dataType.js'
import type { Data } from './dataType/_exports.js'
import type { Extension } from './dataType/_namespace.js'

// ------------------------------------------------------------
// Method
// ------------------------------------------------------------

// dprint-ignore
export interface MethodAdd<$Context extends Context> {
<extension extends Extension>(extension: extension):
<extension extends Extension.Data>(extension: extension):
Client<ContextAddOne<$Context, extension>>
}

Expand All @@ -24,9 +24,9 @@ export interface MethodAdd<$Context extends Context> {
// ------------------------------------------------------------

export interface ContextFragmentExtensions {
readonly extensions: readonly Extension[]
readonly extensions: readonly Extension.Data[]
readonly extensionsIndex: {
[extensionName: string]: Extension
[extensionName: string]: Extension.Data
}
}

Expand All @@ -46,7 +46,7 @@ export const contextFragmentExtensionsEmpty: ContextFragmentExtensionsEmpty = {
// dprint-ignore
export type ContextAddOne<
$Context extends Context,
$Extension extends Extension,
$Extension extends Extension.Data,
> = {
readonly [_ in keyof $Context]:
_ extends 'properties' ?
Expand Down Expand Up @@ -81,7 +81,7 @@ export type ContextAddOne<
// todo: make return a fragment
export const contextFragmentExtensionsAdd = <
const $Context extends Context,
$Extension extends Extension,
$Extension extends Extension.Data,
>(context: $Context, extension: $Extension): ContextAddOne<$Context, $Extension> => {
const fragment: Writable<Context> = {
...context,
Expand Down
183 changes: 183 additions & 0 deletions src/client/properties/output/_.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,183 @@
/* eslint-disable */
import { type ExecutionResult } from 'graphql'
import { describe } from 'node:test'
import { expect, expectTypeOf } from 'vitest'
import { Graffle } from '../../../../tests/_/schemas/kitchen-sink/graffle/__.js'
// import { schema } from '../../../../tests/_/schemas/kitchen-sink/schema.js'
import { ATransport } from '../../../../tests/_/fixtures/transports.js'
import { g0, test } from '../../../../tests/_/helpers.js'
import { schema } from '../../../../tests/_/schemas/query-only/schema.js'
import { TransportMemory } from '../../../extensions/TransportMemory/TransportMemory.js'
import type { Anyware } from '../../../lib/anyware/_namespace.js'
import { assertEqual } from '../../../lib/assert-equal.js'
import { type GraphQLExecutionResultError } from '../../../lib/grafaid/graphql.js'
import { create } from '../../client.js'

const g1 = g0.use(TransportMemory).transport({ schema })
// const G = Graffle.create

// const defaultGraffle = Graffle.create({ check: { preflight: false } })

test('default is throws errors', async () => {
await expect(g1.gql('').send()).rejects.toThrowErrorMatchingInlineSnapshot(
`[ContextualAggregateError: One or more errors in the execution result.]`,
)
})
test('can return errors', async () => {
const g2 = g1.with({ output: { defaults: { errorChannel: 'return' } } })
const result = await g2.gql('').send()
expect(result).toMatchInlineSnapshot(`[ContextualAggregateError: One or more errors in the execution result.]`)
})

// // test('default is errors thrown, no envelope, no schema errors', async () => {
// // const graffle = create({
// // checkPreflight: false,
// // output: {
// // defaults: {
// // errorChannel: 'throw',
// // },
// // envelope: {
// // enabled: false,
// // errors: {
// // execution: true,
// // other: false,
// // },
// // },
// // errors: {
// // execution: 'default',
// // other: 'default',
// // },
// // },
// // })
// // const result1 = await graffle.query.__typename()
// // const result2 = await defaultGraffle.query.__typename()
// // expectTypeOf(result1).toEqualTypeOf<'Query'>()
// // expectTypeOf(result2).toEqualTypeOf<'Query'>()
// // })

// // dprint-ignore
// describe('.envelope', () => {
// type FieldMethodResultDisabled = 'Query'
// type FieldMethodResultEnabled = ExecutionResult<{ __typename: FieldMethodResultDisabled }>

// // type ResultFieldMethodResultDisabled = {
// // __typename: 'Object1'
// // } | {
// // __typename: 'ErrorOne'
// // } | {
// // __typename: 'ErrorTwo'
// // }
// // type ResultFieldMethodResultEnabled = ExecutionResult<{ resultNonNull: ResultFieldMethodResultDisabled }>

// // todo reference to Graffle client
// // const fieldMethod = <$Graffle extends {query:{__typename:()=>Promise<any>}}>(g: $Graffle) => g.query.__typename()

// describe('false disables it ', () => {
// const g = G({ output: { envelope: false }, checkPreflight: false })

// test('query.<fieldMethod>', ({ kitchenSink }) => {
// expectTypeOf(g.query.__typename()).resolves.toEqualTypeOf<FieldMethodResultDisabled>()
// })
// // test('query.<resultFieldMethod>', () => {
// // expectTypeOf(g.query.resultNonNull(resultFieldSelect)).resolves.toEqualTypeOf<ResultFieldMethodResultDisabled>()
// // })
// test('query.$batch', async () => {
// expectTypeOf(await g.query.$batch({ __typename: true, idNonNull: true })).toEqualTypeOf<{ __typename: 'Query'; idNonNull: string } | null>()
// })
// })
// describe('true enables it', () => {
// const g = Graffle.create({ output: { envelope: true }, checkPreflight: false })
// test('query.<fieldMethod>', () => {
// expectTypeOf(g.query.__typename()).resolves.toMatchTypeOf<FieldMethodResultEnabled>()
// })
// // test('query.<resultFieldMethod>', async () => {
// // expectTypeOf((await g.query.resultNonNull(resultFieldSelect))).toMatchTypeOf<ResultFieldMethodResultEnabled>()
// // })
// test('query.$batch', () => {
// const result = g.query.$batch({ __typename: true, idNonNull: true })
// assertEqual<typeof result, ExecutionResult<{ __typename: 'Query'; idNonNull: string }>>
// })
// })
// test('object enables it', async () => {
// const graffle = Graffle.create({ output: { envelope: {} }, checkPreflight: false })
// expectTypeOf(await graffle.query.__typename()).toMatchTypeOf<FieldMethodResultEnabled>()
// })
// describe('.enabled', () => {
// test('false disables it', async () => {
// const graffle = Graffle.create({ output: { envelope: { enabled: false } }, checkPreflight: false })
// expectTypeOf(await graffle.query.__typename()).toEqualTypeOf<FieldMethodResultDisabled>()
// })
// test('true enables it', async () => {
// const graffle = Graffle.create({ output: { envelope: { enabled: true } }, checkPreflight: false })
// expectTypeOf(await graffle.query.__typename()).toMatchTypeOf<FieldMethodResultEnabled>()
// })
// })
// describe('with defaults.errorChannel: "return"', () => {
// describe('.errors', () => {
// test('defaults to execution errors in envelope', () => {
// const g = G({ output: { defaults: { errorChannel: 'return' }, envelope: true }, checkPreflight: false })
// expectTypeOf(g.query.__typename()).resolves.toMatchTypeOf<ExecutionResult<{ __typename: 'Query' }> | Anyware.ResultFailure>()
// })
// test('.execution:false restores errors to return', async () => {
// const g = G({
// output: { defaults: { errorChannel: 'return' }, envelope: { errors: { execution: false } } },
// checkPreflight: false,
// })
// expectTypeOf(await g.query.__typename()).toEqualTypeOf<
// Omit<ExecutionResult<{ __typename: 'Query' }>, 'errors'> | Anyware.ResultFailure | GraphQLExecutionResultError
// >()
// })
// test('.other:true raises them to envelope', () => {
// const g = G({
// output: { defaults: { errorChannel: 'return' }, envelope: { errors: { other: true } } },
// checkPreflight: false,
// })
// expectTypeOf(g.query.__typename()).resolves.toMatchTypeOf<ExecutionResult<{ __typename: 'Query' }>>()
// })
// })
// })
// test('with no errors included, then there are no error fields in the envelope', async () => {
// const g = G({
// // todo allow this shorthand
// // output: { envelope: false },
// output: { envelope: { errors: { execution:false, other:false } } },
// checkPreflight: false,
// })
// const result = await g.query.__typename()
// expectTypeOf<keyof typeof result>().toEqualTypeOf<'data'|'extensions'> // no errors
// })
// })

// describe('defaults.errorChannel: "return"', () => {
// describe('puts errors into return type', () => {
// const g = G({ output: { defaults: { errorChannel: 'return' } }, checkPreflight: false })
// test('query.<fieldMethod>', async () => {
// expectTypeOf(await g.query.__typename()).toEqualTypeOf<
// 'Query' | Anyware.ResultFailure | GraphQLExecutionResultError
// >()
// })
// })
// describe('with .errors', () => {
// test('.execution: throw', async () => {
// const g = G({
// output: { defaults: { errorChannel: 'return' }, errors: { execution: 'throw' } },
// checkPreflight: false,
// })
// expectTypeOf(await g.query.__typename()).toEqualTypeOf<'Query' | Anyware.ResultFailure>()
// })
// test('.other: throw', async () => {
// const g = G({
// output: { defaults: { errorChannel: 'return' }, errors: { other: 'throw' } },
// checkPreflight: false,
// })
// expectTypeOf(await g.query.__typename()).toEqualTypeOf<'Query' | GraphQLExecutionResultError>()
// })
// test('.*: throw', async () => {
// const g = G({
// output: { defaults: { errorChannel: 'return' }, errors: { other: 'throw', execution: 'throw' } },
// checkPreflight: false,
// })
// expectTypeOf(await g.query.__typename()).toEqualTypeOf<'Query'>()
// })
// })
// })
Loading

0 comments on commit 9358234

Please sign in to comment.