Skip to content

Commit a554328

Browse files
authored
tests(ts-client): refactor to one default schema (#790)
1 parent 5f13401 commit a554328

27 files changed

+1094
-1608
lines changed

src/client/ResultSet/ResultSet.test-d.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
/* eslint-disable @typescript-eslint/ban-types */
22

33
import { expectTypeOf, test } from 'vitest'
4-
import type { Index } from '../../../tests/ts/_/schema/generated/Index.js'
5-
import type * as Schema from '../../../tests/ts/_/schema/generated/SchemaBuildtime.js'
4+
import type { Index } from '../../../tests/_/schema/generated/Index.js'
5+
import type * as Schema from '../../../tests/_/schema/generated/SchemaBuildtime.js'
66
import type { SelectionSet } from '../SelectionSet/__.js'
77
import type { ResultSet } from './__.js'
88

@@ -51,10 +51,10 @@ test(`general`, () => {
5151
expectTypeOf<RS<{ objectNonNull: { __typename: true } }>>().toEqualTypeOf<{ objectNonNull: { __typename: "Object1" } }>()
5252

5353
// Union
54-
expectTypeOf<RS<{ fooBarUnion: { __typename: true } }>>().toEqualTypeOf<{ fooBarUnion: null | { __typename: "Foo" } | { __typename: "Bar" } }>()
55-
expectTypeOf<RS<{ fooBarUnion: { onFoo: { __typename: true } } }>>().toEqualTypeOf<{ fooBarUnion: null | {} | { __typename: "Foo" } }>()
56-
expectTypeOf<RS<{ fooBarUnion: { onFoo: { id: true } } }>>().toEqualTypeOf<{ fooBarUnion: null | {} | { id: null|string } }>()
57-
expectTypeOf<RS<{ fooBarUnion: { __typename: true; onFoo: { id: true } } }>>().toEqualTypeOf<{ fooBarUnion: null | { __typename: "Bar" } | { __typename: "Foo"; id: null|string } }>()
54+
expectTypeOf<RS<{ unionFooBar: { __typename: true } }>>().toEqualTypeOf<{ unionFooBar: null | { __typename: "Foo" } | { __typename: "Bar" } }>()
55+
expectTypeOf<RS<{ unionFooBar: { onFoo: { __typename: true } } }>>().toEqualTypeOf<{ unionFooBar: null | {} | { __typename: "Foo" } }>()
56+
expectTypeOf<RS<{ unionFooBar: { onFoo: { id: true } } }>>().toEqualTypeOf<{ unionFooBar: null | {} | { id: null|string } }>()
57+
expectTypeOf<RS<{ unionFooBar: { __typename: true; onFoo: { id: true } } }>>().toEqualTypeOf<{ unionFooBar: null | { __typename: "Bar" } | { __typename: "Foo"; id: null|string } }>()
5858
// with Args
5959
expectTypeOf<RS<{ unionFooBarWithArgs: { $: { id: `abc` }, onFoo: { id: true } } }>>().toEqualTypeOf<{ unionFooBarWithArgs: null | {} | { id: null|string } }>()
6060

@@ -82,7 +82,7 @@ test(`general`, () => {
8282
expectTypeOf<RS<{ id_as: true }>>().toEqualTypeOf<{ id_as: ResultSet.Errors.UnknownFieldName<'id_as', Schema.Root.Query> }>()
8383
expectTypeOf<RS<{ id_as_$: true }>>().toEqualTypeOf<{ id_as_$: ResultSet.Errors.UnknownFieldName<'id_as_$', Schema.Root.Query> }>()
8484
// union fragment
85-
expectTypeOf<RS<{ fooBarUnion: { onFoo: { id_as_id2: true } } }>>().toEqualTypeOf<{ fooBarUnion: null | {} | { id2: null|string } }>()
85+
expectTypeOf<RS<{ unionFooBar: { onFoo: { id_as_id2: true } } }>>().toEqualTypeOf<{ unionFooBar: null | {} | { id2: null|string } }>()
8686

8787
// Directive @include
8888
// On scalar non-nullable

src/client/SelectionSet/SelectionSet.test-d.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { assertType, expectTypeOf, test } from 'vitest'
2-
import type { Index } from '../../../tests/ts/_/schema/generated/Index.js'
2+
import type { Index } from '../../../tests/_/schema/generated/Index.js'
33
import type { SelectionSet } from './__.js'
44

55
type Q = SelectionSet.Query<Index>
@@ -52,15 +52,15 @@ test(`Query`, () => {
5252
assertType<Q>({ object: { a2: true } })
5353

5454
// Union
55-
assertType<Q>({ fooBarUnion: { __typename: true } })
56-
assertType<Q>({ fooBarUnion: { onFoo: { __typename: true } } })
57-
assertType<Q>({ fooBarUnion: { onFoo: { id: true } } })
55+
assertType<Q>({ unionFooBar: { __typename: true } })
56+
assertType<Q>({ unionFooBar: { onFoo: { __typename: true } } })
57+
assertType<Q>({ unionFooBar: { onFoo: { id: true } } })
5858
// @ts-expect-error no b
59-
assertType<Q>({ fooBarUnion: { onFoo: { id2: true } } })
60-
assertType<Q>({ fooBarUnion: { onBar: { __typename: true } } })
61-
assertType<Q>({ fooBarUnion: { onBar: { int: true } } })
59+
assertType<Q>({ unionFooBar: { onFoo: { id2: true } } })
60+
assertType<Q>({ unionFooBar: { onBar: { __typename: true } } })
61+
assertType<Q>({ unionFooBar: { onBar: { int: true } } })
6262
// @ts-expect-error no a
63-
assertType<Q>({ fooBarUnion: { onBar: { int2: true } } })
63+
assertType<Q>({ unionFooBar: { onBar: { int2: true } } })
6464

6565
// Union fragments Case
6666
assertType<Q>({ lowerCaseUnion: { onLowerCaseObject: { id: true }, onLowerCaseObject2: { int: true } } })
@@ -112,7 +112,7 @@ test(`Query`, () => {
112112
assertType<Q>({ object: { $skip: true, string: true } })
113113
// assertType<S>({ scalars: skip().select({ a: true }) })
114114
// on fragment
115-
assertType<Q>({ fooBarUnion: { onBar: { $skip: true, int: true } } })
115+
assertType<Q>({ unionFooBar: { onBar: { $skip: true, int: true } } })
116116
// @include
117117
assertType<Q>({ string: { $include: true } })
118118
assertType<Q>({ string: { $include: false } })
@@ -224,7 +224,7 @@ test(`Query`, () => {
224224
// @ts-expect-error no directives on scalars field
225225
assertType<Q>({ scalars: { $scalars: { $skip: true } } })
226226
// union fragment
227-
assertType<Q>({ fooBarUnion: { onBar: { $scalars: true } } })
227+
assertType<Q>({ unionFooBar: { onBar: { $scalars: true } } })
228228
assertType<Q>({ unionFooBarWithArgs: { $: { id: `abc` }, onBar: { $scalars: true } } })
229229

230230
// assertType<S>({ scalars: select() })

src/client/SelectionSet/__snapshots__/toGraphQLDocumentString.test.ts.snap

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -811,13 +811,13 @@ exports[`other > Query 9`] = `
811811
exports[`union > Query 1`] = `
812812
"
813813
{
814-
"fooBarUnion": {
814+
"unionFooBar": {
815815
"__typename": true
816816
}
817817
}
818818
--------------
819819
{
820-
fooBarUnion {
820+
unionFooBar {
821821
__typename
822822
}
823823
}
@@ -827,15 +827,15 @@ exports[`union > Query 1`] = `
827827
exports[`union > Query 2`] = `
828828
"
829829
{
830-
"fooBarUnion": {
830+
"unionFooBar": {
831831
"onBar": {
832832
"int": true
833833
}
834834
}
835835
}
836836
--------------
837837
{
838-
fooBarUnion {
838+
unionFooBar {
839839
... on Bar {
840840
int
841841
}
@@ -847,7 +847,7 @@ exports[`union > Query 2`] = `
847847
exports[`union > Query 3`] = `
848848
"
849849
{
850-
"fooBarUnion": {
850+
"unionFooBar": {
851851
"onBar": {
852852
"$skip": true,
853853
"int": true
@@ -856,7 +856,7 @@ exports[`union > Query 3`] = `
856856
}
857857
--------------
858858
{
859-
fooBarUnion {
859+
unionFooBar {
860860
... on Bar @skip(if: true) {
861861
int
862862
}

src/client/SelectionSet/toGraphQLDocumentString.test.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { parse, print } from 'graphql'
22
import { describe, expect, test } from 'vitest'
3-
import type { Index } from '../../../tests/ts/_/schema/generated/Index.js'
3+
import type { Index } from '../../../tests/_/schema/generated/Index.js'
44
import type { SelectionSet } from './__.js'
55
import { toGraphQLDocumentSelectionSet } from './toGraphQLDocumentString.js'
66

@@ -23,10 +23,10 @@ const prepareResult = (ss: Q) => {
2323

2424
describe(`union`, () => {
2525
test.each([
26-
s({ fooBarUnion: { __typename: true } }),
27-
s({ fooBarUnion: { onBar: { int: true } } }),
28-
s({ fooBarUnion: { onBar: { $skip: true, int: true } } }),
29-
// s({ fooBarUnion: { onBar: {} } }), // todo should be static type error
26+
s({ unionFooBar: { __typename: true } }),
27+
s({ unionFooBar: { onBar: { int: true } } }),
28+
s({ unionFooBar: { onBar: { $skip: true, int: true } } }),
29+
// s({ unionFooBar: { onBar: {} } }), // todo should be static type error
3030
])(`Query`, (ss) => {
3131
expect(prepareResult(ss)).toMatchSnapshot()
3232
})

src/client/client.customScalar.test.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
11
/* eslint-disable */
22
import { beforeEach, describe, expect, test } from 'vitest'
33
import { db } from '../../tests/_/db.js'
4+
import { $Index as schemaIndex } from '../../tests/_/schema/generated/SchemaRuntime.js'
45
import { setupMockServer } from '../../tests/raw/__helpers.js'
5-
// import type { Index } from '../../tests/ts/_/schema/generated/Index.js'
6-
import { $Index as schemaIndex } from '../../tests/ts/_/schema/generated/SchemaRuntime.js'
76
import { create } from './client.js'
87

98
const ctx = setupMockServer()
109
const date0Encoded = db.date0.toISOString()
1110
const date1Encoded = db.date1.toISOString()
1211

13-
const client = () => create({ name: 'MigrateMe', schema: ctx.url, schemaIndex })
12+
const client = () => create({ schema: ctx.url, schemaIndex })
1413

1514
describe(`output`, () => {
1615
test(`query field`, async () => {
@@ -80,7 +79,6 @@ describe(`input`, () => {
8079
})
8180
const clientExpected = (expectedDocument: (document: any) => void) => {
8281
const client = create({
83-
name: 'MigrateMe',
8482
schema: ctx.url,
8583
schemaIndex,
8684
hooks: {

src/client/client.returnMode.test-d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ import { ExecutionResult } from 'graphql'
33
import { ObjMap } from 'graphql/jsutils/ObjMap.js'
44
import { describe } from 'node:test'
55
import { expectTypeOf, test } from 'vitest'
6+
import { $Index as schemaIndex } from '../../tests/_/schema/generated/SchemaRuntime.js'
67
import { schema } from '../../tests/_/schema/schema.js'
7-
import { $Index as schemaIndex } from '../../tests/ts/_/schema/generated/SchemaRuntime.js'
88
import { create } from './client.js'
99

1010
// dprint-ignore

src/client/client.test.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
1-
/* eslint-disable */
21
import { expect, test } from 'vitest'
2+
import { $Index as schemaIndex } from '../../tests/_/schema/generated/SchemaRuntime.js'
33
import { setupMockServer } from '../../tests/raw/__helpers.js'
4-
import { $Index as schemaIndex } from '../../tests/ts/_/schema/generated/SchemaRuntime.js'
54
import { create } from './client.js'
65

76
const ctx = setupMockServer()
8-
const data = { fooBarUnion: { int: 1 } }
7+
const data = { unionFooBar: { int: 1 } }
98

10-
const client = () => create({ name: 'MigrateMe', schema: ctx.url, schemaIndex })
9+
const client = () => create({ schema: ctx.url, schemaIndex })
1110

1211
test.todo(`query`, async () => {
1312
const mockRes = ctx.res({ body: { data } }).spec.body!
14-
expect(await client().query.$batch({ fooBarUnion: { onBar: { int: true } } })).toEqual(mockRes.data)
13+
expect(await client().query.$batch({ unionFooBar: { onBar: { int: true } } })).toEqual(mockRes.data)
1514
})

0 commit comments

Comments
 (0)