|
| 1 | +/* eslint-disable */ |
| 2 | +import { describe, expect, test } from 'vitest' |
| 3 | +import { db } from '../../tests/_/db.js' |
| 4 | +import { $Index as schemaIndex } from '../../tests/_/schema/generated/SchemaRuntime.js' |
| 5 | +import { schema } from '../../tests/_/schema/schema.js' |
| 6 | +import { __typename } from '../Schema/_.js' |
| 7 | +import { create } from './client.js' |
| 8 | + |
| 9 | +// dprint-ignore |
| 10 | +describe('default', () => { |
| 11 | + const client = create({ schema, schemaIndex }) |
| 12 | + test(`document`, async () => { |
| 13 | + await expect(client.document({ main: { query: { id: true } } }).run()).resolves.toEqual({ id: db.id }) |
| 14 | + }) |
| 15 | + test('raw', async () => { |
| 16 | + await expect(client.raw('query main {\nid\n}', {}, 'main')).resolves.toEqual({ data: { id: db.id } }) |
| 17 | + }) |
| 18 | + test('query field method', async () => { |
| 19 | + await expect(client.query.__typename()).resolves.toEqual('Query') |
| 20 | + }) |
| 21 | + test('query $batch', async () => { |
| 22 | + await expect(client.query.$batch({ __typename: true, id: true })).resolves.toEqual({ __typename: 'Query', id: db.id }) |
| 23 | + }) |
| 24 | + test('mutation field method', async () => { |
| 25 | + await expect(client.mutation.__typename()).resolves.toEqual('Mutation') |
| 26 | + }) |
| 27 | + test('mutation $batch', async () => { |
| 28 | + await expect(client.mutation.$batch({ __typename: true, id: true })).resolves.toEqual({ __typename: 'Mutation', id: db.id }) |
| 29 | + }) |
| 30 | +}) |
| 31 | + |
| 32 | +// dprint-ignore |
| 33 | +describe('data', () => { |
| 34 | + const client = create({ schema, schemaIndex, returnMode: 'data' }) |
| 35 | + test(`document`, async () => { |
| 36 | + await expect(client.document({ main: { query: { id: true } } }).run()).resolves.toEqual({ id: db.id }) |
| 37 | + }) |
| 38 | + test('raw', async () => { |
| 39 | + await expect(client.raw('query main {\nid\n}', {}, 'main')).resolves.toEqual({ data: { id: db.id } }) |
| 40 | + }) |
| 41 | + test('query field method', async () => { |
| 42 | + await expect(client.query.__typename()).resolves.toEqual('Query') |
| 43 | + }) |
| 44 | + test('query $batch', async () => { |
| 45 | + await expect(client.query.$batch({ __typename: true, id: true })).resolves.toEqual({ __typename: 'Query', id: db.id }) |
| 46 | + }) |
| 47 | + test('mutation field method', async () => { |
| 48 | + await expect(client.mutation.__typename()).resolves.toEqual('Mutation') |
| 49 | + }) |
| 50 | + test('mutation $batch', async () => { |
| 51 | + await expect(client.mutation.$batch({ __typename: true, id: true })).resolves.toEqual({ __typename: 'Mutation', id: db.id }) |
| 52 | + }) |
| 53 | +}) |
| 54 | + |
| 55 | +// dprint-ignore |
| 56 | +describe('graphql', () => { |
| 57 | + const client = create({ schema, schemaIndex, returnMode: 'graphql' }) |
| 58 | + test(`document`, async () => { |
| 59 | + await expect(client.document({ main: { query: { id: true } } }).run()).resolves.toEqual({ data: { id: db.id } }) // dprint-ignore |
| 60 | + }) |
| 61 | + test('raw', async () => { |
| 62 | + await expect(client.raw('query main {\nid\n}', {}, 'main')).resolves.toEqual({ data: { id: db.id } }) |
| 63 | + }) |
| 64 | + test('query field method', async () => { |
| 65 | + await expect(client.query.__typename()).resolves.toEqual({ data: { __typename: 'Query' } }) |
| 66 | + }) |
| 67 | + test('query $batch', async () => { |
| 68 | + await expect(client.query.$batch({ __typename: true, id: true })).resolves.toEqual({ data: { __typename: 'Query', id: db.id } }) |
| 69 | + }) |
| 70 | + test('mutation field method', async () => { |
| 71 | + await expect(client.mutation.__typename()).resolves.toEqual({ data: { __typename: 'Mutation' } }) |
| 72 | + }) |
| 73 | + test('mutation $batch', async () => { |
| 74 | + await expect(client.mutation.$batch({ __typename: true, id: true })).resolves.toEqual({ data: { __typename: 'Mutation', id: db.id } }) |
| 75 | + }) |
| 76 | +}) |
0 commit comments