-
Notifications
You must be signed in to change notification settings - Fork 308
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(ts-client): use graphql return mode & named schema
- Loading branch information
1 parent
547dfe5
commit b45dc60
Showing
32 changed files
with
549 additions
and
224 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
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
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
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
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
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
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
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,59 @@ | ||
/* eslint-disable */ | ||
import { ExecutionResult } from 'graphql' | ||
import { ObjMap } from 'graphql/jsutils/ObjMap.js' | ||
import { describe } from 'node:test' | ||
import { expectTypeOf, test } from 'vitest' | ||
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 | ||
describe('default', () => { | ||
const client = create({ schema, schemaIndex }) | ||
test(`document`, async () => { | ||
expectTypeOf(client.document({ main: { query: { id: true } } }).run()).resolves.toEqualTypeOf<{ id: string | null }>() | ||
}) | ||
test(`raw`, async () => { | ||
expectTypeOf(client.raw('query main {\nid\n}', {}, 'main')).resolves.toEqualTypeOf<ExecutionResult>() | ||
}) | ||
test('query field method', async () => { | ||
await expectTypeOf(client.query.__typename()).resolves.toEqualTypeOf<'Query'>() | ||
}) | ||
test('query $batch', async () => { | ||
await expectTypeOf(client.query.$batch({ __typename: true, id: true })).resolves.toEqualTypeOf<{ __typename: 'Query', id: string|null }>() | ||
}) | ||
}) | ||
|
||
// dprint-ignore | ||
describe('data', () => { | ||
const client = create({ schema, schemaIndex, returnMode: 'data' }) | ||
test(`document`, async () => { | ||
expectTypeOf(client.document({ main: { query: { id: true } } }).run()).resolves.toEqualTypeOf<{ id: string | null }>() | ||
}) | ||
test(`raw`, async () => { | ||
expectTypeOf(client.raw('query main {\nid\n}', {}, 'main')).resolves.toEqualTypeOf<ExecutionResult>() | ||
}) | ||
test('query field method', async () => { | ||
await expectTypeOf(client.query.__typename()).resolves.toEqualTypeOf<'Query'>() | ||
}) | ||
test('query $batch', async () => { | ||
await expectTypeOf(client.query.$batch({ __typename: true, id: true })).resolves.toEqualTypeOf<{ __typename: 'Query', id: string|null }>() | ||
}) | ||
}) | ||
|
||
// dprint-ignore | ||
describe('graphql', () => { | ||
const client = create({ schema, schemaIndex, returnMode: 'graphql' }) | ||
test(`document`, async () => { | ||
expectTypeOf(client.document({ main: { query: { id: true } } }).run()).resolves.toEqualTypeOf<ExecutionResult<{ id: string | null }, ObjMap<unknown>>>() | ||
}) | ||
test(`raw`, async () => { | ||
expectTypeOf(client.raw('query main {\nid\n}', {}, 'main')).resolves.toEqualTypeOf<ExecutionResult>() | ||
}) | ||
test('query field method', async () => { | ||
await expectTypeOf(client.query.__typename()).resolves.toEqualTypeOf<ExecutionResult<{ __typename: 'Query' }>>() | ||
}) | ||
test('query $batch', async () => { | ||
await expectTypeOf(client.query.$batch({ __typename: true, id: true })).resolves.toEqualTypeOf<ExecutionResult<{ __typename: 'Query', id: string|null }>>() | ||
}) | ||
}) |
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,76 @@ | ||
/* eslint-disable */ | ||
import { describe, expect, test } from 'vitest' | ||
import { db } from '../../tests/_/db.js' | ||
import { $Index as schemaIndex } from '../../tests/_/schema/generated/SchemaRuntime.js' | ||
import { schema } from '../../tests/_/schema/schema.js' | ||
import { __typename } from '../Schema/_.js' | ||
import { create } from './client.js' | ||
|
||
// dprint-ignore | ||
describe('default', () => { | ||
const client = create({ schema, schemaIndex }) | ||
test(`document`, async () => { | ||
await expect(client.document({ main: { query: { id: true } } }).run()).resolves.toEqual({ id: db.id }) | ||
}) | ||
test('raw', async () => { | ||
await expect(client.raw('query main {\nid\n}', {}, 'main')).resolves.toEqual({ data: { id: db.id } }) | ||
}) | ||
test('query field method', async () => { | ||
await expect(client.query.__typename()).resolves.toEqual('Query') | ||
}) | ||
test('query $batch', async () => { | ||
await expect(client.query.$batch({ __typename: true, id: true })).resolves.toEqual({ __typename: 'Query', id: db.id }) | ||
}) | ||
test('mutation field method', async () => { | ||
await expect(client.mutation.__typename()).resolves.toEqual('Mutation') | ||
}) | ||
test('mutation $batch', async () => { | ||
await expect(client.mutation.$batch({ __typename: true, id: true })).resolves.toEqual({ __typename: 'Mutation', id: db.id }) | ||
}) | ||
}) | ||
|
||
// dprint-ignore | ||
describe('data', () => { | ||
const client = create({ schema, schemaIndex, returnMode: 'data' }) | ||
test(`document`, async () => { | ||
await expect(client.document({ main: { query: { id: true } } }).run()).resolves.toEqual({ id: db.id }) | ||
}) | ||
test('raw', async () => { | ||
await expect(client.raw('query main {\nid\n}', {}, 'main')).resolves.toEqual({ data: { id: db.id } }) | ||
}) | ||
test('query field method', async () => { | ||
await expect(client.query.__typename()).resolves.toEqual('Query') | ||
}) | ||
test('query $batch', async () => { | ||
await expect(client.query.$batch({ __typename: true, id: true })).resolves.toEqual({ __typename: 'Query', id: db.id }) | ||
}) | ||
test('mutation field method', async () => { | ||
await expect(client.mutation.__typename()).resolves.toEqual('Mutation') | ||
}) | ||
test('mutation $batch', async () => { | ||
await expect(client.mutation.$batch({ __typename: true, id: true })).resolves.toEqual({ __typename: 'Mutation', id: db.id }) | ||
}) | ||
}) | ||
|
||
// dprint-ignore | ||
describe('graphql', () => { | ||
const client = create({ schema, schemaIndex, returnMode: 'graphql' }) | ||
test(`document`, async () => { | ||
await expect(client.document({ main: { query: { id: true } } }).run()).resolves.toEqual({ data: { id: db.id } }) // dprint-ignore | ||
}) | ||
test('raw', async () => { | ||
await expect(client.raw('query main {\nid\n}', {}, 'main')).resolves.toEqual({ data: { id: db.id } }) | ||
}) | ||
test('query field method', async () => { | ||
await expect(client.query.__typename()).resolves.toEqual({ data: { __typename: 'Query' } }) | ||
}) | ||
test('query $batch', async () => { | ||
await expect(client.query.$batch({ __typename: true, id: true })).resolves.toEqual({ data: { __typename: 'Query', id: db.id } }) | ||
}) | ||
test('mutation field method', async () => { | ||
await expect(client.mutation.__typename()).resolves.toEqual({ data: { __typename: 'Mutation' } }) | ||
}) | ||
test('mutation $batch', async () => { | ||
await expect(client.mutation.$batch({ __typename: true, id: true })).resolves.toEqual({ data: { __typename: 'Mutation', id: db.id } }) | ||
}) | ||
}) |
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
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
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
Oops, something went wrong.