-
Notifications
You must be signed in to change notification settings - Fork 311
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(ts-client): no select root types if not in schema
- Loading branch information
1 parent
893a5e0
commit 5f13401
Showing
4 changed files
with
46 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,2 @@ | ||
export * from '../../client/client.js' | ||
// todo need to export a generated version | ||
export { create as createSelect } from '../../select.js' | ||
export { create as createSelect, select } from '../../select.js' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { describe, expect, expectTypeOf, it, test } from 'vitest' | ||
import type { Index } from '../tests/_/schema/schema.js' | ||
import type * as SchemaQueryOnly from '../tests/_/schemaQueryOnly/generated/Index.js' | ||
import type { SelectionSet } from './client/SelectionSet/__.js' | ||
import { create } from './select.js' | ||
|
||
describe(`select`, () => { | ||
const select = create<Index>() | ||
it(`returns the input for any method name`, () => { | ||
const s = select as any // eslint-disable-line | ||
expect(s.anything(1)).toEqual(1) // eslint-disable-line | ||
}) | ||
|
||
it(`has type safe methods`, () => { | ||
// @ts-expect-error ID issue | ||
type $Parameters = Parameters<typeof select.Bar> | ||
expectTypeOf<$Parameters>().toEqualTypeOf<[SelectionSet.Object<Index['objects']['Bar'], Index>]>() | ||
expectTypeOf(select.Bar({ int: true })).toEqualTypeOf<{ int: true }>() | ||
}) | ||
}) | ||
|
||
describe(`create`, () => { | ||
const select = create<SchemaQueryOnly.Index>() | ||
test(`does not have root types if not in schema`, () => { | ||
// fine | ||
select.Query | ||
// @ts-expect-error no mutation in schema | ||
select.Mutation | ||
// @ts-expect-error no mutation in schema | ||
select.Subscription | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,13 @@ | ||
import { expect, it } from 'vitest' | ||
import type { Index } from '../tests/ts/_/schema/generated/Index.js' | ||
import { expect, test } from 'vitest' | ||
import type { Index } from '../tests/_/schema/schema.js' | ||
import { create } from './select.js' | ||
|
||
it(`returns the input for any method name`, () => { | ||
const select = create() as any // eslint-disable-line | ||
expect(select.anything(1)).toEqual(1) // eslint-disable-line | ||
const select = create<Index>() | ||
test(`returns the input for any method name`, () => { | ||
const s = select as any // eslint-disable-line | ||
expect(s.anything(1)).toEqual(1) // eslint-disable-line | ||
}) | ||
|
||
it(`has type safe methods`, () => { | ||
const select = create<Index>() | ||
test(`has type safe methods`, () => { | ||
expect(select.Bar({ ___: { $defer: true, int: true } })).toEqual({ ___: { $defer: true, int: true } }) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters