Skip to content

Commit

Permalink
chore(docs): document anyware (#1093)
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonkuhrt authored Sep 16, 2024
1 parent 031503f commit cb7cf1f
Show file tree
Hide file tree
Showing 19 changed files with 451 additions and 124 deletions.
14 changes: 14 additions & 0 deletions examples/20_output/output_preset__standard-graphql.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/**
* This example shows how to configure output to approximate the traditional GraphQL ExecutionResult type.
*/

import { Graffle, Preset } from '../../src/entrypoints/main.js'
import { show } from '../$/show.js'

const graffle = Graffle.create({
output: Preset.traditionalGraphqlOutput,
})

const result = await graffle.rawString({ document: `{ query { thisWillError } }` })

show(result)
Original file line number Diff line number Diff line change
Expand Up @@ -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': '1726370577818'
'x-sent-at-time': '1726460908915'
},
signal: undefined,
method: 'post',
Expand Down
10 changes: 5 additions & 5 deletions examples/__outputs__/20_output/output_envelope.output.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
headers: Headers {
connection: 'keep-alive',
'content-length': '119',
'x-served-by': 'cache-yul1970040-YUL',
'x-served-by': 'cache-yul1970049-YUL',
'accept-ranges': 'bytes',
date: 'Sun, 08 Sep 2024 18:13:26 GMT',
'content-type': 'application/graphql-response+json; charset=utf-8',
Expand All @@ -32,13 +32,13 @@
'alt-svc': 'h3=":443"; ma=86400',
'access-control-allow-origin': '*',
'x-powered-by': 'Stellate',
age: '551373',
age: '641704',
'cache-control': 'public, s-maxage=2628000, stale-while-revalidate=2628000',
'x-cache': 'HIT',
'x-cache-hits': '59',
'x-cache-hits': '72',
'gcdn-cache': 'HIT',
'stellate-rate-limit-budget-remaining': '44',
'stellate-rate-limit-rules': '"IP limit";type="RequestCount";budget=50;limited=?0;remaining=44;refill=38',
'stellate-rate-limit-budget-remaining': '49',
'stellate-rate-limit-rules': '"IP limit";type="RequestCount";budget=50;limited=?0;remaining=49;refill=60',
'stellate-rate-limit-decision': 'pass',
'stellate-rate-limit-budget-required': '5',
'content-encoding': 'br'
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/some/path/to/runPipeline.ts:84
return new ContextualError(message, { hookName: signal.hookName, source: signal.source }, signal.error)
^


ContextualError: There was an error in the core implementation of hook "exchange".
at runPipeline (/some/path/to/runPipeline.ts:XX:XX)
at async runPipeline (/some/path/to/runPipeline.ts:XX:XX)
at async runPipeline (/some/path/to/runPipeline.ts:XX:XX)
... 3 lines matching cause stack trace ...
at async Object.raw (/some/path/to/client.ts:XX:XX)
at async Proxy.rawString (/some/path/to/client.ts:XX:XX)
at async <anonymous> (/some/path/to/output_preset__standard-graphql.ts:XX:XX) {
context: { hookName: 'exchange', source: 'implementation' },
[cause]: TypeError: Failed to parse URL from undefined
at new Request (node:internal/deps/undici/undici:XX:XX)
at Object.run (/some/path/to/core.ts:XX:XX)
... 6 lines matching cause stack trace ...
at async runRaw (/some/path/to/client.ts:XX:XX)
at async Object.raw (/some/path/to/client.ts:XX:XX) {
[cause]: TypeError: Invalid URL
at new URL (node:internal/url:XX:XX)
at new Request (node:internal/deps/undici/undici:XX:XX)
at Object.run (/some/path/to/core.ts:XX:XX)
at runHook (/some/path/to/runHook.ts:XX:XX)
at runPipeline (/some/path/to/runPipeline.ts:XX:XX)
at runPipeline (/some/path/to/runPipeline.ts:XX:XX)
at async runPipeline (/some/path/to/runPipeline.ts:XX:XX)
at async Object.run (/some/path/to/main.ts:XX:XX)
at async run (/some/path/to/client.ts:XX:XX)
at async runRaw (/some/path/to/client.ts:XX:XX) {
code: 'ERR_INVALID_URL',
input: 'undefined'
}
}
}

Node.js vXX.XX.XX
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@
}
},
instrumentationScope: { name: 'graffle', version: undefined, schemaUrl: undefined },
traceId: '5f3cc79a0d7f600e6443b66ca5fd7599',
parentId: 'c7121550554a028f',
traceId: '3c05d978d79fc466c2ed6652ffd28fd5',
parentId: '58e0399ed88c4508',
traceState: undefined,
name: 'encode',
id: 'bf19a2fd444136bd',
id: '49c086e96494dda5',
kind: 0,
timestamp: 1726370578428000,
duration: 542.708,
timestamp: 1726460909321000,
duration: 540.791,
attributes: {},
status: { code: 0 },
events: [],
Expand All @@ -33,14 +33,14 @@
}
},
instrumentationScope: { name: 'graffle', version: undefined, schemaUrl: undefined },
traceId: '5f3cc79a0d7f600e6443b66ca5fd7599',
parentId: 'c7121550554a028f',
traceId: '3c05d978d79fc466c2ed6652ffd28fd5',
parentId: '58e0399ed88c4508',
traceState: undefined,
name: 'pack',
id: '7f76dd08ed8139ad',
id: 'd0a097fb28078b38',
kind: 0,
timestamp: 1726370578434000,
duration: 1102.792,
timestamp: 1726460909324000,
duration: 1157.917,
attributes: {},
status: { code: 0 },
events: [],
Expand All @@ -57,14 +57,14 @@
}
},
instrumentationScope: { name: 'graffle', version: undefined, schemaUrl: undefined },
traceId: '5f3cc79a0d7f600e6443b66ca5fd7599',
parentId: 'c7121550554a028f',
traceId: '3c05d978d79fc466c2ed6652ffd28fd5',
parentId: '58e0399ed88c4508',
traceState: undefined,
name: 'exchange',
id: 'febb48d8497c0eb4',
id: 'e786363ec0b36e1e',
kind: 0,
timestamp: 1726370578436000,
duration: 175379.417,
timestamp: 1726460909325000,
duration: 162975.333,
attributes: {},
status: { code: 0 },
events: [],
Expand All @@ -81,14 +81,14 @@
}
},
instrumentationScope: { name: 'graffle', version: undefined, schemaUrl: undefined },
traceId: '5f3cc79a0d7f600e6443b66ca5fd7599',
parentId: 'c7121550554a028f',
traceId: '3c05d978d79fc466c2ed6652ffd28fd5',
parentId: '58e0399ed88c4508',
traceState: undefined,
name: 'unpack',
id: '858aa86480423499',
id: '74c7e6a7ac759030',
kind: 0,
timestamp: 1726370578611000,
duration: 2229.292,
timestamp: 1726460909489000,
duration: 2389.542,
attributes: {},
status: { code: 0 },
events: [],
Expand All @@ -105,14 +105,14 @@
}
},
instrumentationScope: { name: 'graffle', version: undefined, schemaUrl: undefined },
traceId: '5f3cc79a0d7f600e6443b66ca5fd7599',
parentId: 'c7121550554a028f',
traceId: '3c05d978d79fc466c2ed6652ffd28fd5',
parentId: '58e0399ed88c4508',
traceState: undefined,
name: 'decode',
id: '903b572b71e9d6c3',
id: 'd6783e1de7c1353b',
kind: 0,
timestamp: 1726370578614000,
duration: 121.791,
timestamp: 1726460909491000,
duration: 128.584,
attributes: {},
status: { code: 0 },
events: [],
Expand All @@ -129,14 +129,14 @@
}
},
instrumentationScope: { name: 'graffle', version: undefined, schemaUrl: undefined },
traceId: '5f3cc79a0d7f600e6443b66ca5fd7599',
traceId: '3c05d978d79fc466c2ed6652ffd28fd5',
parentId: undefined,
traceState: undefined,
name: 'request',
id: 'c7121550554a028f',
id: '58e0399ed88c4508',
kind: 0,
timestamp: 1726370578427000,
duration: 187055.167,
timestamp: 1726460909321000,
duration: 170847,
attributes: {},
status: { code: 0 },
events: [],
Expand Down
1 change: 1 addition & 0 deletions src/entrypoints/_Preset.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { traditionalGraphqlOutput } from '../layers/6_client/Settings/Config.js'
1 change: 1 addition & 0 deletions src/entrypoints/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ export { type Config as BuilderConfig } from '../layers/6_client/Settings/Config
export { type WithInput } from '../layers/6_client/Settings/inputIncrementable/inputIncrementable.js'
export * from '../lib/prelude.js'
export * from './__Graffle.js'
export * as Preset from './_Preset.js'
2 changes: 1 addition & 1 deletion src/layers/5_core/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ export type HookDefPack<$Config extends Config> = {
}>
slots: {
/**
* When request will be sent using POST this slot is called to create the value that will be used for the HTTP body.
* When request will be sent using GET this slot is called to create the value that will be used for the HTTP Search Parameters.
*/
searchParams: getRequestEncodeSearchParameters
/**
Expand Down
19 changes: 19 additions & 0 deletions tests/examples/20_output/output_preset__standard-graphql.test.ts
Original file line number Diff line number Diff line change
@@ -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(`output_preset__standard-graphql`, async () => {
const exampleResult = await runExample(`./examples/20_output/output_preset__standard-graphql.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__/20_output/output_preset__standard-graphql.output.txt`,
)
})
2 changes: 1 addition & 1 deletion website/content/_snippets/example-links/output.md
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<p class="ExampleLinks">Examples <span class="ExampleLinksTitleSeparator">-></span> <a href="../../examples/output/default">Default</a> <span class="ExampleLinksSeparator"></span> <a href="../../examples/output/envelope">Envelope</a> <span class="ExampleLinksSeparator"></span> <a href="../../examples/output/envelope-error">Envelope Error</a> <span class="ExampleLinksSeparator"></span> <a href="../../examples/output/envelope-error-throw">Envelope Error Throw</a> <span class="ExampleLinksSeparator"></span> <a href="../../examples/output/return-error">Return Error</a> <span class="ExampleLinksSeparator"></span> <a href="../../examples/output/return-error-execution">Return Error Execution</a></p>
<p class="ExampleLinks">Examples <span class="ExampleLinksTitleSeparator">-></span> <a href="../../examples/output/default">Default</a> <span class="ExampleLinksSeparator"></span> <a href="../../examples/output/envelope">Envelope</a> <span class="ExampleLinksSeparator"></span> <a href="../../examples/output/envelope-error">Envelope Error</a> <span class="ExampleLinksSeparator"></span> <a href="../../examples/output/envelope-error-throw">Envelope Error Throw</a> <span class="ExampleLinksSeparator"></span> <a href="../../examples/output/standard-graphql">Standard Graphql</a> <span class="ExampleLinksSeparator"></span> <a href="../../examples/output/return-error">Return Error</a> <span class="ExampleLinksSeparator"></span> <a href="../../examples/output/return-error-execution">Return Error Execution</a></p>
1 change: 1 addition & 0 deletions website/content/_snippets/example-links/output_preset.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<p class="ExampleLinks">Examples <span class="ExampleLinksTitleSeparator">-></span> <a href="../../examples/output/standard-graphql">Standard Graphql</a></p>
1 change: 1 addition & 0 deletions website/content/_snippets/example-links/preset.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<p class="ExampleLinks">Examples <span class="ExampleLinksTitleSeparator">-></span> <a href="../../examples/output/standard-graphql">Standard Graphql</a></p>
6 changes: 2 additions & 4 deletions website/content/examples/10_transport-http/abort.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const graffle = Graffle.create({

const resultPromise = graffle
.with({ transport: { signal: abortController.signal } })
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
// ^^^^^^^^^^^^^^^
.rawString({
document: `
{
Expand All @@ -31,13 +31,11 @@ const resultPromise = graffle
})

abortController.abort()
// ^^^^^^^
// ^^^^^

const result = await resultPromise.catch((error: unknown) => (error as Error).message)

console.log(result)

// todo .with(...) variant
```
<!-- dprint-ignore-end -->

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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': '1726370577818'
'x-sent-at-time': '1726460908915'
},
signal: undefined,
method: 'post',
Expand Down
10 changes: 5 additions & 5 deletions website/content/examples/20_output/envelope.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ console.log(result)
headers: Headers {
connection: 'keep-alive',
'content-length': '119',
'x-served-by': 'cache-yul1970040-YUL',
'x-served-by': 'cache-yul1970049-YUL',
'accept-ranges': 'bytes',
date: 'Sun, 08 Sep 2024 18:13:26 GMT',
'content-type': 'application/graphql-response+json; charset=utf-8',
Expand All @@ -59,13 +59,13 @@ console.log(result)
'alt-svc': 'h3=":443"; ma=86400',
'access-control-allow-origin': '*',
'x-powered-by': 'Stellate',
age: '551373',
age: '641704',
'cache-control': 'public, s-maxage=2628000, stale-while-revalidate=2628000',
'x-cache': 'HIT',
'x-cache-hits': '59',
'x-cache-hits': '72',
'gcdn-cache': 'HIT',
'stellate-rate-limit-budget-remaining': '44',
'stellate-rate-limit-rules': '"IP limit";type="RequestCount";budget=50;limited=?0;remaining=44;refill=38',
'stellate-rate-limit-budget-remaining': '49',
'stellate-rate-limit-rules': '"IP limit";type="RequestCount";budget=50;limited=?0;remaining=49;refill=60',
'stellate-rate-limit-decision': 'pass',
'stellate-rate-limit-budget-required': '5',
'content-encoding': 'br'
Expand Down
66 changes: 66 additions & 0 deletions website/content/examples/20_output/standard-graphql.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
---
aside: false
---

# Standard Graphql

This example shows how to configure output to approximate the traditional GraphQL ExecutionResult type.

<!-- dprint-ignore-start -->
```ts twoslash
import { Graffle, Preset } from 'graffle'

const graffle = Graffle.create({
output: Preset.traditionalGraphqlOutput,
})

const result = await graffle.rawString({ document: `{ query { thisWillError } }` })

console.log(result)
```
<!-- dprint-ignore-end -->

#### Outputs

<!-- dprint-ignore-start -->
```txt
/some/path/to/runPipeline.ts:84
return new ContextualError(message, { hookName: signal.hookName, source: signal.source }, signal.error)
^
ContextualError: There was an error in the core implementation of hook "exchange".
at runPipeline (/some/path/to/runPipeline.ts:XX:XX)
at async runPipeline (/some/path/to/runPipeline.ts:XX:XX)
at async runPipeline (/some/path/to/runPipeline.ts:XX:XX)
... 3 lines matching cause stack trace ...
at async Object.raw (/some/path/to/client.ts:XX:XX)
at async Proxy.rawString (/some/path/to/client.ts:XX:XX)
at async <anonymous> (/some/path/to/output_preset__standard-graphql.ts:XX:XX) {
context: { hookName: 'exchange', source: 'implementation' },
[cause]: TypeError: Failed to parse URL from undefined
at new Request (node:internal/deps/undici/undici:XX:XX)
at Object.run (/some/path/to/core.ts:XX:XX)
... 6 lines matching cause stack trace ...
at async runRaw (/some/path/to/client.ts:XX:XX)
at async Object.raw (/some/path/to/client.ts:XX:XX) {
[cause]: TypeError: Invalid URL
at new URL (node:internal/url:XX:XX)
at new Request (node:internal/deps/undici/undici:XX:XX)
at Object.run (/some/path/to/core.ts:XX:XX)
at runHook (/some/path/to/runHook.ts:XX:XX)
at runPipeline (/some/path/to/runPipeline.ts:XX:XX)
at runPipeline (/some/path/to/runPipeline.ts:XX:XX)
at async runPipeline (/some/path/to/runPipeline.ts:XX:XX)
at async Object.run (/some/path/to/main.ts:XX:XX)
at async run (/some/path/to/client.ts:XX:XX)
at async runRaw (/some/path/to/client.ts:XX:XX) {
code: 'ERR_INVALID_URL',
input: 'undefined'
}
}
}
Node.js vXX.XX.XX
```
<!-- dprint-ignore-end -->
Loading

0 comments on commit cb7cf1f

Please sign in to comment.