From 44cab1eec8b19800fcdac90c12d88d3645a56ff5 Mon Sep 17 00:00:00 2001 From: Jason Kuhrt Date: Mon, 14 Oct 2024 09:23:09 -0400 Subject: [PATCH] chore(docs): make gql examples more idiomatic --- examples/30_gql/gql_gql-string.ts | 8 +-- ..._gql-string_gql-typed__gql-string-typed.ts | 10 ++-- ...tension_headers__dynamicHeaders.output.txt | 2 +- .../20_output/output_envelope.output.txt | 2 +- ...on_opentelemetry__opentelemetry.output.txt | 58 +++++++++---------- .../_snippets/example-links/extension.md | 2 +- .../extension/opentelemetry.detail.md | 58 +++++++++---------- .../examples/extension/opentelemetry.md | 58 +++++++++---------- .../examples/gql/gql-string-typed.detail.md | 6 +- .../examples/gql/gql-string-typed.md | 6 +- .../examples/gql/gql-string.detail.md | 8 +-- .../_snippets/examples/gql/gql-string.md | 8 +-- .../examples/output/envelope.detail.md | 2 +- .../_snippets/examples/output/envelope.md | 2 +- .../transport-http/dynamic-headers.detail.md | 2 +- .../transport-http/dynamic-headers.md | 2 +- .../10_transport-http/dynamic-headers.md | 2 +- .../content/examples/20_output/envelope.md | 2 +- .../examples/30_gql/gql-string-typed.md | 10 ++-- website/content/examples/30_gql/gql-string.md | 8 +-- .../examples/60_extension/opentelemetry.md | 58 +++++++++---------- 21 files changed, 149 insertions(+), 165 deletions(-) diff --git a/examples/30_gql/gql_gql-string.ts b/examples/30_gql/gql_gql-string.ts index 3af60eb0..80603684 100644 --- a/examples/30_gql/gql_gql-string.ts +++ b/examples/30_gql/gql_gql-string.ts @@ -9,14 +9,12 @@ const graffle = Graffle.create({ schema: publicGraphQLSchemaEndpoints.Pokemon, }) -const document = /* gql */ ` +const data = await graffle.gql` { pokemon { name } - } -` - -const data = await graffle.gql(document).send() + } +`.send() show(data) diff --git a/examples/30_gql/gql_gql-string_gql-typed__gql-string-typed.ts b/examples/30_gql/gql_gql-string_gql-typed__gql-string-typed.ts index d6a51074..991028c7 100644 --- a/examples/30_gql/gql_gql-string_gql-typed__gql-string-typed.ts +++ b/examples/30_gql/gql_gql-string_gql-typed__gql-string-typed.ts @@ -1,7 +1,7 @@ /** * This example shows how to send a request using a string for the GraphQL document while also being typesafe in regards to the passed variables and return type. - * Note that the typing is a cast and would not catch if the actual GraphQL document disagreed with the types. As the comment suggests below, ideally some sort - * of automation would generate the types for you. + * Note that the typing of a string is effectively a cast here and so would not catch if the actual GraphQL document disagreed with your types. As the comment + * suggests below, ideally some sort of automation would generate the types for you. */ import { Graffle, type TypedDocument } from '../../src/entrypoints/main.js' @@ -33,7 +33,7 @@ type Document = TypedDocument.String< { name: string } > -const document: Document = /* gql */ ` +const data = await graffle.gql` query pokemonByName ($name: String!) { pokemonByName (name: $name) { name @@ -45,8 +45,6 @@ const document: Document = /* gql */ ` } } } -` - -const data = await graffle.gql(document).send({ name: `Pikachu` }) +`.send({ name: `Pikachu` }) show(data?.pokemonByName) 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 a7a7e7fb..d7ad01fa 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': '1728856241218' + 'x-sent-at-time': '1728912147789' }, 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 6e46d764..f0498b61 100644 --- a/examples/__outputs__/20_output/output_envelope.output.txt +++ b/examples/__outputs__/20_output/output_envelope.output.txt @@ -18,7 +18,7 @@ headers: Headers { 'content-type': 'application/graphql-response+json; charset=utf-8', 'content-length': '142', - date: 'Sun, 13 Oct 2024 21:50:41 GMT', + date: 'Mon, 14 Oct 2024 13:22:28 GMT', connection: 'keep-alive', 'keep-alive': 'timeout=5' }, diff --git a/examples/__outputs__/60_extension/extension_opentelemetry__opentelemetry.output.txt b/examples/__outputs__/60_extension/extension_opentelemetry__opentelemetry.output.txt index 93a93cc3..ed1a7f19 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: '0d775d0099c7910506a0772440555fbe', - parentId: '9b0787a81673ace4', + traceId: '27049eba5a2aefdef485bb13b3c9103a', + parentId: 'e85b98029274120c', traceState: undefined, name: 'encode', - id: 'e6fbdb4081ec6e4e', + id: 'c50625041c2a6ed5', kind: 0, - timestamp: 1728856242273000, - duration: 1418.125, + timestamp: 1728912148775000, + duration: 1505.542, attributes: {}, status: { code: 0 }, events: [], @@ -33,14 +33,14 @@ } }, instrumentationScope: { name: 'graffle', version: undefined, schemaUrl: undefined }, - traceId: '0d775d0099c7910506a0772440555fbe', - parentId: '9b0787a81673ace4', + traceId: '27049eba5a2aefdef485bb13b3c9103a', + parentId: 'e85b98029274120c', traceState: undefined, name: 'pack', - id: 'c20c4b4a0bb60890', + id: '11f13791202ae25b', kind: 0, - timestamp: 1728856242277000, - duration: 11234.958, + timestamp: 1728912148779000, + duration: 12466.834, attributes: {}, status: { code: 0 }, events: [], @@ -57,14 +57,14 @@ } }, instrumentationScope: { name: 'graffle', version: undefined, schemaUrl: undefined }, - traceId: '0d775d0099c7910506a0772440555fbe', - parentId: '9b0787a81673ace4', + traceId: '27049eba5a2aefdef485bb13b3c9103a', + parentId: 'e85b98029274120c', traceState: undefined, name: 'exchange', - id: 'b37626f52b507127', + id: 'e6cfb7ae84ff6884', kind: 0, - timestamp: 1728856242288000, - duration: 106411.25, + timestamp: 1728912148792000, + duration: 21899.333, attributes: {}, status: { code: 0 }, events: [], @@ -81,14 +81,14 @@ } }, instrumentationScope: { name: 'graffle', version: undefined, schemaUrl: undefined }, - traceId: '0d775d0099c7910506a0772440555fbe', - parentId: '9b0787a81673ace4', + traceId: '27049eba5a2aefdef485bb13b3c9103a', + parentId: 'e85b98029274120c', traceState: undefined, name: 'unpack', - id: '7cdde5c9f15d334d', + id: 'd4efa36db6b171cd', kind: 0, - timestamp: 1728856242395000, - duration: 1244.125, + timestamp: 1728912148814000, + duration: 1314.958, attributes: {}, status: { code: 0 }, events: [], @@ -105,14 +105,14 @@ } }, instrumentationScope: { name: 'graffle', version: undefined, schemaUrl: undefined }, - traceId: '0d775d0099c7910506a0772440555fbe', - parentId: '9b0787a81673ace4', + traceId: '27049eba5a2aefdef485bb13b3c9103a', + parentId: 'e85b98029274120c', traceState: undefined, name: 'decode', - id: 'b048da7b0a82b097', + id: '58283a74b8b0c8ac', kind: 0, - timestamp: 1728856242396000, - duration: 181.792, + timestamp: 1728912148816000, + duration: 245.125, attributes: {}, status: { code: 0 }, events: [], @@ -129,14 +129,14 @@ } }, instrumentationScope: { name: 'graffle', version: undefined, schemaUrl: undefined }, - traceId: '0d775d0099c7910506a0772440555fbe', + traceId: '27049eba5a2aefdef485bb13b3c9103a', parentId: undefined, traceState: undefined, name: 'request', - id: '9b0787a81673ace4', + id: 'e85b98029274120c', kind: 0, - timestamp: 1728856242273000, - duration: 123962.916, + timestamp: 1728912148775000, + duration: 41363.958, attributes: {}, status: { code: 0 }, events: [], diff --git a/website/content/_snippets/example-links/extension.md b/website/content/_snippets/example-links/extension.md index 20c765f1..8d975f23 100644 --- a/website/content/_snippets/example-links/extension.md +++ b/website/content/_snippets/example-links/extension.md @@ -1 +1 @@ - + diff --git a/website/content/_snippets/examples/extension/opentelemetry.detail.md b/website/content/_snippets/examples/extension/opentelemetry.detail.md index e4871e96..dbfa0a0b 100644 --- a/website/content/_snippets/examples/extension/opentelemetry.detail.md +++ b/website/content/_snippets/examples/extension/opentelemetry.detail.md @@ -37,14 +37,14 @@ console.log(data) } }, instrumentationScope: { name: 'graffle', version: undefined, schemaUrl: undefined }, - traceId: '0d775d0099c7910506a0772440555fbe', - parentId: '9b0787a81673ace4', + traceId: '27049eba5a2aefdef485bb13b3c9103a', + parentId: 'e85b98029274120c', traceState: undefined, name: 'encode', - id: 'e6fbdb4081ec6e4e', + id: 'c50625041c2a6ed5', kind: 0, - timestamp: 1728856242273000, - duration: 1418.125, + timestamp: 1728912148775000, + duration: 1505.542, attributes: {}, status: { code: 0 }, events: [], @@ -64,14 +64,14 @@ console.log(data) } }, instrumentationScope: { name: 'graffle', version: undefined, schemaUrl: undefined }, - traceId: '0d775d0099c7910506a0772440555fbe', - parentId: '9b0787a81673ace4', + traceId: '27049eba5a2aefdef485bb13b3c9103a', + parentId: 'e85b98029274120c', traceState: undefined, name: 'pack', - id: 'c20c4b4a0bb60890', + id: '11f13791202ae25b', kind: 0, - timestamp: 1728856242277000, - duration: 11234.958, + timestamp: 1728912148779000, + duration: 12466.834, attributes: {}, status: { code: 0 }, events: [], @@ -91,14 +91,14 @@ console.log(data) } }, instrumentationScope: { name: 'graffle', version: undefined, schemaUrl: undefined }, - traceId: '0d775d0099c7910506a0772440555fbe', - parentId: '9b0787a81673ace4', + traceId: '27049eba5a2aefdef485bb13b3c9103a', + parentId: 'e85b98029274120c', traceState: undefined, name: 'exchange', - id: 'b37626f52b507127', + id: 'e6cfb7ae84ff6884', kind: 0, - timestamp: 1728856242288000, - duration: 106411.25, + timestamp: 1728912148792000, + duration: 21899.333, attributes: {}, status: { code: 0 }, events: [], @@ -118,14 +118,14 @@ console.log(data) } }, instrumentationScope: { name: 'graffle', version: undefined, schemaUrl: undefined }, - traceId: '0d775d0099c7910506a0772440555fbe', - parentId: '9b0787a81673ace4', + traceId: '27049eba5a2aefdef485bb13b3c9103a', + parentId: 'e85b98029274120c', traceState: undefined, name: 'unpack', - id: '7cdde5c9f15d334d', + id: 'd4efa36db6b171cd', kind: 0, - timestamp: 1728856242395000, - duration: 1244.125, + timestamp: 1728912148814000, + duration: 1314.958, attributes: {}, status: { code: 0 }, events: [], @@ -145,14 +145,14 @@ console.log(data) } }, instrumentationScope: { name: 'graffle', version: undefined, schemaUrl: undefined }, - traceId: '0d775d0099c7910506a0772440555fbe', - parentId: '9b0787a81673ace4', + traceId: '27049eba5a2aefdef485bb13b3c9103a', + parentId: 'e85b98029274120c', traceState: undefined, name: 'decode', - id: 'b048da7b0a82b097', + id: '58283a74b8b0c8ac', kind: 0, - timestamp: 1728856242396000, - duration: 181.792, + timestamp: 1728912148816000, + duration: 245.125, attributes: {}, status: { code: 0 }, events: [], @@ -172,14 +172,14 @@ console.log(data) } }, instrumentationScope: { name: 'graffle', version: undefined, schemaUrl: undefined }, - traceId: '0d775d0099c7910506a0772440555fbe', + traceId: '27049eba5a2aefdef485bb13b3c9103a', parentId: undefined, traceState: undefined, name: 'request', - id: '9b0787a81673ace4', + id: 'e85b98029274120c', kind: 0, - timestamp: 1728856242273000, - duration: 123962.916, + timestamp: 1728912148775000, + duration: 41363.958, attributes: {}, status: { code: 0 }, events: [], diff --git a/website/content/_snippets/examples/extension/opentelemetry.md b/website/content/_snippets/examples/extension/opentelemetry.md index ab5c7f55..83d62bb9 100644 --- a/website/content/_snippets/examples/extension/opentelemetry.md +++ b/website/content/_snippets/examples/extension/opentelemetry.md @@ -35,14 +35,14 @@ console.log(data) } }, instrumentationScope: { name: 'graffle', version: undefined, schemaUrl: undefined }, - traceId: '0d775d0099c7910506a0772440555fbe', - parentId: '9b0787a81673ace4', + traceId: '27049eba5a2aefdef485bb13b3c9103a', + parentId: 'e85b98029274120c', traceState: undefined, name: 'encode', - id: 'e6fbdb4081ec6e4e', + id: 'c50625041c2a6ed5', kind: 0, - timestamp: 1728856242273000, - duration: 1418.125, + timestamp: 1728912148775000, + duration: 1505.542, attributes: {}, status: { code: 0 }, events: [], @@ -62,14 +62,14 @@ console.log(data) } }, instrumentationScope: { name: 'graffle', version: undefined, schemaUrl: undefined }, - traceId: '0d775d0099c7910506a0772440555fbe', - parentId: '9b0787a81673ace4', + traceId: '27049eba5a2aefdef485bb13b3c9103a', + parentId: 'e85b98029274120c', traceState: undefined, name: 'pack', - id: 'c20c4b4a0bb60890', + id: '11f13791202ae25b', kind: 0, - timestamp: 1728856242277000, - duration: 11234.958, + timestamp: 1728912148779000, + duration: 12466.834, attributes: {}, status: { code: 0 }, events: [], @@ -89,14 +89,14 @@ console.log(data) } }, instrumentationScope: { name: 'graffle', version: undefined, schemaUrl: undefined }, - traceId: '0d775d0099c7910506a0772440555fbe', - parentId: '9b0787a81673ace4', + traceId: '27049eba5a2aefdef485bb13b3c9103a', + parentId: 'e85b98029274120c', traceState: undefined, name: 'exchange', - id: 'b37626f52b507127', + id: 'e6cfb7ae84ff6884', kind: 0, - timestamp: 1728856242288000, - duration: 106411.25, + timestamp: 1728912148792000, + duration: 21899.333, attributes: {}, status: { code: 0 }, events: [], @@ -116,14 +116,14 @@ console.log(data) } }, instrumentationScope: { name: 'graffle', version: undefined, schemaUrl: undefined }, - traceId: '0d775d0099c7910506a0772440555fbe', - parentId: '9b0787a81673ace4', + traceId: '27049eba5a2aefdef485bb13b3c9103a', + parentId: 'e85b98029274120c', traceState: undefined, name: 'unpack', - id: '7cdde5c9f15d334d', + id: 'd4efa36db6b171cd', kind: 0, - timestamp: 1728856242395000, - duration: 1244.125, + timestamp: 1728912148814000, + duration: 1314.958, attributes: {}, status: { code: 0 }, events: [], @@ -143,14 +143,14 @@ console.log(data) } }, instrumentationScope: { name: 'graffle', version: undefined, schemaUrl: undefined }, - traceId: '0d775d0099c7910506a0772440555fbe', - parentId: '9b0787a81673ace4', + traceId: '27049eba5a2aefdef485bb13b3c9103a', + parentId: 'e85b98029274120c', traceState: undefined, name: 'decode', - id: 'b048da7b0a82b097', + id: '58283a74b8b0c8ac', kind: 0, - timestamp: 1728856242396000, - duration: 181.792, + timestamp: 1728912148816000, + duration: 245.125, attributes: {}, status: { code: 0 }, events: [], @@ -170,14 +170,14 @@ console.log(data) } }, instrumentationScope: { name: 'graffle', version: undefined, schemaUrl: undefined }, - traceId: '0d775d0099c7910506a0772440555fbe', + traceId: '27049eba5a2aefdef485bb13b3c9103a', parentId: undefined, traceState: undefined, name: 'request', - id: '9b0787a81673ace4', + id: 'e85b98029274120c', kind: 0, - timestamp: 1728856242273000, - duration: 123962.916, + timestamp: 1728912148775000, + duration: 41363.958, attributes: {}, status: { code: 0 }, events: [], diff --git a/website/content/_snippets/examples/gql/gql-string-typed.detail.md b/website/content/_snippets/examples/gql/gql-string-typed.detail.md index 6f78a870..baf15977 100644 --- a/website/content/_snippets/examples/gql/gql-string-typed.detail.md +++ b/website/content/_snippets/examples/gql/gql-string-typed.detail.md @@ -33,7 +33,7 @@ type Document = TypedDocument.String< { name: string } > -const document: Document = /* gql */ ` +const data = await graffle.gql` query pokemonByName ($name: String!) { pokemonByName (name: $name) { name @@ -45,9 +45,7 @@ const document: Document = /* gql */ ` } } } -` - -const data = await graffle.gql(document).send({ name: `Pikachu` }) +`.send({ name: `Pikachu` }) console.log(data?.pokemonByName) ``` diff --git a/website/content/_snippets/examples/gql/gql-string-typed.md b/website/content/_snippets/examples/gql/gql-string-typed.md index f5b2def1..bf92a844 100644 --- a/website/content/_snippets/examples/gql/gql-string-typed.md +++ b/website/content/_snippets/examples/gql/gql-string-typed.md @@ -31,7 +31,7 @@ type Document = TypedDocument.String< { name: string } > -const document: Document = /* gql */ ` +const data = await graffle.gql` query pokemonByName ($name: String!) { pokemonByName (name: $name) { name @@ -43,9 +43,7 @@ const document: Document = /* gql */ ` } } } -` - -const data = await graffle.gql(document).send({ name: `Pikachu` }) +`.send({ name: `Pikachu` }) console.log(data?.pokemonByName) ``` diff --git a/website/content/_snippets/examples/gql/gql-string.detail.md b/website/content/_snippets/examples/gql/gql-string.detail.md index ee2cf246..83e18593 100644 --- a/website/content/_snippets/examples/gql/gql-string.detail.md +++ b/website/content/_snippets/examples/gql/gql-string.detail.md @@ -11,15 +11,13 @@ const graffle = Graffle.create({ schema: `http://localhost:3000/graphql`, }) -const document = /* gql */ ` +const data = await graffle.gql` { pokemon { name } - } -` - -const data = await graffle.gql(document).send() + } +`.send() console.log(data) ``` diff --git a/website/content/_snippets/examples/gql/gql-string.md b/website/content/_snippets/examples/gql/gql-string.md index 19369a71..d2802c65 100644 --- a/website/content/_snippets/examples/gql/gql-string.md +++ b/website/content/_snippets/examples/gql/gql-string.md @@ -9,15 +9,13 @@ const graffle = Graffle.create({ schema: `http://localhost:3000/graphql`, }) -const document = /* gql */ ` +const data = await graffle.gql` { pokemon { name } - } -` - -const data = await graffle.gql(document).send() + } +`.send() console.log(data) ``` diff --git a/website/content/_snippets/examples/output/envelope.detail.md b/website/content/_snippets/examples/output/envelope.detail.md index 6cc5ce54..1aa39773 100644 --- a/website/content/_snippets/examples/output/envelope.detail.md +++ b/website/content/_snippets/examples/output/envelope.detail.md @@ -40,7 +40,7 @@ console.log(result) headers: Headers { 'content-type': 'application/graphql-response+json; charset=utf-8', 'content-length': '142', - date: 'Sun, 13 Oct 2024 21:50:41 GMT', + date: 'Mon, 14 Oct 2024 13:22:28 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 fba64ca7..88977614 100644 --- a/website/content/_snippets/examples/output/envelope.md +++ b/website/content/_snippets/examples/output/envelope.md @@ -38,7 +38,7 @@ console.log(result) headers: Headers { 'content-type': 'application/graphql-response+json; charset=utf-8', 'content-length': '142', - date: 'Sun, 13 Oct 2024 21:50:41 GMT', + date: 'Mon, 14 Oct 2024 13:22:28 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 949906a9..965e68e4 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.gql`{ pokemons { name } }`.send() headers: Headers { accept: 'application/graphql-response+json; charset=utf-8, application/json; charset=utf-8', 'content-type': 'application/json', - 'x-sent-at-time': '1728856241218' + 'x-sent-at-time': '1728912147789' }, 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 63efbd6f..85402457 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.gql`{ pokemons { name } }`.send() headers: Headers { accept: 'application/graphql-response+json; charset=utf-8, application/json; charset=utf-8', 'content-type': 'application/json', - 'x-sent-at-time': '1728856241218' + 'x-sent-at-time': '1728912147789' }, 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 ba23979e..d973fb4a 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.gql`{ pokemons { name } }`.send() headers: Headers { accept: 'application/graphql-response+json; charset=utf-8, application/json; charset=utf-8', 'content-type': 'application/json', - 'x-sent-at-time': '1728856241218' + 'x-sent-at-time': '1728912147789' }, signal: undefined, method: 'post', diff --git a/website/content/examples/20_output/envelope.md b/website/content/examples/20_output/envelope.md index 2e21c0f6..c8002141 100644 --- a/website/content/examples/20_output/envelope.md +++ b/website/content/examples/20_output/envelope.md @@ -45,7 +45,7 @@ console.log(result) headers: Headers { 'content-type': 'application/graphql-response+json; charset=utf-8', 'content-length': '142', - date: 'Sun, 13 Oct 2024 21:50:41 GMT', + date: 'Mon, 14 Oct 2024 13:22:28 GMT', connection: 'keep-alive', 'keep-alive': 'timeout=5' }, diff --git a/website/content/examples/30_gql/gql-string-typed.md b/website/content/examples/30_gql/gql-string-typed.md index 5f6cec20..f61d17b7 100644 --- a/website/content/examples/30_gql/gql-string-typed.md +++ b/website/content/examples/30_gql/gql-string-typed.md @@ -5,8 +5,8 @@ aside: false # Gql String Typed This example shows how to send a request using a string for the GraphQL document while also being typesafe in regards to the passed variables and return type. -Note that the typing is a cast and would not catch if the actual GraphQL document disagreed with the types. As the comment suggests below, ideally some sort -of automation would generate the types for you. +Note that the typing of a string is effectively a cast here and so would not catch if the actual GraphQL document disagreed with your types. As the comment +suggests below, ideally some sort of automation would generate the types for you. ```ts twoslash @@ -38,7 +38,7 @@ type Document = TypedDocument.String< { name: string } > -const document: Document = /* gql */ ` +const data = await graffle.gql` query pokemonByName ($name: String!) { pokemonByName (name: $name) { name @@ -50,9 +50,7 @@ const document: Document = /* gql */ ` } } } -` - -const data = await graffle.gql(document).send({ name: `Pikachu` }) +`.send({ name: `Pikachu` }) console.log(data?.pokemonByName) ``` diff --git a/website/content/examples/30_gql/gql-string.md b/website/content/examples/30_gql/gql-string.md index 118838c4..c8e73d55 100644 --- a/website/content/examples/30_gql/gql-string.md +++ b/website/content/examples/30_gql/gql-string.md @@ -14,15 +14,13 @@ const graffle = Graffle.create({ schema: `http://localhost:3000/graphql`, }) -const document = /* gql */ ` +const data = await graffle.gql` { pokemon { name } - } -` - -const data = await graffle.gql(document).send() + } +`.send() console.log(data) ``` diff --git a/website/content/examples/60_extension/opentelemetry.md b/website/content/examples/60_extension/opentelemetry.md index eb0e2967..fb088b63 100644 --- a/website/content/examples/60_extension/opentelemetry.md +++ b/website/content/examples/60_extension/opentelemetry.md @@ -40,14 +40,14 @@ console.log(data) } }, instrumentationScope: { name: 'graffle', version: undefined, schemaUrl: undefined }, - traceId: '0d775d0099c7910506a0772440555fbe', - parentId: '9b0787a81673ace4', + traceId: '27049eba5a2aefdef485bb13b3c9103a', + parentId: 'e85b98029274120c', traceState: undefined, name: 'encode', - id: 'e6fbdb4081ec6e4e', + id: 'c50625041c2a6ed5', kind: 0, - timestamp: 1728856242273000, - duration: 1418.125, + timestamp: 1728912148775000, + duration: 1505.542, attributes: {}, status: { code: 0 }, events: [], @@ -67,14 +67,14 @@ console.log(data) } }, instrumentationScope: { name: 'graffle', version: undefined, schemaUrl: undefined }, - traceId: '0d775d0099c7910506a0772440555fbe', - parentId: '9b0787a81673ace4', + traceId: '27049eba5a2aefdef485bb13b3c9103a', + parentId: 'e85b98029274120c', traceState: undefined, name: 'pack', - id: 'c20c4b4a0bb60890', + id: '11f13791202ae25b', kind: 0, - timestamp: 1728856242277000, - duration: 11234.958, + timestamp: 1728912148779000, + duration: 12466.834, attributes: {}, status: { code: 0 }, events: [], @@ -94,14 +94,14 @@ console.log(data) } }, instrumentationScope: { name: 'graffle', version: undefined, schemaUrl: undefined }, - traceId: '0d775d0099c7910506a0772440555fbe', - parentId: '9b0787a81673ace4', + traceId: '27049eba5a2aefdef485bb13b3c9103a', + parentId: 'e85b98029274120c', traceState: undefined, name: 'exchange', - id: 'b37626f52b507127', + id: 'e6cfb7ae84ff6884', kind: 0, - timestamp: 1728856242288000, - duration: 106411.25, + timestamp: 1728912148792000, + duration: 21899.333, attributes: {}, status: { code: 0 }, events: [], @@ -121,14 +121,14 @@ console.log(data) } }, instrumentationScope: { name: 'graffle', version: undefined, schemaUrl: undefined }, - traceId: '0d775d0099c7910506a0772440555fbe', - parentId: '9b0787a81673ace4', + traceId: '27049eba5a2aefdef485bb13b3c9103a', + parentId: 'e85b98029274120c', traceState: undefined, name: 'unpack', - id: '7cdde5c9f15d334d', + id: 'd4efa36db6b171cd', kind: 0, - timestamp: 1728856242395000, - duration: 1244.125, + timestamp: 1728912148814000, + duration: 1314.958, attributes: {}, status: { code: 0 }, events: [], @@ -148,14 +148,14 @@ console.log(data) } }, instrumentationScope: { name: 'graffle', version: undefined, schemaUrl: undefined }, - traceId: '0d775d0099c7910506a0772440555fbe', - parentId: '9b0787a81673ace4', + traceId: '27049eba5a2aefdef485bb13b3c9103a', + parentId: 'e85b98029274120c', traceState: undefined, name: 'decode', - id: 'b048da7b0a82b097', + id: '58283a74b8b0c8ac', kind: 0, - timestamp: 1728856242396000, - duration: 181.792, + timestamp: 1728912148816000, + duration: 245.125, attributes: {}, status: { code: 0 }, events: [], @@ -175,14 +175,14 @@ console.log(data) } }, instrumentationScope: { name: 'graffle', version: undefined, schemaUrl: undefined }, - traceId: '0d775d0099c7910506a0772440555fbe', + traceId: '27049eba5a2aefdef485bb13b3c9103a', parentId: undefined, traceState: undefined, name: 'request', - id: '9b0787a81673ace4', + id: 'e85b98029274120c', kind: 0, - timestamp: 1728856242273000, - duration: 123962.916, + timestamp: 1728912148775000, + duration: 41363.958, attributes: {}, status: { code: 0 }, events: [],