diff --git a/examples/55_generated/generated_document__document.ts b/examples/55_generated/generated_document__document.ts index e678884e6..97dfdd4d2 100644 --- a/examples/55_generated/generated_document__document.ts +++ b/examples/55_generated/generated_document__document.ts @@ -1,5 +1,5 @@ /** - * This example shows how to use the TypeScript interface for GraphQL arguments. + * This example shows how to use the TypeScript interface for whole GraphQL documents. */ import { Pokemon } from '../$/generated-clients/pokemon/__.js' @@ -8,15 +8,37 @@ import { showJson } from '../$/helpers.js' const pokemon = Pokemon.create() const pokemons = await pokemon.document({ - query: { - pokemonsQuery: { - pokemons: [`pokemons2`, { - $: { filter: { name: { in: [`Pikachu`, `Charizard`] } } }, + query: { // A root type. + pokemonsAndTrainers: { // A name of an the operation. + trainers: { // A root field. + name: true, // A field. + }, + pokemons: { + $: { // A field's arguments + filter: { name: { in: [`Pikachu`, `Charizard`] } }, + }, name: true, - trainer: { name: true }, - }], + trainer: { + name: true, + }, + }, + }, + }, + mutation: { + makeSomeNewPokemons: { + addPokemon: [ + ['addAngryPikachu', { + $: { name: `AngryPikachu`, attack: 100, defense: 100, hp: 100 }, + name: true, + }], + ['addAngryCharizard', { + $: { name: `AngryCharizard`, attack: 100, defense: 100, hp: 100 }, + name: true, + }], + ], }, }, }) + .run('pokemonsAndTrainers') showJson(pokemons) diff --git a/examples/__outputs__/10_transport-http/transport-http_extension_headers__dynamicHeaders.output.txt b/examples/__outputs__/10_transport-http/transport-http_extension_headers__dynamicHeaders.output.txt index 37f474a1e..92a6dde61 100644 --- a/examples/__outputs__/10_transport-http/transport-http_extension_headers__dynamicHeaders.output.txt +++ b/examples/__outputs__/10_transport-http/transport-http_extension_headers__dynamicHeaders.output.txt @@ -4,7 +4,7 @@ headers: Headers { accept: 'application/graphql-response+json; charset=utf-8, application/json; charset=utf-8', 'content-type': 'application/json', - 'x-sent-at-time': '1727291929241' + 'x-sent-at-time': '1727310087052' }, signal: undefined, method: 'post', diff --git a/examples/__outputs__/20_output/output_envelope.output.txt b/examples/__outputs__/20_output/output_envelope.output.txt index fc4008eb1..3890803e2 100644 --- a/examples/__outputs__/20_output/output_envelope.output.txt +++ b/examples/__outputs__/20_output/output_envelope.output.txt @@ -16,7 +16,7 @@ headers: Headers { 'content-type': 'application/graphql-response+json; charset=utf-8', 'content-length': '104', - date: 'Wed, 25 Sep 2024 19:18:49 GMT', + date: 'Thu, 26 Sep 2024 00:21:27 GMT', connection: 'keep-alive', 'keep-alive': 'timeout=5' }, diff --git a/examples/__outputs__/55_generated/generated_document__document.output.txt b/examples/__outputs__/55_generated/generated_document__document.output.txt index 06f6758cd..a652c4b5f 100644 --- a/examples/__outputs__/55_generated/generated_document__document.output.txt +++ b/examples/__outputs__/55_generated/generated_document__document.output.txt @@ -1,2 +1,25 @@ ---------------------------------------- SHOW ---------------------------------------- -{} \ No newline at end of file +{ + "trainers": [ + { + "name": "Ash" + }, + { + "name": "Misty" + } + ], + "pokemons": [ + { + "name": "Pikachu", + "trainer": { + "name": "Ash" + } + }, + { + "name": "Charizard", + "trainer": { + "name": "Ash" + } + } + ] +} \ No newline at end of file diff --git a/examples/__outputs__/60_extension/extension_opentelemetry__opentelemetry.output.txt b/examples/__outputs__/60_extension/extension_opentelemetry__opentelemetry.output.txt index 4f727d2e8..95db827c1 100644 --- a/examples/__outputs__/60_extension/extension_opentelemetry__opentelemetry.output.txt +++ b/examples/__outputs__/60_extension/extension_opentelemetry__opentelemetry.output.txt @@ -9,14 +9,14 @@ } }, instrumentationScope: { name: 'graffle', version: undefined, schemaUrl: undefined }, - traceId: '9d154073558dfe77a07840d133b4358c', - parentId: '57916921f30d3744', + traceId: 'f384fda0c6aa8cdc0600586696d83aac', + parentId: '78959de15b116846', traceState: undefined, name: 'encode', - id: 'dcdd7c9ea7a24491', + id: 'e78df0ee2a54acb6', kind: 0, - timestamp: 1727291930021000, - duration: 1392.459, + timestamp: 1727310087760000, + duration: 554.291, attributes: {}, status: { code: 0 }, events: [], @@ -33,14 +33,14 @@ } }, instrumentationScope: { name: 'graffle', version: undefined, schemaUrl: undefined }, - traceId: '9d154073558dfe77a07840d133b4358c', - parentId: '57916921f30d3744', + traceId: 'f384fda0c6aa8cdc0600586696d83aac', + parentId: '78959de15b116846', traceState: undefined, name: 'pack', - id: 'd1ca1155f050f30c', + id: '88b5c48ab9be7a36', kind: 0, - timestamp: 1727291930024000, - duration: 16745.417, + timestamp: 1727310087845000, + duration: 17482.625, attributes: {}, status: { code: 0 }, events: [], @@ -57,14 +57,14 @@ } }, instrumentationScope: { name: 'graffle', version: undefined, schemaUrl: undefined }, - traceId: '9d154073558dfe77a07840d133b4358c', - parentId: '57916921f30d3744', + traceId: 'f384fda0c6aa8cdc0600586696d83aac', + parentId: '78959de15b116846', traceState: undefined, name: 'exchange', - id: 'c9978fd02d8f3228', + id: 'd4a611cb0daf3ac1', kind: 0, - timestamp: 1727291930042000, - duration: 24516.084, + timestamp: 1727310087867000, + duration: 48095.333, attributes: {}, status: { code: 0 }, events: [], @@ -81,14 +81,14 @@ } }, instrumentationScope: { name: 'graffle', version: undefined, schemaUrl: undefined }, - traceId: '9d154073558dfe77a07840d133b4358c', - parentId: '57916921f30d3744', + traceId: 'f384fda0c6aa8cdc0600586696d83aac', + parentId: '78959de15b116846', traceState: undefined, name: 'unpack', - id: '663a79043ef1feea', + id: '20d213f3a3f86f1d', kind: 0, - timestamp: 1727291930067000, - duration: 1665.125, + timestamp: 1727310087916000, + duration: 1125.833, attributes: {}, status: { code: 0 }, events: [], @@ -105,14 +105,14 @@ } }, instrumentationScope: { name: 'graffle', version: undefined, schemaUrl: undefined }, - traceId: '9d154073558dfe77a07840d133b4358c', - parentId: '57916921f30d3744', + traceId: 'f384fda0c6aa8cdc0600586696d83aac', + parentId: '78959de15b116846', traceState: undefined, name: 'decode', - id: '9fd8d38e892a7a50', + id: 'c35ae080bfb451be', kind: 0, - timestamp: 1727291930068000, - duration: 184.333, + timestamp: 1727310087917000, + duration: 181.958, attributes: {}, status: { code: 0 }, events: [], @@ -129,14 +129,14 @@ } }, instrumentationScope: { name: 'graffle', version: undefined, schemaUrl: undefined }, - traceId: '9d154073558dfe77a07840d133b4358c', + traceId: 'f384fda0c6aa8cdc0600586696d83aac', parentId: undefined, traceState: undefined, name: 'request', - id: '57916921f30d3744', + id: '78959de15b116846', kind: 0, - timestamp: 1727291930020000, - duration: 48270.291, + timestamp: 1727310087759000, + duration: 158234.5, attributes: {}, status: { code: 0 }, events: [], diff --git a/package.json b/package.json index 9808b450c..496c63caf 100644 --- a/package.json +++ b/package.json @@ -91,7 +91,7 @@ "test:examples": "vitest --config vitest.examples.config.ts --dir tests/examples", "test": "vitest", "test:web": "vitest --environment jsdom", - "test:types": "vitest --typecheck src/**/**/*.test-d.ts", + "test:types": "vitest --typecheck --dir src --testNamePattern .*.test-d.ts", "test:coverage": "pnpm test -- --coverage", "release:stable": "dripip stable", "release:preview": "dripip preview", diff --git a/src/layers/6_client/requestMethods/document.test-d.ts b/src/layers/6_client/requestMethods/document.test-d.ts index a30b32f65..1a52bba3f 100644 --- a/src/layers/6_client/requestMethods/document.test-d.ts +++ b/src/layers/6_client/requestMethods/document.test-d.ts @@ -1,4 +1,4 @@ -import { describe, expectTypeOf, test } from 'vitest' +import { expectTypeOf, test } from 'vitest' import { Graffle } from '../../../../tests/_/schema/generated/__.js' import * as Schema from '../../../../tests/_/schema/schema.js' import { MutationOnly } from '../../../../tests/_/schemaMutationOnly/generated/__.js' @@ -16,65 +16,57 @@ test(`requires input`, () => { // graffle.document({}) }) -describe(`input`, () => { - test(`document with one query`, () => { - const run = graffle.document({ query: { foo: { id: true } } }).run - expectTypeOf(run).toMatchTypeOf<(...params: ['foo'] | [] | [undefined]) => Promise>() - }) +test(`document with one query`, async () => { + const run = graffle.document({ query: { foo: { id: true } } }).run + type $Parameters = Parameters + expectTypeOf<$Parameters>().toEqualTypeOf<[]>() + const result = await run() + expectTypeOf(result).toEqualTypeOf<{ id: string | null }>() +}) - test(`document with two queries`, () => { - const run = graffle.document({ - query: { - foo: { id: true }, - bar: { id: true }, - }, - }).run - expectTypeOf(run).toMatchTypeOf<(name: 'foo' | 'bar') => Promise>() - }) +test(`document with two queries`, async () => { + const run = graffle.document({ + query: { + foo: { id: true }, + bar: { date: true }, + }, + }).run + type $Parameters = Parameters + expectTypeOf<$Parameters>().toEqualTypeOf<['foo' | 'bar']>() + const result = await run(`foo`) + expectTypeOf(result).toEqualTypeOf<{ id: string | null }>() +}) - test(`root operation not available if it is not in schema`, () => { - const queryOnly = QueryOnly.create({ - schema: SchemaQueryOnly.schema, - }) - queryOnly.document({ - query: { foo: { id: true } }, - // todo - // // @ts-expect-error mutation not in schema - // mutation: { foo: { id: true } }, - }) - const mutationOnly = MutationOnly.create({ - schema: SchemaMutationOnly.schema, - }) - mutationOnly.document({ - // @ts-expect-error query not in schema - foo: { query: { id: true } }, - bar: { mutation: { id: true } }, - }) - }) +test(`document with two queries of different root types`, async () => { + const run = graffle.document({ + query: { + foo: { id: true }, + }, + mutation: { + bar: { idNonNull: true }, + }, + }).run + type $Parameters = Parameters + expectTypeOf<$Parameters>().toEqualTypeOf<['foo' | 'bar']>() + const result = await run(`foo`) + expectTypeOf(result).toEqualTypeOf<{ id: string | null }>() }) -describe(`document(...).run()`, () => { - test(`document with one query`, () => { - { - const result = graffle.document({ query: { x: { id: true } } }).run() - expectTypeOf(result).resolves.toEqualTypeOf<{ id: string | null }>() - } - { - const result = graffle.document({ query: { x: { id: true } } }).run(`x`) - expectTypeOf(result).resolves.toEqualTypeOf<{ id: string | null }>() - } - { - const result = graffle.document({ query: { x: { id: true } } }).run(undefined) - expectTypeOf(result).resolves.toEqualTypeOf<{ id: string | null }>() - } +test(`root operation not available if it is not in schema`, () => { + const queryOnly = QueryOnly.create({ + schema: SchemaQueryOnly.schema, + }) + queryOnly.document({ + query: { foo: { id: true } }, + // @ts-expect-error mutation not in schema + mutation: { foo: { id: true } }, + }) + const mutationOnly = MutationOnly.create({ + schema: SchemaMutationOnly.schema, }) - test(`document with two queries`, () => { - const result = graffle.document({ - query: { - foo: { id: true }, - bar: { id: true }, - }, - }).run(`foo`) - expectTypeOf(result).resolves.toEqualTypeOf<{ id: string | null }>() + mutationOnly.document({ + mutation: { bar: { id: true } }, + // @ts-expect-error query not in schema + query: { foo: { id: true } }, }) }) diff --git a/src/layers/6_client/requestMethods/document.test.ts b/src/layers/6_client/requestMethods/document.test.ts index 33552e031..fdaf66d00 100644 --- a/src/layers/6_client/requestMethods/document.test.ts +++ b/src/layers/6_client/requestMethods/document.test.ts @@ -73,16 +73,12 @@ describe(`document with two queries`, () => { test(`document with one query`, async () => { const { run } = graffle.document({ query: { foo: { id: true } } }) - await expect(run(`foo`)).resolves.toEqual({ id: db.id1 }) await expect(run()).resolves.toEqual({ id: db.id1 }) - await expect(run(undefined)).resolves.toEqual({ id: db.id1 }) }) test(`document with one mutation`, async () => { const { run } = graffle.document({ mutation: { foo: { id: true } } }) - await expect(run(`foo`)).resolves.toEqual({ id: db.id1 }) await expect(run()).resolves.toEqual({ id: db.id1 }) - await expect(run(undefined)).resolves.toEqual({ id: db.id1 }) }) test(`error`, async () => { diff --git a/src/layers/6_client/requestMethods/document.ts b/src/layers/6_client/requestMethods/document.ts index 5594079b6..7d9b3703b 100644 --- a/src/layers/6_client/requestMethods/document.ts +++ b/src/layers/6_client/requestMethods/document.ts @@ -14,9 +14,21 @@ export type DocumentRunner< $$Name extends Document.GetOperationNames<$$Document> = Document.GetOperationNames<$$Document> > = { run: < - $Name extends $$Name, - $Params extends (IsTupleMultiple> extends true ? [name: $Name] : ([] | [name: $Name | undefined])), + $Params extends (IsTupleMultiple> extends true ? [name: $$Name] : []), + const $Name extends string = $Params extends [] ? $$Name : $Params[0], >(...params: $Params) => + // [$Name] + // ResultSet.Root< + // AddTypenameToSelectedRootTypeResultFields< + // $$Config, + // $$Index, + // Document.GetRootTypeNameOfOperation<$$Document, $Name>, + // Document.GetOperation<$$Document, $Name> + // >, + // $$Index, + // Document.GetRootTypeNameOfOperation<$$Document, $Name> + // > + // Promise< ResolveOutputReturnRootType< $$Config, diff --git a/website/content/_snippets/example-links/raw.md b/website/content/_snippets/example-links/raw.md index bb1caa8bb..ea6f96190 100644 --- a/website/content/_snippets/example-links/raw.md +++ b/website/content/_snippets/example-links/raw.md @@ -1 +1 @@ - + diff --git a/website/content/_snippets/examples/extension/opentelemetry.detail.md b/website/content/_snippets/examples/extension/opentelemetry.detail.md index b651cb1e9..67463b1b5 100644 --- a/website/content/_snippets/examples/extension/opentelemetry.detail.md +++ b/website/content/_snippets/examples/extension/opentelemetry.detail.md @@ -38,14 +38,14 @@ console.log(data) } }, instrumentationScope: { name: 'graffle', version: undefined, schemaUrl: undefined }, - traceId: '9d154073558dfe77a07840d133b4358c', - parentId: '57916921f30d3744', + traceId: 'f384fda0c6aa8cdc0600586696d83aac', + parentId: '78959de15b116846', traceState: undefined, name: 'encode', - id: 'dcdd7c9ea7a24491', + id: 'e78df0ee2a54acb6', kind: 0, - timestamp: 1727291930021000, - duration: 1392.459, + timestamp: 1727310087760000, + duration: 554.291, attributes: {}, status: { code: 0 }, events: [], @@ -65,14 +65,14 @@ console.log(data) } }, instrumentationScope: { name: 'graffle', version: undefined, schemaUrl: undefined }, - traceId: '9d154073558dfe77a07840d133b4358c', - parentId: '57916921f30d3744', + traceId: 'f384fda0c6aa8cdc0600586696d83aac', + parentId: '78959de15b116846', traceState: undefined, name: 'pack', - id: 'd1ca1155f050f30c', + id: '88b5c48ab9be7a36', kind: 0, - timestamp: 1727291930024000, - duration: 16745.417, + timestamp: 1727310087845000, + duration: 17482.625, attributes: {}, status: { code: 0 }, events: [], @@ -92,14 +92,14 @@ console.log(data) } }, instrumentationScope: { name: 'graffle', version: undefined, schemaUrl: undefined }, - traceId: '9d154073558dfe77a07840d133b4358c', - parentId: '57916921f30d3744', + traceId: 'f384fda0c6aa8cdc0600586696d83aac', + parentId: '78959de15b116846', traceState: undefined, name: 'exchange', - id: 'c9978fd02d8f3228', + id: 'd4a611cb0daf3ac1', kind: 0, - timestamp: 1727291930042000, - duration: 24516.084, + timestamp: 1727310087867000, + duration: 48095.333, attributes: {}, status: { code: 0 }, events: [], @@ -119,14 +119,14 @@ console.log(data) } }, instrumentationScope: { name: 'graffle', version: undefined, schemaUrl: undefined }, - traceId: '9d154073558dfe77a07840d133b4358c', - parentId: '57916921f30d3744', + traceId: 'f384fda0c6aa8cdc0600586696d83aac', + parentId: '78959de15b116846', traceState: undefined, name: 'unpack', - id: '663a79043ef1feea', + id: '20d213f3a3f86f1d', kind: 0, - timestamp: 1727291930067000, - duration: 1665.125, + timestamp: 1727310087916000, + duration: 1125.833, attributes: {}, status: { code: 0 }, events: [], @@ -146,14 +146,14 @@ console.log(data) } }, instrumentationScope: { name: 'graffle', version: undefined, schemaUrl: undefined }, - traceId: '9d154073558dfe77a07840d133b4358c', - parentId: '57916921f30d3744', + traceId: 'f384fda0c6aa8cdc0600586696d83aac', + parentId: '78959de15b116846', traceState: undefined, name: 'decode', - id: '9fd8d38e892a7a50', + id: 'c35ae080bfb451be', kind: 0, - timestamp: 1727291930068000, - duration: 184.333, + timestamp: 1727310087917000, + duration: 181.958, attributes: {}, status: { code: 0 }, events: [], @@ -173,14 +173,14 @@ console.log(data) } }, instrumentationScope: { name: 'graffle', version: undefined, schemaUrl: undefined }, - traceId: '9d154073558dfe77a07840d133b4358c', + traceId: 'f384fda0c6aa8cdc0600586696d83aac', parentId: undefined, traceState: undefined, name: 'request', - id: '57916921f30d3744', + id: '78959de15b116846', kind: 0, - timestamp: 1727291930020000, - duration: 48270.291, + timestamp: 1727310087759000, + duration: 158234.5, attributes: {}, status: { code: 0 }, events: [], diff --git a/website/content/_snippets/examples/extension/opentelemetry.md b/website/content/_snippets/examples/extension/opentelemetry.md index 547091033..dd98c6ee1 100644 --- a/website/content/_snippets/examples/extension/opentelemetry.md +++ b/website/content/_snippets/examples/extension/opentelemetry.md @@ -36,14 +36,14 @@ console.log(data) } }, instrumentationScope: { name: 'graffle', version: undefined, schemaUrl: undefined }, - traceId: '9d154073558dfe77a07840d133b4358c', - parentId: '57916921f30d3744', + traceId: 'f384fda0c6aa8cdc0600586696d83aac', + parentId: '78959de15b116846', traceState: undefined, name: 'encode', - id: 'dcdd7c9ea7a24491', + id: 'e78df0ee2a54acb6', kind: 0, - timestamp: 1727291930021000, - duration: 1392.459, + timestamp: 1727310087760000, + duration: 554.291, attributes: {}, status: { code: 0 }, events: [], @@ -63,14 +63,14 @@ console.log(data) } }, instrumentationScope: { name: 'graffle', version: undefined, schemaUrl: undefined }, - traceId: '9d154073558dfe77a07840d133b4358c', - parentId: '57916921f30d3744', + traceId: 'f384fda0c6aa8cdc0600586696d83aac', + parentId: '78959de15b116846', traceState: undefined, name: 'pack', - id: 'd1ca1155f050f30c', + id: '88b5c48ab9be7a36', kind: 0, - timestamp: 1727291930024000, - duration: 16745.417, + timestamp: 1727310087845000, + duration: 17482.625, attributes: {}, status: { code: 0 }, events: [], @@ -90,14 +90,14 @@ console.log(data) } }, instrumentationScope: { name: 'graffle', version: undefined, schemaUrl: undefined }, - traceId: '9d154073558dfe77a07840d133b4358c', - parentId: '57916921f30d3744', + traceId: 'f384fda0c6aa8cdc0600586696d83aac', + parentId: '78959de15b116846', traceState: undefined, name: 'exchange', - id: 'c9978fd02d8f3228', + id: 'd4a611cb0daf3ac1', kind: 0, - timestamp: 1727291930042000, - duration: 24516.084, + timestamp: 1727310087867000, + duration: 48095.333, attributes: {}, status: { code: 0 }, events: [], @@ -117,14 +117,14 @@ console.log(data) } }, instrumentationScope: { name: 'graffle', version: undefined, schemaUrl: undefined }, - traceId: '9d154073558dfe77a07840d133b4358c', - parentId: '57916921f30d3744', + traceId: 'f384fda0c6aa8cdc0600586696d83aac', + parentId: '78959de15b116846', traceState: undefined, name: 'unpack', - id: '663a79043ef1feea', + id: '20d213f3a3f86f1d', kind: 0, - timestamp: 1727291930067000, - duration: 1665.125, + timestamp: 1727310087916000, + duration: 1125.833, attributes: {}, status: { code: 0 }, events: [], @@ -144,14 +144,14 @@ console.log(data) } }, instrumentationScope: { name: 'graffle', version: undefined, schemaUrl: undefined }, - traceId: '9d154073558dfe77a07840d133b4358c', - parentId: '57916921f30d3744', + traceId: 'f384fda0c6aa8cdc0600586696d83aac', + parentId: '78959de15b116846', traceState: undefined, name: 'decode', - id: '9fd8d38e892a7a50', + id: 'c35ae080bfb451be', kind: 0, - timestamp: 1727291930068000, - duration: 184.333, + timestamp: 1727310087917000, + duration: 181.958, attributes: {}, status: { code: 0 }, events: [], @@ -171,14 +171,14 @@ console.log(data) } }, instrumentationScope: { name: 'graffle', version: undefined, schemaUrl: undefined }, - traceId: '9d154073558dfe77a07840d133b4358c', + traceId: 'f384fda0c6aa8cdc0600586696d83aac', parentId: undefined, traceState: undefined, name: 'request', - id: '57916921f30d3744', + id: '78959de15b116846', kind: 0, - timestamp: 1727291930020000, - duration: 48270.291, + timestamp: 1727310087759000, + duration: 158234.5, attributes: {}, status: { code: 0 }, events: [], diff --git a/website/content/_snippets/examples/generated/document.detail.md b/website/content/_snippets/examples/generated/document.detail.md index 075a61e44..c231a6e0d 100644 --- a/website/content/_snippets/examples/generated/document.detail.md +++ b/website/content/_snippets/examples/generated/document.detail.md @@ -11,16 +11,38 @@ import { Pokemon } from './pokemon/__.js' const pokemon = Pokemon.create() const pokemons = await pokemon.document({ - query: { - pokemonsQuery: { - pokemons: [`pokemons2`, { - $: { filter: { name: { in: [`Pikachu`, `Charizard`] } } }, + query: { // A root type. + pokemonsAndTrainers: { // A name of an the operation. + trainers: { // A root field. + name: true, // A field. + }, + pokemons: { + $: { // A field's arguments + filter: { name: { in: [`Pikachu`, `Charizard`] } }, + }, name: true, - trainer: { name: true }, - }], + trainer: { + name: true, + }, + }, + }, + }, + mutation: { + makeSomeNewPokemons: { + addPokemon: [ + ['addAngryPikachu', { + $: { name: `AngryPikachu`, attack: 100, defense: 100, hp: 100 }, + name: true, + }], + ['addAngryCharizard', { + $: { name: `AngryCharizard`, attack: 100, defense: 100, hp: 100 }, + name: true, + }], + ], }, }, }) + .run('pokemonsAndTrainers') console.log(pokemons) ``` @@ -28,7 +50,30 @@ console.log(pokemons) ```json -{} +{ + "trainers": [ + { + "name": "Ash" + }, + { + "name": "Misty" + } + ], + "pokemons": [ + { + "name": "Pikachu", + "trainer": { + "name": "Ash" + } + }, + { + "name": "Charizard", + "trainer": { + "name": "Ash" + } + } + ] +} ``` diff --git a/website/content/_snippets/examples/generated/document.md b/website/content/_snippets/examples/generated/document.md index ecaecfc57..20c7e3194 100644 --- a/website/content/_snippets/examples/generated/document.md +++ b/website/content/_snippets/examples/generated/document.md @@ -9,16 +9,38 @@ import { Pokemon } from './pokemon/__.js' const pokemon = Pokemon.create() const pokemons = await pokemon.document({ - query: { - pokemonsQuery: { - pokemons: [`pokemons2`, { - $: { filter: { name: { in: [`Pikachu`, `Charizard`] } } }, + query: { // A root type. + pokemonsAndTrainers: { // A name of an the operation. + trainers: { // A root field. + name: true, // A field. + }, + pokemons: { + $: { // A field's arguments + filter: { name: { in: [`Pikachu`, `Charizard`] } }, + }, name: true, - trainer: { name: true }, - }], + trainer: { + name: true, + }, + }, + }, + }, + mutation: { + makeSomeNewPokemons: { + addPokemon: [ + ['addAngryPikachu', { + $: { name: `AngryPikachu`, attack: 100, defense: 100, hp: 100 }, + name: true, + }], + ['addAngryCharizard', { + $: { name: `AngryCharizard`, attack: 100, defense: 100, hp: 100 }, + name: true, + }], + ], }, }, }) + .run('pokemonsAndTrainers') console.log(pokemons) ``` @@ -26,7 +48,30 @@ console.log(pokemons) ```json -{} +{ + "trainers": [ + { + "name": "Ash" + }, + { + "name": "Misty" + } + ], + "pokemons": [ + { + "name": "Pikachu", + "trainer": { + "name": "Ash" + } + }, + { + "name": "Charizard", + "trainer": { + "name": "Ash" + } + } + ] +} ``` diff --git a/website/content/_snippets/examples/output/envelope.detail.md b/website/content/_snippets/examples/output/envelope.detail.md index 2dd87e18b..d95f8a58e 100644 --- a/website/content/_snippets/examples/output/envelope.detail.md +++ b/website/content/_snippets/examples/output/envelope.detail.md @@ -39,7 +39,7 @@ console.log(result) headers: Headers { 'content-type': 'application/graphql-response+json; charset=utf-8', 'content-length': '104', - date: 'Wed, 25 Sep 2024 19:18:49 GMT', + date: 'Thu, 26 Sep 2024 00:21:27 GMT', connection: 'keep-alive', 'keep-alive': 'timeout=5' }, diff --git a/website/content/_snippets/examples/output/envelope.md b/website/content/_snippets/examples/output/envelope.md index 1ea1c91ce..249964428 100644 --- a/website/content/_snippets/examples/output/envelope.md +++ b/website/content/_snippets/examples/output/envelope.md @@ -37,7 +37,7 @@ console.log(result) headers: Headers { 'content-type': 'application/graphql-response+json; charset=utf-8', 'content-length': '104', - date: 'Wed, 25 Sep 2024 19:18:49 GMT', + date: 'Thu, 26 Sep 2024 00:21:27 GMT', connection: 'keep-alive', 'keep-alive': 'timeout=5' }, diff --git a/website/content/_snippets/examples/transport-http/dynamic-headers.detail.md b/website/content/_snippets/examples/transport-http/dynamic-headers.detail.md index 138052ab9..8be55c700 100644 --- a/website/content/_snippets/examples/transport-http/dynamic-headers.detail.md +++ b/website/content/_snippets/examples/transport-http/dynamic-headers.detail.md @@ -38,7 +38,7 @@ await graffle.rawString({ document: `{ pokemons { name } }` }) headers: Headers { accept: 'application/graphql-response+json; charset=utf-8, application/json; charset=utf-8', 'content-type': 'application/json', - 'x-sent-at-time': '1727291929241' + 'x-sent-at-time': '1727310087052' }, signal: undefined, method: 'post', diff --git a/website/content/_snippets/examples/transport-http/dynamic-headers.md b/website/content/_snippets/examples/transport-http/dynamic-headers.md index 13317fa59..818071623 100644 --- a/website/content/_snippets/examples/transport-http/dynamic-headers.md +++ b/website/content/_snippets/examples/transport-http/dynamic-headers.md @@ -36,7 +36,7 @@ await graffle.rawString({ document: `{ pokemons { name } }` }) headers: Headers { accept: 'application/graphql-response+json; charset=utf-8, application/json; charset=utf-8', 'content-type': 'application/json', - 'x-sent-at-time': '1727291929241' + 'x-sent-at-time': '1727310087052' }, signal: undefined, method: 'post', diff --git a/website/content/examples/10_transport-http/dynamic-headers.md b/website/content/examples/10_transport-http/dynamic-headers.md index 1e9eb0d96..3a693f977 100644 --- a/website/content/examples/10_transport-http/dynamic-headers.md +++ b/website/content/examples/10_transport-http/dynamic-headers.md @@ -43,7 +43,7 @@ await graffle.rawString({ document: `{ pokemons { name } }` }) headers: Headers { accept: 'application/graphql-response+json; charset=utf-8, application/json; charset=utf-8', 'content-type': 'application/json', - 'x-sent-at-time': '1727291929241' + 'x-sent-at-time': '1727310087052' }, signal: undefined, method: 'post', diff --git a/website/content/examples/20_output/envelope.md b/website/content/examples/20_output/envelope.md index d330664cb..387d43a87 100644 --- a/website/content/examples/20_output/envelope.md +++ b/website/content/examples/20_output/envelope.md @@ -44,7 +44,7 @@ console.log(result) headers: Headers { 'content-type': 'application/graphql-response+json; charset=utf-8', 'content-length': '104', - date: 'Wed, 25 Sep 2024 19:18:49 GMT', + date: 'Thu, 26 Sep 2024 00:21:27 GMT', connection: 'keep-alive', 'keep-alive': 'timeout=5' }, diff --git a/website/content/examples/55_generated/document.md b/website/content/examples/55_generated/document.md index 7df736065..54e8450d6 100644 --- a/website/content/examples/55_generated/document.md +++ b/website/content/examples/55_generated/document.md @@ -4,7 +4,7 @@ aside: false # Document -This example shows how to use the TypeScript interface for GraphQL arguments. +This example shows how to use the TypeScript interface for whole GraphQL documents. ```ts twoslash @@ -14,16 +14,38 @@ import { Pokemon } from './pokemon/__.js' const pokemon = Pokemon.create() const pokemons = await pokemon.document({ - query: { - pokemonsQuery: { - pokemons: [`pokemons2`, { - $: { filter: { name: { in: [`Pikachu`, `Charizard`] } } }, + query: { // A root type. + pokemonsAndTrainers: { // A name of an the operation. + trainers: { // A root field. + name: true, // A field. + }, + pokemons: { + $: { // A field's arguments + filter: { name: { in: [`Pikachu`, `Charizard`] } }, + }, name: true, - trainer: { name: true }, - }], + trainer: { + name: true, + }, + }, + }, + }, + mutation: { + makeSomeNewPokemons: { + addPokemon: [ + ['addAngryPikachu', { + $: { name: `AngryPikachu`, attack: 100, defense: 100, hp: 100 }, + name: true, + }], + ['addAngryCharizard', { + $: { name: `AngryCharizard`, attack: 100, defense: 100, hp: 100 }, + name: true, + }], + ], }, }, }) + .run('pokemonsAndTrainers') console.log(pokemons) ``` @@ -33,6 +55,29 @@ console.log(pokemons) ```json -{} +{ + "trainers": [ + { + "name": "Ash" + }, + { + "name": "Misty" + } + ], + "pokemons": [ + { + "name": "Pikachu", + "trainer": { + "name": "Ash" + } + }, + { + "name": "Charizard", + "trainer": { + "name": "Ash" + } + } + ] +} ``` diff --git a/website/content/examples/60_extension/opentelemetry.md b/website/content/examples/60_extension/opentelemetry.md index b18c047ef..a79620080 100644 --- a/website/content/examples/60_extension/opentelemetry.md +++ b/website/content/examples/60_extension/opentelemetry.md @@ -41,14 +41,14 @@ console.log(data) } }, instrumentationScope: { name: 'graffle', version: undefined, schemaUrl: undefined }, - traceId: '9d154073558dfe77a07840d133b4358c', - parentId: '57916921f30d3744', + traceId: 'f384fda0c6aa8cdc0600586696d83aac', + parentId: '78959de15b116846', traceState: undefined, name: 'encode', - id: 'dcdd7c9ea7a24491', + id: 'e78df0ee2a54acb6', kind: 0, - timestamp: 1727291930021000, - duration: 1392.459, + timestamp: 1727310087760000, + duration: 554.291, attributes: {}, status: { code: 0 }, events: [], @@ -68,14 +68,14 @@ console.log(data) } }, instrumentationScope: { name: 'graffle', version: undefined, schemaUrl: undefined }, - traceId: '9d154073558dfe77a07840d133b4358c', - parentId: '57916921f30d3744', + traceId: 'f384fda0c6aa8cdc0600586696d83aac', + parentId: '78959de15b116846', traceState: undefined, name: 'pack', - id: 'd1ca1155f050f30c', + id: '88b5c48ab9be7a36', kind: 0, - timestamp: 1727291930024000, - duration: 16745.417, + timestamp: 1727310087845000, + duration: 17482.625, attributes: {}, status: { code: 0 }, events: [], @@ -95,14 +95,14 @@ console.log(data) } }, instrumentationScope: { name: 'graffle', version: undefined, schemaUrl: undefined }, - traceId: '9d154073558dfe77a07840d133b4358c', - parentId: '57916921f30d3744', + traceId: 'f384fda0c6aa8cdc0600586696d83aac', + parentId: '78959de15b116846', traceState: undefined, name: 'exchange', - id: 'c9978fd02d8f3228', + id: 'd4a611cb0daf3ac1', kind: 0, - timestamp: 1727291930042000, - duration: 24516.084, + timestamp: 1727310087867000, + duration: 48095.333, attributes: {}, status: { code: 0 }, events: [], @@ -122,14 +122,14 @@ console.log(data) } }, instrumentationScope: { name: 'graffle', version: undefined, schemaUrl: undefined }, - traceId: '9d154073558dfe77a07840d133b4358c', - parentId: '57916921f30d3744', + traceId: 'f384fda0c6aa8cdc0600586696d83aac', + parentId: '78959de15b116846', traceState: undefined, name: 'unpack', - id: '663a79043ef1feea', + id: '20d213f3a3f86f1d', kind: 0, - timestamp: 1727291930067000, - duration: 1665.125, + timestamp: 1727310087916000, + duration: 1125.833, attributes: {}, status: { code: 0 }, events: [], @@ -149,14 +149,14 @@ console.log(data) } }, instrumentationScope: { name: 'graffle', version: undefined, schemaUrl: undefined }, - traceId: '9d154073558dfe77a07840d133b4358c', - parentId: '57916921f30d3744', + traceId: 'f384fda0c6aa8cdc0600586696d83aac', + parentId: '78959de15b116846', traceState: undefined, name: 'decode', - id: '9fd8d38e892a7a50', + id: 'c35ae080bfb451be', kind: 0, - timestamp: 1727291930068000, - duration: 184.333, + timestamp: 1727310087917000, + duration: 181.958, attributes: {}, status: { code: 0 }, events: [], @@ -176,14 +176,14 @@ console.log(data) } }, instrumentationScope: { name: 'graffle', version: undefined, schemaUrl: undefined }, - traceId: '9d154073558dfe77a07840d133b4358c', + traceId: 'f384fda0c6aa8cdc0600586696d83aac', parentId: undefined, traceState: undefined, name: 'request', - id: '57916921f30d3744', + id: '78959de15b116846', kind: 0, - timestamp: 1727291930020000, - duration: 48270.291, + timestamp: 1727310087759000, + duration: 158234.5, attributes: {}, status: { code: 0 }, events: [],