Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tests(ts-client): refactor to one default schema #790

Merged
merged 2 commits into from
Apr 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions src/client/ResultSet/ResultSet.test-d.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/* eslint-disable @typescript-eslint/ban-types */

import { expectTypeOf, test } from 'vitest'
import type { Index } from '../../../tests/ts/_/schema/generated/Index.js'
import type * as Schema from '../../../tests/ts/_/schema/generated/SchemaBuildtime.js'
import type { Index } from '../../../tests/_/schema/generated/Index.js'
import type * as Schema from '../../../tests/_/schema/generated/SchemaBuildtime.js'
import type { SelectionSet } from '../SelectionSet/__.js'
import type { ResultSet } from './__.js'

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

// Union
expectTypeOf<RS<{ fooBarUnion: { __typename: true } }>>().toEqualTypeOf<{ fooBarUnion: null | { __typename: "Foo" } | { __typename: "Bar" } }>()
expectTypeOf<RS<{ fooBarUnion: { onFoo: { __typename: true } } }>>().toEqualTypeOf<{ fooBarUnion: null | {} | { __typename: "Foo" } }>()
expectTypeOf<RS<{ fooBarUnion: { onFoo: { id: true } } }>>().toEqualTypeOf<{ fooBarUnion: null | {} | { id: null|string } }>()
expectTypeOf<RS<{ fooBarUnion: { __typename: true; onFoo: { id: true } } }>>().toEqualTypeOf<{ fooBarUnion: null | { __typename: "Bar" } | { __typename: "Foo"; id: null|string } }>()
expectTypeOf<RS<{ unionFooBar: { __typename: true } }>>().toEqualTypeOf<{ unionFooBar: null | { __typename: "Foo" } | { __typename: "Bar" } }>()
expectTypeOf<RS<{ unionFooBar: { onFoo: { __typename: true } } }>>().toEqualTypeOf<{ unionFooBar: null | {} | { __typename: "Foo" } }>()
expectTypeOf<RS<{ unionFooBar: { onFoo: { id: true } } }>>().toEqualTypeOf<{ unionFooBar: null | {} | { id: null|string } }>()
expectTypeOf<RS<{ unionFooBar: { __typename: true; onFoo: { id: true } } }>>().toEqualTypeOf<{ unionFooBar: null | { __typename: "Bar" } | { __typename: "Foo"; id: null|string } }>()
// with Args
expectTypeOf<RS<{ unionFooBarWithArgs: { $: { id: `abc` }, onFoo: { id: true } } }>>().toEqualTypeOf<{ unionFooBarWithArgs: null | {} | { id: null|string } }>()

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

// Directive @include
// On scalar non-nullable
Expand Down
20 changes: 10 additions & 10 deletions src/client/SelectionSet/SelectionSet.test-d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { assertType, expectTypeOf, test } from 'vitest'
import type { Index } from '../../../tests/ts/_/schema/generated/Index.js'
import type { Index } from '../../../tests/_/schema/generated/Index.js'
import type { SelectionSet } from './__.js'

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

// Union
assertType<Q>({ fooBarUnion: { __typename: true } })
assertType<Q>({ fooBarUnion: { onFoo: { __typename: true } } })
assertType<Q>({ fooBarUnion: { onFoo: { id: true } } })
assertType<Q>({ unionFooBar: { __typename: true } })
assertType<Q>({ unionFooBar: { onFoo: { __typename: true } } })
assertType<Q>({ unionFooBar: { onFoo: { id: true } } })
// @ts-expect-error no b
assertType<Q>({ fooBarUnion: { onFoo: { id2: true } } })
assertType<Q>({ fooBarUnion: { onBar: { __typename: true } } })
assertType<Q>({ fooBarUnion: { onBar: { int: true } } })
assertType<Q>({ unionFooBar: { onFoo: { id2: true } } })
assertType<Q>({ unionFooBar: { onBar: { __typename: true } } })
assertType<Q>({ unionFooBar: { onBar: { int: true } } })
// @ts-expect-error no a
assertType<Q>({ fooBarUnion: { onBar: { int2: true } } })
assertType<Q>({ unionFooBar: { onBar: { int2: true } } })

// Union fragments Case
assertType<Q>({ lowerCaseUnion: { onLowerCaseObject: { id: true }, onLowerCaseObject2: { int: true } } })
Expand Down Expand Up @@ -112,7 +112,7 @@ test(`Query`, () => {
assertType<Q>({ object: { $skip: true, string: true } })
// assertType<S>({ scalars: skip().select({ a: true }) })
// on fragment
assertType<Q>({ fooBarUnion: { onBar: { $skip: true, int: true } } })
assertType<Q>({ unionFooBar: { onBar: { $skip: true, int: true } } })
// @include
assertType<Q>({ string: { $include: true } })
assertType<Q>({ string: { $include: false } })
Expand Down Expand Up @@ -224,7 +224,7 @@ test(`Query`, () => {
// @ts-expect-error no directives on scalars field
assertType<Q>({ scalars: { $scalars: { $skip: true } } })
// union fragment
assertType<Q>({ fooBarUnion: { onBar: { $scalars: true } } })
assertType<Q>({ unionFooBar: { onBar: { $scalars: true } } })
assertType<Q>({ unionFooBarWithArgs: { $: { id: `abc` }, onBar: { $scalars: true } } })

// assertType<S>({ scalars: select() })
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -811,13 +811,13 @@ exports[`other > Query 9`] = `
exports[`union > Query 1`] = `
"
{
"fooBarUnion": {
"unionFooBar": {
"__typename": true
}
}
--------------
{
fooBarUnion {
unionFooBar {
__typename
}
}
Expand All @@ -827,15 +827,15 @@ exports[`union > Query 1`] = `
exports[`union > Query 2`] = `
"
{
"fooBarUnion": {
"unionFooBar": {
"onBar": {
"int": true
}
}
}
--------------
{
fooBarUnion {
unionFooBar {
... on Bar {
int
}
Expand All @@ -847,7 +847,7 @@ exports[`union > Query 2`] = `
exports[`union > Query 3`] = `
"
{
"fooBarUnion": {
"unionFooBar": {
"onBar": {
"$skip": true,
"int": true
Expand All @@ -856,7 +856,7 @@ exports[`union > Query 3`] = `
}
--------------
{
fooBarUnion {
unionFooBar {
... on Bar @skip(if: true) {
int
}
Expand Down
10 changes: 5 additions & 5 deletions src/client/SelectionSet/toGraphQLDocumentString.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { parse, print } from 'graphql'
import { describe, expect, test } from 'vitest'
import type { Index } from '../../../tests/ts/_/schema/generated/Index.js'
import type { Index } from '../../../tests/_/schema/generated/Index.js'
import type { SelectionSet } from './__.js'
import { toGraphQLDocumentSelectionSet } from './toGraphQLDocumentString.js'

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

describe(`union`, () => {
test.each([
s({ fooBarUnion: { __typename: true } }),
s({ fooBarUnion: { onBar: { int: true } } }),
s({ fooBarUnion: { onBar: { $skip: true, int: true } } }),
// s({ fooBarUnion: { onBar: {} } }), // todo should be static type error
s({ unionFooBar: { __typename: true } }),
s({ unionFooBar: { onBar: { int: true } } }),
s({ unionFooBar: { onBar: { $skip: true, int: true } } }),
// s({ unionFooBar: { onBar: {} } }), // todo should be static type error
])(`Query`, (ss) => {
expect(prepareResult(ss)).toMatchSnapshot()
})
Expand Down
6 changes: 2 additions & 4 deletions src/client/client.customScalar.test.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
/* eslint-disable */
import { beforeEach, describe, expect, test } from 'vitest'
import { db } from '../../tests/_/db.js'
import { $Index as schemaIndex } from '../../tests/_/schema/generated/SchemaRuntime.js'
import { setupMockServer } from '../../tests/raw/__helpers.js'
// import type { Index } from '../../tests/ts/_/schema/generated/Index.js'
import { $Index as schemaIndex } from '../../tests/ts/_/schema/generated/SchemaRuntime.js'
import { create } from './client.js'

const ctx = setupMockServer()
const date0Encoded = db.date0.toISOString()
const date1Encoded = db.date1.toISOString()

const client = () => create({ name: 'MigrateMe', schema: ctx.url, schemaIndex })
const client = () => create({ schema: ctx.url, schemaIndex })

describe(`output`, () => {
test(`query field`, async () => {
Expand Down Expand Up @@ -80,7 +79,6 @@ describe(`input`, () => {
})
const clientExpected = (expectedDocument: (document: any) => void) => {
const client = create({
name: 'MigrateMe',
schema: ctx.url,
schemaIndex,
hooks: {
Expand Down
2 changes: 1 addition & 1 deletion src/client/client.returnMode.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import { ExecutionResult } from 'graphql'
import { ObjMap } from 'graphql/jsutils/ObjMap.js'
import { describe } from 'node:test'
import { expectTypeOf, test } from 'vitest'
import { $Index as schemaIndex } from '../../tests/_/schema/generated/SchemaRuntime.js'
import { schema } from '../../tests/_/schema/schema.js'
import { $Index as schemaIndex } from '../../tests/ts/_/schema/generated/SchemaRuntime.js'
import { create } from './client.js'

// dprint-ignore
Expand Down
9 changes: 4 additions & 5 deletions src/client/client.test.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
/* eslint-disable */
import { expect, test } from 'vitest'
import { $Index as schemaIndex } from '../../tests/_/schema/generated/SchemaRuntime.js'
import { setupMockServer } from '../../tests/raw/__helpers.js'
import { $Index as schemaIndex } from '../../tests/ts/_/schema/generated/SchemaRuntime.js'
import { create } from './client.js'

const ctx = setupMockServer()
const data = { fooBarUnion: { int: 1 } }
const data = { unionFooBar: { int: 1 } }

const client = () => create({ name: 'MigrateMe', schema: ctx.url, schemaIndex })
const client = () => create({ schema: ctx.url, schemaIndex })

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