diff --git a/examples/30_raw/raw.ts b/examples/30_raw/raw_rawDocumentNode__raw-document-node.ts similarity index 100% rename from examples/30_raw/raw.ts rename to examples/30_raw/raw_rawDocumentNode__raw-document-node.ts diff --git a/examples/30_raw/raw_rawTyped__raw-typed.ts b/examples/30_raw/raw_rawDocumentNode_rawTyped__raw-document-node-typed.ts similarity index 100% rename from examples/30_raw/raw_rawTyped__raw-typed.ts rename to examples/30_raw/raw_rawDocumentNode_rawTyped__raw-document-node-typed.ts 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 a86becb2b..e1a350915 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': '1726461294313' + 'x-sent-at-time': '1726541102597' }, 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 8ec7b74e0..164805ded 100644 --- a/examples/__outputs__/20_output/output_envelope.output.txt +++ b/examples/__outputs__/20_output/output_envelope.output.txt @@ -19,7 +19,7 @@ headers: Headers { connection: 'keep-alive', 'content-length': '119', - 'x-served-by': 'cache-yul1970022-YUL', + 'x-served-by': 'cache-yul1970024-YUL', 'accept-ranges': 'bytes', date: 'Sun, 08 Sep 2024 18:13:26 GMT', 'content-type': 'application/graphql-response+json; charset=utf-8', @@ -32,13 +32,13 @@ 'alt-svc': 'h3=":443"; ma=86400', 'access-control-allow-origin': '*', 'x-powered-by': 'Stellate', - age: '642089', + age: '721898', 'cache-control': 'public, s-maxage=2628000, stale-while-revalidate=2628000', 'x-cache': 'HIT', - 'x-cache-hits': '80', + 'x-cache-hits': '84', 'gcdn-cache': 'HIT', - 'stellate-rate-limit-budget-remaining': '47', - 'stellate-rate-limit-rules': '"IP limit";type="RequestCount";budget=50;limited=?0;remaining=47;refill=60', + 'stellate-rate-limit-budget-remaining': '44', + 'stellate-rate-limit-rules': '"IP limit";type="RequestCount";budget=50;limited=?0;remaining=44;refill=59', 'stellate-rate-limit-decision': 'pass', 'stellate-rate-limit-budget-required': '5', 'content-encoding': 'br' diff --git a/examples/__outputs__/30_raw/raw.output.txt b/examples/__outputs__/30_raw/raw_rawDocumentNode__raw-document-node.output.txt similarity index 100% rename from examples/__outputs__/30_raw/raw.output.txt rename to examples/__outputs__/30_raw/raw_rawDocumentNode__raw-document-node.output.txt diff --git a/examples/__outputs__/30_raw/raw_rawTyped__raw-typed.output.txt b/examples/__outputs__/30_raw/raw_rawDocumentNode_rawTyped__raw-document-node-typed.output.txt similarity index 100% rename from examples/__outputs__/30_raw/raw_rawTyped__raw-typed.output.txt rename to examples/__outputs__/30_raw/raw_rawDocumentNode_rawTyped__raw-document-node-typed.output.txt diff --git a/examples/__outputs__/40_other/anyware.output.txt b/examples/__outputs__/40_other/anyware.output.txt new file mode 100644 index 000000000..e69de29bb diff --git a/examples/__outputs__/60_extension/extension_opentelemetry__opentelemetry.output.txt b/examples/__outputs__/60_extension/extension_opentelemetry__opentelemetry.output.txt index 92d66c818..5be26dcac 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: '33c2903599214054eb34ee8382ee63e1', - parentId: 'a9cd435480d53274', + traceId: '9f4dcc1213a3f3d4605da3d9c3340361', + parentId: 'f0c18d7e669cfd3d', traceState: undefined, name: 'encode', - id: 'ae33c18f5cc9cae0', + id: 'e06d4e860f48bc58', kind: 0, - timestamp: 1726461294589000, - duration: 539.583, + timestamp: 1726541103051000, + duration: 552.125, attributes: {}, status: { code: 0 }, events: [], @@ -33,14 +33,14 @@ } }, instrumentationScope: { name: 'graffle', version: undefined, schemaUrl: undefined }, - traceId: '33c2903599214054eb34ee8382ee63e1', - parentId: 'a9cd435480d53274', + traceId: '9f4dcc1213a3f3d4605da3d9c3340361', + parentId: 'f0c18d7e669cfd3d', traceState: undefined, name: 'pack', - id: '95b40ccefe000e6e', + id: 'a29e1e9baaa80c0e', kind: 0, - timestamp: 1726461294591000, - duration: 1186.792, + timestamp: 1726541103053000, + duration: 1086.75, attributes: {}, status: { code: 0 }, events: [], @@ -57,14 +57,14 @@ } }, instrumentationScope: { name: 'graffle', version: undefined, schemaUrl: undefined }, - traceId: '33c2903599214054eb34ee8382ee63e1', - parentId: 'a9cd435480d53274', + traceId: '9f4dcc1213a3f3d4605da3d9c3340361', + parentId: 'f0c18d7e669cfd3d', traceState: undefined, name: 'exchange', - id: '986a75e706d54ec1', + id: 'f2a21df585a2fdbb', kind: 0, - timestamp: 1726461294593000, - duration: 147109.584, + timestamp: 1726541103055000, + duration: 177279.959, attributes: {}, status: { code: 0 }, events: [], @@ -81,14 +81,14 @@ } }, instrumentationScope: { name: 'graffle', version: undefined, schemaUrl: undefined }, - traceId: '33c2903599214054eb34ee8382ee63e1', - parentId: 'a9cd435480d53274', + traceId: '9f4dcc1213a3f3d4605da3d9c3340361', + parentId: 'f0c18d7e669cfd3d', traceState: undefined, name: 'unpack', - id: '2bd1476a05bb0a51', + id: '2088b4af9a15807e', kind: 0, - timestamp: 1726461294741000, - duration: 2265.625, + timestamp: 1726541103233000, + duration: 2944, attributes: {}, status: { code: 0 }, events: [], @@ -105,14 +105,14 @@ } }, instrumentationScope: { name: 'graffle', version: undefined, schemaUrl: undefined }, - traceId: '33c2903599214054eb34ee8382ee63e1', - parentId: 'a9cd435480d53274', + traceId: '9f4dcc1213a3f3d4605da3d9c3340361', + parentId: 'f0c18d7e669cfd3d', traceState: undefined, name: 'decode', - id: '40a75edd2f4f08d4', + id: '11a1c3568453721f', kind: 0, - timestamp: 1726461294743000, - duration: 124.542, + timestamp: 1726541103236000, + duration: 127.375, attributes: {}, status: { code: 0 }, events: [], @@ -129,14 +129,14 @@ } }, instrumentationScope: { name: 'graffle', version: undefined, schemaUrl: undefined }, - traceId: '33c2903599214054eb34ee8382ee63e1', + traceId: '9f4dcc1213a3f3d4605da3d9c3340361', parentId: undefined, traceState: undefined, name: 'request', - id: 'a9cd435480d53274', + id: 'f0c18d7e669cfd3d', kind: 0, - timestamp: 1726461294589000, - duration: 154733.292, + timestamp: 1726541103050000, + duration: 186111.542, attributes: {}, status: { code: 0 }, events: [], diff --git a/tests/examples/30_raw/raw_rawDocumentNode__raw-document-node.test.ts b/tests/examples/30_raw/raw_rawDocumentNode__raw-document-node.test.ts new file mode 100644 index 000000000..f54317ccd --- /dev/null +++ b/tests/examples/30_raw/raw_rawDocumentNode__raw-document-node.test.ts @@ -0,0 +1,19 @@ +// @vitest-environment node + +// WARNING: +// This test is generated by scripts/generate-example-derivatives/generate.ts +// Do not modify this file directly. + +import { expect, test } from 'vitest' +import { runExample } from '../../../scripts/generate-examples-derivatives/helpers.js' + +test(`raw_rawDocumentNode__raw-document-node`, async () => { + const exampleResult = await runExample(`./examples/30_raw/raw_rawDocumentNode__raw-document-node.ts`) + // Examples should output their data results. + const exampleResultMaybeEncoded = exampleResult + // If ever outputs vary by Node version, you can use this to snapshot by Node version. + // const nodeMajor = process.version.match(/v(\d+)/)?.[1] ?? `unknown` + await expect(exampleResultMaybeEncoded).toMatchFileSnapshot( + `../../../examples/__outputs__/30_raw/raw_rawDocumentNode__raw-document-node.output.txt`, + ) +}) diff --git a/tests/examples/30_raw/raw_rawDocumentNode__raw.test.ts b/tests/examples/30_raw/raw_rawDocumentNode__raw.test.ts new file mode 100644 index 000000000..9dfd4914a --- /dev/null +++ b/tests/examples/30_raw/raw_rawDocumentNode__raw.test.ts @@ -0,0 +1,19 @@ +// @vitest-environment node + +// WARNING: +// This test is generated by scripts/generate-example-derivatives/generate.ts +// Do not modify this file directly. + +import { expect, test } from 'vitest' +import { runExample } from '../../../scripts/generate-examples-derivatives/helpers.js' + +test(`raw_rawDocumentNode__raw`, async () => { + const exampleResult = await runExample(`./examples/30_raw/raw_rawDocumentNode__raw.ts`) + // Examples should output their data results. + const exampleResultMaybeEncoded = exampleResult + // If ever outputs vary by Node version, you can use this to snapshot by Node version. + // const nodeMajor = process.version.match(/v(\d+)/)?.[1] ?? `unknown` + await expect(exampleResultMaybeEncoded).toMatchFileSnapshot( + `../../../examples/__outputs__/30_raw/raw_rawDocumentNode__raw.output.txt`, + ) +}) diff --git a/tests/examples/30_raw/raw_rawDocumentNode_rawTyped__raw-document-node-typed.test.ts b/tests/examples/30_raw/raw_rawDocumentNode_rawTyped__raw-document-node-typed.test.ts new file mode 100644 index 000000000..4944e4ebe --- /dev/null +++ b/tests/examples/30_raw/raw_rawDocumentNode_rawTyped__raw-document-node-typed.test.ts @@ -0,0 +1,19 @@ +// @vitest-environment node + +// WARNING: +// This test is generated by scripts/generate-example-derivatives/generate.ts +// Do not modify this file directly. + +import { expect, test } from 'vitest' +import { runExample } from '../../../scripts/generate-examples-derivatives/helpers.js' + +test(`raw_rawDocumentNode_rawTyped__raw-document-node-typed`, async () => { + const exampleResult = await runExample(`./examples/30_raw/raw_rawDocumentNode_rawTyped__raw-document-node-typed.ts`) + // Examples should output their data results. + const exampleResultMaybeEncoded = exampleResult + // If ever outputs vary by Node version, you can use this to snapshot by Node version. + // const nodeMajor = process.version.match(/v(\d+)/)?.[1] ?? `unknown` + await expect(exampleResultMaybeEncoded).toMatchFileSnapshot( + `../../../examples/__outputs__/30_raw/raw_rawDocumentNode_rawTyped__raw-document-node-typed.output.txt`, + ) +}) diff --git a/tests/examples/30_raw/raw_rawDocumentNode_rawTyped__raw-typed.test.ts b/tests/examples/30_raw/raw_rawDocumentNode_rawTyped__raw-typed.test.ts new file mode 100644 index 000000000..58d7048d7 --- /dev/null +++ b/tests/examples/30_raw/raw_rawDocumentNode_rawTyped__raw-typed.test.ts @@ -0,0 +1,19 @@ +// @vitest-environment node + +// WARNING: +// This test is generated by scripts/generate-example-derivatives/generate.ts +// Do not modify this file directly. + +import { expect, test } from 'vitest' +import { runExample } from '../../../scripts/generate-examples-derivatives/helpers.js' + +test(`raw_rawDocumentNode_rawTyped__raw-typed`, async () => { + const exampleResult = await runExample(`./examples/30_raw/raw_rawDocumentNode_rawTyped__raw-typed.ts`) + // Examples should output their data results. + const exampleResultMaybeEncoded = exampleResult + // If ever outputs vary by Node version, you can use this to snapshot by Node version. + // const nodeMajor = process.version.match(/v(\d+)/)?.[1] ?? `unknown` + await expect(exampleResultMaybeEncoded).toMatchFileSnapshot( + `../../../examples/__outputs__/30_raw/raw_rawDocumentNode_rawTyped__raw-typed.output.txt`, + ) +}) diff --git a/tests/examples/40_other/anyware.test.ts b/tests/examples/40_other/anyware.test.ts new file mode 100644 index 000000000..273b4cc02 --- /dev/null +++ b/tests/examples/40_other/anyware.test.ts @@ -0,0 +1,19 @@ +// @vitest-environment node + +// WARNING: +// This test is generated by scripts/generate-example-derivatives/generate.ts +// Do not modify this file directly. + +import { expect, test } from 'vitest' +import { runExample } from '../../../scripts/generate-examples-derivatives/helpers.js' + +test(`anyware`, async () => { + const exampleResult = await runExample(`./examples/40_other/anyware.ts`) + // Examples should output their data results. + const exampleResultMaybeEncoded = exampleResult + // If ever outputs vary by Node version, you can use this to snapshot by Node version. + // const nodeMajor = process.version.match(/v(\d+)/)?.[1] ?? `unknown` + await expect(exampleResultMaybeEncoded).toMatchFileSnapshot( + `../../../examples/__outputs__/40_other/anyware.output.txt`, + ) +}) diff --git a/website/content/_snippets/example-links/anyware.md b/website/content/_snippets/example-links/anyware.md new file mode 100644 index 000000000..1a1a43ccf --- /dev/null +++ b/website/content/_snippets/example-links/anyware.md @@ -0,0 +1 @@ + diff --git a/website/content/_snippets/example-links/raw.md b/website/content/_snippets/example-links/raw.md index 3702aaed0..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/example-links/rawDocumentNode.md b/website/content/_snippets/example-links/rawDocumentNode.md new file mode 100644 index 000000000..207594be3 --- /dev/null +++ b/website/content/_snippets/example-links/rawDocumentNode.md @@ -0,0 +1 @@ + diff --git a/website/content/_snippets/example-links/rawDocumentNode_rawTyped.md b/website/content/_snippets/example-links/rawDocumentNode_rawTyped.md new file mode 100644 index 000000000..6e48e5106 --- /dev/null +++ b/website/content/_snippets/example-links/rawDocumentNode_rawTyped.md @@ -0,0 +1 @@ + diff --git a/website/content/_snippets/example-links/rawTyped.md b/website/content/_snippets/example-links/rawTyped.md index f772e5cce..5675fc97a 100644 --- a/website/content/_snippets/example-links/rawTyped.md +++ b/website/content/_snippets/example-links/rawTyped.md @@ -1 +1 @@ - + diff --git a/website/content/_snippets/example-links/raw_rawDocumentNode.md b/website/content/_snippets/example-links/raw_rawDocumentNode.md new file mode 100644 index 000000000..207594be3 --- /dev/null +++ b/website/content/_snippets/example-links/raw_rawDocumentNode.md @@ -0,0 +1 @@ + diff --git a/website/content/_snippets/example-links/raw_rawDocumentNode_rawTyped.md b/website/content/_snippets/example-links/raw_rawDocumentNode_rawTyped.md new file mode 100644 index 000000000..6e48e5106 --- /dev/null +++ b/website/content/_snippets/example-links/raw_rawDocumentNode_rawTyped.md @@ -0,0 +1 @@ + diff --git a/website/content/_snippets/example-links/raw_rawTyped.md b/website/content/_snippets/example-links/raw_rawTyped.md index f772e5cce..5675fc97a 100644 --- a/website/content/_snippets/example-links/raw_rawTyped.md +++ b/website/content/_snippets/example-links/raw_rawTyped.md @@ -1 +1 @@ - + diff --git a/website/content/examples/10_transport-http/dynamic-headers.md b/website/content/examples/10_transport-http/dynamic-headers.md index 75ab8e7fa..fc1ffc9d2 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: `{ languages { code } }` }) headers: Headers { accept: 'application/graphql-response+json; charset=utf-8, application/json; charset=utf-8', 'content-type': 'application/json', - 'x-sent-at-time': '1726461294313' + 'x-sent-at-time': '1726541102597' }, signal: undefined, method: 'post', diff --git a/website/content/examples/20_output/envelope.md b/website/content/examples/20_output/envelope.md index cbfaec59a..c6632126c 100644 --- a/website/content/examples/20_output/envelope.md +++ b/website/content/examples/20_output/envelope.md @@ -46,7 +46,7 @@ console.log(result) headers: Headers { connection: 'keep-alive', 'content-length': '119', - 'x-served-by': 'cache-yul1970022-YUL', + 'x-served-by': 'cache-yul1970024-YUL', 'accept-ranges': 'bytes', date: 'Sun, 08 Sep 2024 18:13:26 GMT', 'content-type': 'application/graphql-response+json; charset=utf-8', @@ -59,13 +59,13 @@ console.log(result) 'alt-svc': 'h3=":443"; ma=86400', 'access-control-allow-origin': '*', 'x-powered-by': 'Stellate', - age: '642089', + age: '721898', 'cache-control': 'public, s-maxage=2628000, stale-while-revalidate=2628000', 'x-cache': 'HIT', - 'x-cache-hits': '80', + 'x-cache-hits': '84', 'gcdn-cache': 'HIT', - 'stellate-rate-limit-budget-remaining': '47', - 'stellate-rate-limit-rules': '"IP limit";type="RequestCount";budget=50;limited=?0;remaining=47;refill=60', + 'stellate-rate-limit-budget-remaining': '44', + 'stellate-rate-limit-rules': '"IP limit";type="RequestCount";budget=50;limited=?0;remaining=44;refill=59', 'stellate-rate-limit-decision': 'pass', 'stellate-rate-limit-budget-required': '5', 'content-encoding': 'br' diff --git a/website/content/examples/30_raw/raw-typed.md b/website/content/examples/30_raw/raw-document-node-typed.md similarity index 98% rename from website/content/examples/30_raw/raw-typed.md rename to website/content/examples/30_raw/raw-document-node-typed.md index c1570be7e..678b1758f 100644 --- a/website/content/examples/30_raw/raw-typed.md +++ b/website/content/examples/30_raw/raw-document-node-typed.md @@ -2,7 +2,7 @@ aside: false --- -# Raw Typed +# Raw Document Node Typed This example shows how to send a request using a Document instance for the GraphQL document while also being typesafe in regards to the passed variables and return type. diff --git a/website/content/examples/30_raw/raw.md b/website/content/examples/30_raw/raw-document-node.md similarity index 98% rename from website/content/examples/30_raw/raw.md rename to website/content/examples/30_raw/raw-document-node.md index 478d2ff3a..27fd01000 100644 --- a/website/content/examples/30_raw/raw.md +++ b/website/content/examples/30_raw/raw-document-node.md @@ -2,7 +2,7 @@ aside: false --- -# Raw +# Raw Document Node This example shows how to send a request using a Document instance for the GraphQL document. diff --git a/website/content/examples/40_other/anyware.md b/website/content/examples/40_other/anyware.md new file mode 100644 index 000000000..f0e6b2f92 --- /dev/null +++ b/website/content/examples/40_other/anyware.md @@ -0,0 +1,29 @@ +--- +aside: false +--- + +# Anyware + + +```ts twoslash +import { Graffle } from 'graffle' + +Graffle + .create({ schema: `https://countries.trevorblades.com/graphql` }) + .anyware(async ({ encode }) => { + if (encode.input.interface === 'typed') { + // Do something here. + } + + if (encode.input.transport === 'memory') { + // Do something here. + } + + // etc. + + return encode() + }) +``` + + +#### Outputs diff --git a/website/content/examples/60_extension/opentelemetry.md b/website/content/examples/60_extension/opentelemetry.md index 724f28ea5..54cb52a60 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: '33c2903599214054eb34ee8382ee63e1', - parentId: 'a9cd435480d53274', + traceId: '9f4dcc1213a3f3d4605da3d9c3340361', + parentId: 'f0c18d7e669cfd3d', traceState: undefined, name: 'encode', - id: 'ae33c18f5cc9cae0', + id: 'e06d4e860f48bc58', kind: 0, - timestamp: 1726461294589000, - duration: 539.583, + timestamp: 1726541103051000, + duration: 552.125, attributes: {}, status: { code: 0 }, events: [], @@ -67,14 +67,14 @@ console.log(data) } }, instrumentationScope: { name: 'graffle', version: undefined, schemaUrl: undefined }, - traceId: '33c2903599214054eb34ee8382ee63e1', - parentId: 'a9cd435480d53274', + traceId: '9f4dcc1213a3f3d4605da3d9c3340361', + parentId: 'f0c18d7e669cfd3d', traceState: undefined, name: 'pack', - id: '95b40ccefe000e6e', + id: 'a29e1e9baaa80c0e', kind: 0, - timestamp: 1726461294591000, - duration: 1186.792, + timestamp: 1726541103053000, + duration: 1086.75, attributes: {}, status: { code: 0 }, events: [], @@ -94,14 +94,14 @@ console.log(data) } }, instrumentationScope: { name: 'graffle', version: undefined, schemaUrl: undefined }, - traceId: '33c2903599214054eb34ee8382ee63e1', - parentId: 'a9cd435480d53274', + traceId: '9f4dcc1213a3f3d4605da3d9c3340361', + parentId: 'f0c18d7e669cfd3d', traceState: undefined, name: 'exchange', - id: '986a75e706d54ec1', + id: 'f2a21df585a2fdbb', kind: 0, - timestamp: 1726461294593000, - duration: 147109.584, + timestamp: 1726541103055000, + duration: 177279.959, attributes: {}, status: { code: 0 }, events: [], @@ -121,14 +121,14 @@ console.log(data) } }, instrumentationScope: { name: 'graffle', version: undefined, schemaUrl: undefined }, - traceId: '33c2903599214054eb34ee8382ee63e1', - parentId: 'a9cd435480d53274', + traceId: '9f4dcc1213a3f3d4605da3d9c3340361', + parentId: 'f0c18d7e669cfd3d', traceState: undefined, name: 'unpack', - id: '2bd1476a05bb0a51', + id: '2088b4af9a15807e', kind: 0, - timestamp: 1726461294741000, - duration: 2265.625, + timestamp: 1726541103233000, + duration: 2944, attributes: {}, status: { code: 0 }, events: [], @@ -148,14 +148,14 @@ console.log(data) } }, instrumentationScope: { name: 'graffle', version: undefined, schemaUrl: undefined }, - traceId: '33c2903599214054eb34ee8382ee63e1', - parentId: 'a9cd435480d53274', + traceId: '9f4dcc1213a3f3d4605da3d9c3340361', + parentId: 'f0c18d7e669cfd3d', traceState: undefined, name: 'decode', - id: '40a75edd2f4f08d4', + id: '11a1c3568453721f', kind: 0, - timestamp: 1726461294743000, - duration: 124.542, + timestamp: 1726541103236000, + duration: 127.375, attributes: {}, status: { code: 0 }, events: [], @@ -175,14 +175,14 @@ console.log(data) } }, instrumentationScope: { name: 'graffle', version: undefined, schemaUrl: undefined }, - traceId: '33c2903599214054eb34ee8382ee63e1', + traceId: '9f4dcc1213a3f3d4605da3d9c3340361', parentId: undefined, traceState: undefined, name: 'request', - id: 'a9cd435480d53274', + id: 'f0c18d7e669cfd3d', kind: 0, - timestamp: 1726461294589000, - duration: 154733.292, + timestamp: 1726541103050000, + duration: 186111.542, attributes: {}, status: { code: 0 }, events: [], diff --git a/website/content/guides/20_methods/10_raw.md b/website/content/guides/20_methods/10_raw.md index e136f5cea..fa4e00db8 100644 --- a/website/content/guides/20_methods/10_raw.md +++ b/website/content/guides/20_methods/10_raw.md @@ -1,99 +1,23 @@ # Raw -Raw methods allow you to work directly with GraphQL queries and data types. They have [`...OrThrow`](#orthrow) variants like other methods. They force you to use the [envelope](#envelope), however your configuration for [error channels](#errors) is still honoured. + -> Aside: These methods are approximately what `graffle` was before it turned into Graffle. +Raw methods allow you to work directly with GraphQL syntax. They approximate what `graphql-request` was before it turned into `graffle`. -## DocumentNode Document +## Sending Document Nodes -Use the `gql` template tag to get syntax highlighting (GraphQL editor extensions special case this template tag name) and construction of `TypedQueryDocumentNode`s from strings: + -Example ([see full runnable example](./examples/raw.ts)): +Graffle allows you to send `DocumentNode` instances (created from a class in the `graphql` package) directly. -```ts -import { gql } from 'graffle/utils' - -const document = gql` - query MyThing { - stuff { - foo - bar - } - } -` - -const result = await graffle.raw({ document }) -``` - -### Type Safety +Graffle exports a utility template tag `gql` to easily create them. Its name is also strategically chosen to leverage automatic GraphQL syntax highlighting that editors generally provide. You can attain type safety by creating your document with type variables. In a typical real project this would be something that a tool like [GraphQL Code Generator automatically](https://the-guild.dev/graphql/codegen) does for you. -Example ([see full runnable example](./examples/raw-typed.ts)): - -```ts -const document = gql<{ stuff: { foo: string; bar: number }, { filter: boolean } }>` - query MyThing ($filter:boolean) { - stuff (filter:$filter) { - foo - bar - } - } -` - -const result = await graffle.raw({ - document, - // Correctly typed variables now required. - variables: { - filter: true, - } -}) -``` - -## String Document - -You can skip creating document nodes if you need or wish by using `.rawString`. - -> Aside: During interface design, using an overload to combine `.raw` and `.rawString` was at first used but soon abandoned because of the poor intellisense experience TypeScript overloads currently have in editors. - -Example ([see full runnable example](./examples/rawString.ts)): - -```ts -const document = ` - query MyThing { - stuff (filter:$filter) { - foo - bar - } - } -` - -const result = await graffle.rawString({ document }) -``` - -### Type Safety - -You can attain type safety by casting your document with `TypedDocumentString`. In a typical project your tooling (like GraphQL Code Generator) would do this for you. - -Example ([see full runnable example](./examples/rawString-typed.ts)): +## Sending Strings -```ts -import { TypedDocumentString } from 'graffle/utils' + -const document = ` - query MyThing ($filter: boolean) { - stuff (filter: $filter) { - foo - bar - } - } -` as TypedDocumentString<{ stuff: { foo: string; bar: number }, { filter: boolean } }> +You can skip creating document nodes if you don't need them, instead just sending a string directly. -const result = await graffle.rawString({ - document, - // Correctly typed variables now required. - variables: { - filter: true, - } -}) -``` +You can still attain type safety even for the string input by casting your string to `TypedDocumentString`.