-
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.
- Loading branch information
1 parent
624e684
commit fccd6eb
Showing
1 changed file
with
42 additions
and
58 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,69 +1,53 @@ | ||
/* eslint-disable */ | ||
import { describe, expectTypeOf } from 'vitest' | ||
import { test } from '../../../../tests/_/helpers.js' | ||
import { Graffle } from '../../../../tests/_/schemas/kitchen-sink/graffle/__.js' | ||
import { schema } from '../../../../tests/_/schemas/kitchen-sink/schema.js' | ||
import { gql } from '../../6_helpers/gql.js' | ||
import type { RawResolveOutputReturnRootType } from '../handleOutput.js' | ||
|
||
const g = Graffle.create({ schema }) | ||
|
||
describe(`TypedQueryDocumentNode with just data (no variables)`, () => { | ||
const document = gql<{ id: string }, {}>` | ||
query { | ||
id | ||
} | ||
` | ||
test(`envelope data is typed`, () => { | ||
expectTypeOf(g.raw({ document })).resolves.toEqualTypeOf< | ||
RawResolveOutputReturnRootType<typeof g._.context.config, { id: string }> | ||
>() | ||
}) | ||
test('variables are not allowed to be passed in', () => { | ||
// @ts-expect-error - variables not allowed. | ||
g.raw({ document: document, variables: {} }) | ||
describe(`TypedQueryDocumentNode`, () => { | ||
describe(`data`, () => { | ||
const document = gql<{ id: string }, {}>`query { id }` | ||
test(`envelope data is typed`, ({ kitchenSink: g }) => { | ||
type ExpectedType = RawResolveOutputReturnRootType<typeof g._.context.config, { id: string }> | ||
expectTypeOf(g.raw({ document })).resolves.toEqualTypeOf<ExpectedType>() | ||
}) | ||
test(`variables are not allowed to be passed in`, async ({ kitchenSink: g }) => { | ||
// @ts-expect-error - variables not allowed. | ||
await g.raw({ document: document, variables: {} }) | ||
}) | ||
}) | ||
}) | ||
|
||
describe(`TypedQueryDocumentNode with data and optional variables`, () => { | ||
const document = gql<{ id: string }, { filter?: boolean }>` | ||
query { | ||
id | ||
} | ||
` | ||
test(`envelope data is typed`, () => { | ||
expectTypeOf(g.raw({ document })).resolves.toEqualTypeOf< | ||
RawResolveOutputReturnRootType<typeof g._.context.config, { id: string }> | ||
>() | ||
}) | ||
test('variables are typed and allowed to be passed in or omitted', () => { | ||
// Expect no type errors below | ||
g.raw({ document }) | ||
g.raw({ document, variables: {} }) | ||
g.raw({ document, variables: { filter: true } }) | ||
g.raw({ document, variables: { filter: false } }) | ||
// @ts-expect-error - wrong type | ||
g.raw({ document, variables: { filter: 'wrong type' } }) | ||
describe(`data + optional variables`, () => { | ||
const document = gql<{ id: string }, { filter?: boolean }>`query { id }` | ||
test(`envelope data is typed`, ({ kitchenSink: g }) => { | ||
expectTypeOf(g.raw({ document })).resolves.toEqualTypeOf< | ||
RawResolveOutputReturnRootType<typeof g._.context.config, { id: string }> | ||
>() | ||
}) | ||
test(`variables are typed and allowed to be passed in or omitted`, async ({ kitchenSink: g }) => { | ||
// Expect no type errors below | ||
await g.raw({ document }) | ||
await g.raw({ document, variables: {} }) | ||
await g.raw({ document, variables: { filter: true } }) | ||
await g.raw({ document, variables: { filter: false } }) | ||
// @ts-expect-error - wrong type | ||
await g.raw({ document, variables: { filter: `wrong type` } }) | ||
}) | ||
}) | ||
}) | ||
|
||
describe(`TypedQueryDocumentNode with data and one or more required variables`, () => { | ||
const document = gql<{ id: string }, { filter: boolean }>` | ||
query { | ||
id | ||
} | ||
` | ||
test('valid variables can be given', () => { | ||
g.raw({ document, variables: { filter: true } }) | ||
}) | ||
test('variables property cannot be omitted', () => { | ||
// @ts-expect-error - variables missing | ||
g.raw({ document }) | ||
// @ts-expect-error - variables filter property missing | ||
g.raw({ document, variables: {} }) | ||
}) | ||
test('given variables must be valid types', () => { | ||
// @ts-expect-error - wrong type | ||
g.raw({ document, variables: { filter: 'wrong type' } }) | ||
describe(`data + 1+ variables required`, () => { | ||
const document = gql<{ id: string }, { filter: boolean }>`query { id }` | ||
test(`valid variables can be given`, async ({ kitchenSink: g }) => { | ||
await g.raw({ document, variables: { filter: true } }) | ||
}) | ||
test(`variables property cannot be omitted`, async ({ kitchenSink: g }) => { | ||
// @ts-expect-error - variables missing | ||
await g.raw({ document }) | ||
// @ts-expect-error - variables filter property missing | ||
await g.raw({ document, variables: {} }) | ||
}) | ||
test(`given variables must be valid types`, async ({ kitchenSink: g }) => { | ||
// @ts-expect-error - wrong type | ||
await g.raw({ document, variables: { filter: `wrong type` } }) | ||
}) | ||
}) | ||
}) |