diff --git a/examples/generated|generated_arguments__arguments.output.txt b/examples/__outputs__/generated|generated_arguments__arguments.output.txt similarity index 100% rename from examples/generated|generated_arguments__arguments.output.txt rename to examples/__outputs__/generated|generated_arguments__arguments.output.txt diff --git a/examples/other|transport-memory.output.txt b/examples/__outputs__/other|transport-memory.output.txt similarity index 100% rename from examples/other|transport-memory.output.txt rename to examples/__outputs__/other|transport-memory.output.txt diff --git a/examples/output|output_default.output.txt b/examples/__outputs__/output|output_default.output.txt similarity index 100% rename from examples/output|output_default.output.txt rename to examples/__outputs__/output|output_default.output.txt diff --git a/examples/output|output_envelope.output-encoder.ts b/examples/__outputs__/output|output_envelope.output.encoder.ts similarity index 68% rename from examples/output|output_envelope.output-encoder.ts rename to examples/__outputs__/output|output_envelope.output.encoder.ts index 94ae732be..996b8a3fc 100644 --- a/examples/output|output_envelope.output-encoder.ts +++ b/examples/__outputs__/output|output_envelope.output.encoder.ts @@ -1,4 +1,4 @@ -import { dynamicValue } from './$/helpers.js' +import { dynamicValue } from '../$/helpers.js' export const encode = (value: string) => { return value.replace(/Headers {[^}]*}/s, dynamicValue) diff --git a/examples/output|output_envelope.output.test.txt b/examples/__outputs__/output|output_envelope.output.test.txt similarity index 100% rename from examples/output|output_envelope.output.test.txt rename to examples/__outputs__/output|output_envelope.output.test.txt diff --git a/examples/output|output_envelope.output.txt b/examples/__outputs__/output|output_envelope.output.txt similarity index 89% rename from examples/output|output_envelope.output.txt rename to examples/__outputs__/output|output_envelope.output.txt index 69ce1a8a9..f14b68a41 100644 --- a/examples/output|output_envelope.output.txt +++ b/examples/__outputs__/output|output_envelope.output.txt @@ -19,7 +19,7 @@ headers: Headers { connection: 'keep-alive', 'content-length': '119', - 'x-served-by': 'cache-yul1970051-YUL', + 'x-served-by': 'cache-yul1970035-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: '158583', + age: '176284', 'cache-control': 'public, s-maxage=2628000, stale-while-revalidate=2628000', 'x-cache': 'HIT', - 'x-cache-hits': '36', + 'x-cache-hits': '13', 'gcdn-cache': 'HIT', - 'stellate-rate-limit-budget-remaining': '44', - 'stellate-rate-limit-rules': '"IP limit";type="RequestCount";budget=50;limited=?0;remaining=44;refill=60', + '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' diff --git a/examples/output|output_envelope_envelope-error__envelope-error.output.txt b/examples/__outputs__/output|output_envelope_envelope-error__envelope-error.output.txt similarity index 100% rename from examples/output|output_envelope_envelope-error__envelope-error.output.txt rename to examples/__outputs__/output|output_envelope_envelope-error__envelope-error.output.txt diff --git a/examples/output|output_envelope_envelope_error-throw__envelope-error-throw.output.txt b/examples/__outputs__/output|output_envelope_envelope_error-throw__envelope-error-throw.output.txt similarity index 100% rename from examples/output|output_envelope_envelope_error-throw__envelope-error-throw.output.txt rename to examples/__outputs__/output|output_envelope_envelope_error-throw__envelope-error-throw.output.txt diff --git a/examples/raw|raw.output.txt b/examples/__outputs__/raw|raw.output.txt similarity index 100% rename from examples/raw|raw.output.txt rename to examples/__outputs__/raw|raw.output.txt diff --git a/examples/raw|raw_rawString__rawString.output.txt b/examples/__outputs__/raw|raw_rawString__rawString.output.txt similarity index 100% rename from examples/raw|raw_rawString__rawString.output.txt rename to examples/__outputs__/raw|raw_rawString__rawString.output.txt diff --git a/examples/raw|raw_rawString_rawTyped__rawString-typed.output.txt b/examples/__outputs__/raw|raw_rawString_rawTyped__rawString-typed.output.txt similarity index 100% rename from examples/raw|raw_rawString_rawTyped__rawString-typed.output.txt rename to examples/__outputs__/raw|raw_rawString_rawTyped__rawString-typed.output.txt diff --git a/examples/raw|raw_rawTyped__raw-typed.output.txt b/examples/__outputs__/raw|raw_rawTyped__raw-typed.output.txt similarity index 100% rename from examples/raw|raw_rawTyped__raw-typed.output.txt rename to examples/__outputs__/raw|raw_rawTyped__raw-typed.output.txt diff --git a/examples/transport-http|transport-http_abort.output.txt b/examples/__outputs__/transport-http|transport-http_abort.output.txt similarity index 100% rename from examples/transport-http|transport-http_abort.output.txt rename to examples/__outputs__/transport-http|transport-http_abort.output.txt diff --git a/examples/transport-http|transport-http_extension_fetch__custom-fetch.output.txt b/examples/__outputs__/transport-http|transport-http_extension_fetch__custom-fetch.output.txt similarity index 100% rename from examples/transport-http|transport-http_extension_fetch__custom-fetch.output.txt rename to examples/__outputs__/transport-http|transport-http_extension_fetch__custom-fetch.output.txt diff --git a/examples/transport-http|transport-http_extension_headers__dynamicHeaders.output-encoder.ts b/examples/__outputs__/transport-http|transport-http_extension_headers__dynamicHeaders.output.encoder.ts similarity index 100% rename from examples/transport-http|transport-http_extension_headers__dynamicHeaders.output-encoder.ts rename to examples/__outputs__/transport-http|transport-http_extension_headers__dynamicHeaders.output.encoder.ts diff --git a/examples/transport-http|transport-http_extension_headers__dynamicHeaders.output.test.txt b/examples/__outputs__/transport-http|transport-http_extension_headers__dynamicHeaders.output.test.txt similarity index 100% rename from examples/transport-http|transport-http_extension_headers__dynamicHeaders.output.test.txt rename to examples/__outputs__/transport-http|transport-http_extension_headers__dynamicHeaders.output.test.txt diff --git a/examples/transport-http|transport-http_extension_headers__dynamicHeaders.output.txt b/examples/__outputs__/transport-http|transport-http_extension_headers__dynamicHeaders.output.txt similarity index 91% rename from examples/transport-http|transport-http_extension_headers__dynamicHeaders.output.txt rename to examples/__outputs__/transport-http|transport-http_extension_headers__dynamicHeaders.output.txt index 261118f59..b42fd66ad 100644 --- a/examples/transport-http|transport-http_extension_headers__dynamicHeaders.output.txt +++ b/examples/__outputs__/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': '1725977788513' + 'x-sent-at-time': '1725995489078' }, signal: undefined, method: 'post', diff --git a/examples/transport-http|transport-http_headers_raw__headers.output.txt b/examples/__outputs__/transport-http|transport-http_headers_raw__headers.output.txt similarity index 100% rename from examples/transport-http|transport-http_headers_raw__headers.output.txt rename to examples/__outputs__/transport-http|transport-http_headers_raw__headers.output.txt diff --git a/examples/transport-http|transport-http_method-get.output.txt b/examples/__outputs__/transport-http|transport-http_method-get.output.txt similarity index 100% rename from examples/transport-http|transport-http_method-get.output.txt rename to examples/__outputs__/transport-http|transport-http_method-get.output.txt diff --git a/examples/transport-http|transport-http_raw.output.txt b/examples/__outputs__/transport-http|transport-http_raw.output.txt similarity index 100% rename from examples/transport-http|transport-http_raw.output.txt rename to examples/__outputs__/transport-http|transport-http_raw.output.txt diff --git a/examples/generated|generated_arguments__arguments.ts b/examples/generated|generated_arguments__arguments.ts index 79925706b..f58082dd3 100644 --- a/examples/generated|generated_arguments__arguments.ts +++ b/examples/generated|generated_arguments__arguments.ts @@ -1,3 +1,7 @@ +/** + * This example shows how to use the TypeScript interface for GraphQL arguments. + */ + import { Atlas } from './$/generated-clients/atlas/__.js' import { showJson } from './$/helpers.js' diff --git a/examples/other|transport-memory.ts b/examples/other|transport-memory.ts index 2a1618136..f0fd54e33 100644 --- a/examples/other|transport-memory.ts +++ b/examples/other|transport-memory.ts @@ -1,3 +1,7 @@ +/** + * This example shows how you can send requests against an in-memory GraphQL schema instead of one hosted over HTTP. + */ + import { GraphQLObjectType, GraphQLSchema, GraphQLString } from 'graphql' import { Graffle } from '../src/entrypoints/main.js' import { showJson } from './$/helpers.js' diff --git a/examples/output|output_default.ts b/examples/output|output_default.ts index 601cf5e2d..af450cebc 100644 --- a/examples/output|output_default.ts +++ b/examples/output|output_default.ts @@ -1,3 +1,7 @@ +/** + * This example shows the default output behavior. + */ + import { Atlas } from './$/generated-clients/atlas/__.js' import { show } from './$/helpers.js' diff --git a/examples/output|output_envelope.ts b/examples/output|output_envelope.ts index 4bd25419c..477a26cad 100644 --- a/examples/output|output_envelope.ts +++ b/examples/output|output_envelope.ts @@ -1,3 +1,7 @@ +/** + * This example shows how to configure output to use the envelope. + */ + import { Atlas } from './$/generated-clients/atlas/__.js' import { show } from './$/helpers.js' diff --git a/examples/raw|raw.ts b/examples/raw|raw.ts index 57d5b499d..ff436076e 100644 --- a/examples/raw|raw.ts +++ b/examples/raw|raw.ts @@ -1,3 +1,7 @@ +/** + * This example shows how to send a request using a Document instance for the GraphQL document. + */ + import { gql, Graffle } from '../src/entrypoints/main.js' import { publicGraphQLSchemaEndpoints, show } from './$/helpers.js' diff --git a/examples/raw|raw_rawString__rawString.ts b/examples/raw|raw_rawString__rawString.ts index 83691523b..5ef654e8e 100644 --- a/examples/raw|raw_rawString__rawString.ts +++ b/examples/raw|raw_rawString__rawString.ts @@ -1,3 +1,7 @@ +/** + * This example shows how to send a request using a string for the GraphQL document. + */ + import { Graffle } from '../src/entrypoints/main.js' import { publicGraphQLSchemaEndpoints, show } from './$/helpers.js' diff --git a/examples/raw|raw_rawString_rawTyped__rawString-typed.ts b/examples/raw|raw_rawString_rawTyped__rawString-typed.ts index 65af0c85c..b0a12f440 100644 --- a/examples/raw|raw_rawString_rawTyped__rawString-typed.ts +++ b/examples/raw|raw_rawString_rawTyped__rawString-typed.ts @@ -1,3 +1,9 @@ +/** + * 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. + */ + import { Graffle, type TypedDocumentString } from '../src/entrypoints/main.js' import { publicGraphQLSchemaEndpoints, show } from './$/helpers.js' diff --git a/examples/raw|raw_rawTyped__raw-typed.ts b/examples/raw|raw_rawTyped__raw-typed.ts index 95a7eab4b..bcd9aabfb 100644 --- a/examples/raw|raw_rawTyped__raw-typed.ts +++ b/examples/raw|raw_rawTyped__raw-typed.ts @@ -1,3 +1,7 @@ +/** + * 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. + */ + import type { TypedQueryDocumentNode } from 'graphql' import { gql, Graffle } from '../src/entrypoints/main.js' import { publicGraphQLSchemaEndpoints, show } from './$/helpers.js' diff --git a/examples/transport-http|transport-http_headers_raw__headers.ts b/examples/transport-http|transport-http_headers_raw__headers.ts index c6859687e..3088e524a 100644 --- a/examples/transport-http|transport-http_headers_raw__headers.ts +++ b/examples/transport-http|transport-http_headers_raw__headers.ts @@ -1,6 +1,7 @@ /** * This example shows how to use the `transport` configuration to control request headers. Notice how empty string headers unset previously set headers. */ + import { Graffle } from '../src/entrypoints/main.js' import { show } from './$/helpers.js' import { publicGraphQLSchemaEndpoints } from './$/helpers.js' diff --git a/examples/transport-http|transport-http_raw.ts b/examples/transport-http|transport-http_raw.ts index 692b0fcd6..08f6ec2f9 100644 --- a/examples/transport-http|transport-http_raw.ts +++ b/examples/transport-http|transport-http_raw.ts @@ -1,6 +1,7 @@ /** * This example shows how to use the `raw` configuration of transport configuration to easily access low-level `RequestInit` configuration. */ + import { Graffle } from '../src/entrypoints/main.js' import { show } from './$/helpers.js' import { publicGraphQLSchemaEndpoints } from './$/helpers.js' diff --git a/scripts/generate-examples-derivatives/generate-docs.ts b/scripts/generate-examples-derivatives/generate-docs.ts index cf913b5b2..67faf769c 100644 --- a/scripts/generate-examples-derivatives/generate-docs.ts +++ b/scripts/generate-examples-derivatives/generate-docs.ts @@ -3,11 +3,9 @@ import * as FS from 'node:fs/promises' import { type DefaultTheme } from 'vitepress' import { documentQueryContinents, publicGraphQLSchemaEndpoints } from '../../examples/$/helpers.js' import { deleteFiles } from '../lib/deleteFiles.js' -import { computeCombinations, type Example, readExamples, toTitle } from './helpers.js' - -export const generateDocs = async () => { - const examples = await readExamples() +import { computeCombinations, type Example, toTitle } from './helpers.js' +export const generateDocs = async (examples: Example[]) => { const examplesTransformed = examples .map(transformOther) .map(transformRewriteGraffleImports) diff --git a/scripts/generate-examples-derivatives/generate-outputs.ts b/scripts/generate-examples-derivatives/generate-outputs.ts index d3a2eadb1..9ee15282e 100644 --- a/scripts/generate-examples-derivatives/generate-outputs.ts +++ b/scripts/generate-examples-derivatives/generate-outputs.ts @@ -1,17 +1,18 @@ import * as FS from 'node:fs/promises' import { deleteFiles } from '../lib/deleteFiles.js' -import { readExampleFiles, runExample } from './helpers.js' +import { directories, type Example, runExample } from './helpers.js' -export const generateOutputs = async () => { +export const generateOutputs = async (examples: Example[]) => { // Handle case of renaming or deleting examples. - await deleteFiles({ pattern: `./examples/*.output.*` }) + await Promise.all([ + deleteFiles({ pattern: `./examples/*.output.txt` }), + deleteFiles({ pattern: `${directories.outputs}/*.output.txt` }), + ]) - const exampleFiles = await readExampleFiles() - - await Promise.all(exampleFiles.map(async (file) => { - const filePath = `./examples/${file.name}.ts` + await Promise.all(examples.map(async (example) => { + const filePath = `./examples/${example.file.name}.ts` const exampleResult = await runExample(filePath) - await FS.writeFile(`./examples/${file.name}.output.txt`, exampleResult) + await FS.writeFile(`${directories.outputs}/${example.file.name}.output.txt`, exampleResult) })) console.log(`Generated an output for each example.`) diff --git a/scripts/generate-examples-derivatives/generate-tests.ts b/scripts/generate-examples-derivatives/generate-tests.ts index c7b05aa85..184668dda 100644 --- a/scripts/generate-examples-derivatives/generate-tests.ts +++ b/scripts/generate-examples-derivatives/generate-tests.ts @@ -1,27 +1,23 @@ -import { globby } from 'globby' import * as FS from 'node:fs/promises' import * as Path from 'node:path' import { deleteFiles } from '../lib/deleteFiles.js' -import { readFiles } from '../lib/readFiles.js' +import { directories, type Example } from './helpers.js' -export const generateTests = async () => { +export const generateTests = async (examples: Example[]) => { // Handle case of renaming or deleting examples. - await deleteFiles({ pattern: `./tests/examples/*.test.ts` }) - - const exampleFiles = await readFiles({ - pattern: `./examples/*.ts`, - options: { ignore: [`./examples/$*`, `./examples/*.output.*`, `./examples/*.output-encoder.*`] }, - }) - const encoderFilePaths = await globby(`./examples/*.output-encoder.ts`) + await Promise.all([ + deleteFiles({ pattern: `${directories.outputs}/*.output.test.txt` }), + deleteFiles({ pattern: `${directories.examples}/*.output.test.txt` }), + deleteFiles({ pattern: `./tests/examples/*.test.ts` }), + ]) const outputDir = Path.join(process.cwd(), `./tests/examples`) - await Promise.all(exampleFiles.map(async (file) => { - const encoderFilePath = encoderFilePaths.find((encoderFilePath) => - encoderFilePath.includes(`${file.name}.output-encoder.ts`) - ) - const snapshotFileName = `../../${file.path.dir}/${file.name}.output${encoderFilePath ? `.test` : ``}.txt` - const exampleFilePath = `./examples/${file.name}.ts` + await Promise.all(examples.map(async (example) => { + const snapshotFileName = `../../${example.file.path.dir}/__outputs__/${example.file.name}.output${ + example.output.encoder ? `.test` : `` + }.txt` + const exampleFilePath = `./examples/${example.file.name}.ts` const code = `// @vitest-environment node // WARNING: @@ -30,21 +26,23 @@ export const generateTests = async () => { import { runExample } from '../../scripts/generate-examples-derivatives/helpers.js' import { expect, test } from 'vitest'${ - encoderFilePath - ? `\nimport { encode } from '${Path.relative(outputDir, encoderFilePath.replace(`.ts`, `.js`))}'` + example.output.encoder + ? `\nimport { encode } from '${ + Path.relative(outputDir, example.output.encoder.filePath.replace(`.ts`, `.js`)) + }'` : `` } -test(\`${file.name}\`, async () => { +test(\`${example.file.name}\`, async () => { const exampleResult = await runExample(\`${exampleFilePath}\`) // Examples should output their data results. - const exampleResultMaybeEncoded = ${encoderFilePath ? `encode(exampleResult)` : `exampleResult`} + const exampleResultMaybeEncoded = ${example.output.encoder ? `encode(exampleResult)` : `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(\`${snapshotFileName}\`) }) ` - await FS.writeFile(Path.join(outputDir, `${file.name}.test.ts`), code) + await FS.writeFile(Path.join(outputDir, `${example.file.name}.test.ts`), code) })) console.log(`Generated a test for each example.`) diff --git a/scripts/generate-examples-derivatives/generate.ts b/scripts/generate-examples-derivatives/generate.ts index 242d2eb06..0d8c03194 100644 --- a/scripts/generate-examples-derivatives/generate.ts +++ b/scripts/generate-examples-derivatives/generate.ts @@ -1,6 +1,8 @@ import { generateDocs } from './generate-docs.js' import { generateOutputs } from './generate-outputs.js' import { generateTests } from './generate-tests.js' +import { readExamples } from './helpers.js' -await Promise.all([generateOutputs(), generateTests()]) -await generateDocs() +const examples = await readExamples() +await Promise.all([generateOutputs(examples), generateTests(examples)]) +await generateDocs(examples) diff --git a/scripts/generate-examples-derivatives/helpers.ts b/scripts/generate-examples-derivatives/helpers.ts index 466e3e28f..9fc545666 100644 --- a/scripts/generate-examples-derivatives/helpers.ts +++ b/scripts/generate-examples-derivatives/helpers.ts @@ -1,9 +1,15 @@ import { capitalize, kebabCase } from 'es-toolkit' import { execa } from 'execa' +import { globby } from 'globby' import stripAnsi from 'strip-ansi' import { showPartition } from '../../examples/$/helpers.js' import { type File, readFiles } from '../lib/readFiles.js' +export const directories = { + outputs: `./examples/__outputs__`, + examples: `./examples`, +} + export const examplesIgnorePatterns = [`./examples/$*`, `./examples/*.output.*`, `./examples/*.output-encoder.*`] export const readExampleFiles = () => @@ -16,12 +22,17 @@ export const readExamples = async (): Promise => { const exampleFiles = await readExampleFiles() const outputFiles = await readFiles({ - pattern: `./examples/*.output.txt`, + pattern: `./examples/__outputs__/*.output.txt`, }) + const encoderFilePaths = await globby(`${directories.outputs}/*.output.encoder.ts`) + const examples = exampleFiles.map((example) => { const outputFile = outputFiles.find(file => file.name === `${example.name}.output.txt`) if (!outputFile) throw new Error(`Could not find output file for ${example.name}`) + const encoderFilePath = encoderFilePaths.find((encoderFilePath) => + encoderFilePath.includes(`${example.name}.output.encoder.ts`) + ) const { description, content } = extractDescription(example.content) @@ -34,6 +45,11 @@ export const readExamples = async (): Promise => { output: { file: outputFile, blocks: outputFile.content.split(showPartition + `\n`).map(block => block.trim()).filter(Boolean), + encoder: encoderFilePath + ? { + filePath: encoderFilePath, + } + : undefined, }, isUsingJsonOutput: example.content.includes(`showJson`), description, @@ -82,6 +98,9 @@ export interface Example { output: { file: File blocks: string[] + encoder?: { + filePath: string + } } isUsingJsonOutput: boolean tags: Tag[] diff --git a/tests/examples/generated|generated_arguments__arguments.test.ts b/tests/examples/generated|generated_arguments__arguments.test.ts index 30dea3e45..f5ea7d9db 100644 --- a/tests/examples/generated|generated_arguments__arguments.test.ts +++ b/tests/examples/generated|generated_arguments__arguments.test.ts @@ -14,6 +14,6 @@ test(`generated|generated_arguments__arguments`, async () => { // 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/generated|generated_arguments__arguments.output.txt`, + `../.././examples/__outputs__/generated|generated_arguments__arguments.output.txt`, ) }) diff --git a/tests/examples/other|transport-memory.test.ts b/tests/examples/other|transport-memory.test.ts index 96124daa5..2b90d270d 100644 --- a/tests/examples/other|transport-memory.test.ts +++ b/tests/examples/other|transport-memory.test.ts @@ -13,5 +13,7 @@ test(`other|transport-memory`, async () => { 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/other|transport-memory.output.txt`) + await expect(exampleResultMaybeEncoded).toMatchFileSnapshot( + `../.././examples/__outputs__/other|transport-memory.output.txt`, + ) }) diff --git a/tests/examples/output|output_default.test.ts b/tests/examples/output|output_default.test.ts index 41e22be21..8916c2d19 100644 --- a/tests/examples/output|output_default.test.ts +++ b/tests/examples/output|output_default.test.ts @@ -13,5 +13,7 @@ test(`output|output_default`, async () => { 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/output|output_default.output.txt`) + await expect(exampleResultMaybeEncoded).toMatchFileSnapshot( + `../.././examples/__outputs__/output|output_default.output.txt`, + ) }) diff --git a/tests/examples/output|output_envelope.test.ts b/tests/examples/output|output_envelope.test.ts index fff3fbe9f..2122fb264 100644 --- a/tests/examples/output|output_envelope.test.ts +++ b/tests/examples/output|output_envelope.test.ts @@ -5,7 +5,7 @@ // Do not modify this file directly. import { expect, test } from 'vitest' -import { encode } from '../../examples/output|output_envelope.output-encoder.js' +import { encode } from '../../examples/__outputs__/output|output_envelope.output.encoder.js' import { runExample } from '../../scripts/generate-examples-derivatives/helpers.js' test(`output|output_envelope`, async () => { @@ -14,5 +14,7 @@ test(`output|output_envelope`, async () => { const exampleResultMaybeEncoded = encode(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/output|output_envelope.output.test.txt`) + await expect(exampleResultMaybeEncoded).toMatchFileSnapshot( + `../.././examples/__outputs__/output|output_envelope.output.test.txt`, + ) }) diff --git a/tests/examples/output|output_envelope_envelope-error__envelope-error.test.ts b/tests/examples/output|output_envelope_envelope-error__envelope-error.test.ts index e7f9ed4b1..b317690c0 100644 --- a/tests/examples/output|output_envelope_envelope-error__envelope-error.test.ts +++ b/tests/examples/output|output_envelope_envelope-error__envelope-error.test.ts @@ -14,6 +14,6 @@ test(`output|output_envelope_envelope-error__envelope-error`, async () => { // 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/output|output_envelope_envelope-error__envelope-error.output.txt`, + `../.././examples/__outputs__/output|output_envelope_envelope-error__envelope-error.output.txt`, ) }) diff --git a/tests/examples/output|output_envelope_envelope_error-throw__envelope-error-throw.test.ts b/tests/examples/output|output_envelope_envelope_error-throw__envelope-error-throw.test.ts index 13d5b5797..239c0c9ba 100644 --- a/tests/examples/output|output_envelope_envelope_error-throw__envelope-error-throw.test.ts +++ b/tests/examples/output|output_envelope_envelope_error-throw__envelope-error-throw.test.ts @@ -16,6 +16,6 @@ test(`output|output_envelope_envelope_error-throw__envelope-error-throw`, async // 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/output|output_envelope_envelope_error-throw__envelope-error-throw.output.txt`, + `../.././examples/__outputs__/output|output_envelope_envelope_error-throw__envelope-error-throw.output.txt`, ) }) diff --git a/tests/examples/raw|raw.test.ts b/tests/examples/raw|raw.test.ts index 0c51ec7d5..b6c1dddb6 100644 --- a/tests/examples/raw|raw.test.ts +++ b/tests/examples/raw|raw.test.ts @@ -13,5 +13,5 @@ test(`raw|raw`, async () => { 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/raw|raw.output.txt`) + await expect(exampleResultMaybeEncoded).toMatchFileSnapshot(`../.././examples/__outputs__/raw|raw.output.txt`) }) diff --git a/tests/examples/raw|raw_rawString__rawString.test.ts b/tests/examples/raw|raw_rawString__rawString.test.ts index 81ee25957..53838cf81 100644 --- a/tests/examples/raw|raw_rawString__rawString.test.ts +++ b/tests/examples/raw|raw_rawString__rawString.test.ts @@ -14,6 +14,6 @@ test(`raw|raw_rawString__rawString`, async () => { // 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/raw|raw_rawString__rawString.output.txt`, + `../.././examples/__outputs__/raw|raw_rawString__rawString.output.txt`, ) }) diff --git a/tests/examples/raw|raw_rawString_rawTyped__rawString-typed.test.ts b/tests/examples/raw|raw_rawString_rawTyped__rawString-typed.test.ts index dc2c28a03..7e45429ea 100644 --- a/tests/examples/raw|raw_rawString_rawTyped__rawString-typed.test.ts +++ b/tests/examples/raw|raw_rawString_rawTyped__rawString-typed.test.ts @@ -14,6 +14,6 @@ test(`raw|raw_rawString_rawTyped__rawString-typed`, async () => { // 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/raw|raw_rawString_rawTyped__rawString-typed.output.txt`, + `../.././examples/__outputs__/raw|raw_rawString_rawTyped__rawString-typed.output.txt`, ) }) diff --git a/tests/examples/raw|raw_rawTyped__raw-typed.test.ts b/tests/examples/raw|raw_rawTyped__raw-typed.test.ts index 1f5512e64..82f51feaa 100644 --- a/tests/examples/raw|raw_rawTyped__raw-typed.test.ts +++ b/tests/examples/raw|raw_rawTyped__raw-typed.test.ts @@ -13,5 +13,7 @@ test(`raw|raw_rawTyped__raw-typed`, async () => { 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/raw|raw_rawTyped__raw-typed.output.txt`) + await expect(exampleResultMaybeEncoded).toMatchFileSnapshot( + `../.././examples/__outputs__/raw|raw_rawTyped__raw-typed.output.txt`, + ) }) diff --git a/tests/examples/transport-http|transport-http_abort.test.ts b/tests/examples/transport-http|transport-http_abort.test.ts index efac00cc6..2b3d498a1 100644 --- a/tests/examples/transport-http|transport-http_abort.test.ts +++ b/tests/examples/transport-http|transport-http_abort.test.ts @@ -14,6 +14,6 @@ test(`transport-http|transport-http_abort`, async () => { // 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/transport-http|transport-http_abort.output.txt`, + `../.././examples/__outputs__/transport-http|transport-http_abort.output.txt`, ) }) diff --git a/tests/examples/transport-http|transport-http_extension_fetch__custom-fetch.test.ts b/tests/examples/transport-http|transport-http_extension_fetch__custom-fetch.test.ts index 0c0f85de6..046f3fe01 100644 --- a/tests/examples/transport-http|transport-http_extension_fetch__custom-fetch.test.ts +++ b/tests/examples/transport-http|transport-http_extension_fetch__custom-fetch.test.ts @@ -14,6 +14,6 @@ test(`transport-http|transport-http_extension_fetch__custom-fetch`, async () => // 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/transport-http|transport-http_extension_fetch__custom-fetch.output.txt`, + `../.././examples/__outputs__/transport-http|transport-http_extension_fetch__custom-fetch.output.txt`, ) }) diff --git a/tests/examples/transport-http|transport-http_extension_headers__dynamicHeaders.test.ts b/tests/examples/transport-http|transport-http_extension_headers__dynamicHeaders.test.ts index e1b0520f7..f413381e3 100644 --- a/tests/examples/transport-http|transport-http_extension_headers__dynamicHeaders.test.ts +++ b/tests/examples/transport-http|transport-http_extension_headers__dynamicHeaders.test.ts @@ -5,7 +5,7 @@ // Do not modify this file directly. import { expect, test } from 'vitest' -import { encode } from '../../examples/transport-http|transport-http_extension_headers__dynamicHeaders.output-encoder.js' +import { encode } from '../../examples/__outputs__/transport-http|transport-http_extension_headers__dynamicHeaders.output.encoder.js' import { runExample } from '../../scripts/generate-examples-derivatives/helpers.js' test(`transport-http|transport-http_extension_headers__dynamicHeaders`, async () => { @@ -17,6 +17,6 @@ test(`transport-http|transport-http_extension_headers__dynamicHeaders`, async () // 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/transport-http|transport-http_extension_headers__dynamicHeaders.output.test.txt`, + `../.././examples/__outputs__/transport-http|transport-http_extension_headers__dynamicHeaders.output.test.txt`, ) }) diff --git a/tests/examples/transport-http|transport-http_headers_raw__headers.test.ts b/tests/examples/transport-http|transport-http_headers_raw__headers.test.ts index a88962128..46fdef1cd 100644 --- a/tests/examples/transport-http|transport-http_headers_raw__headers.test.ts +++ b/tests/examples/transport-http|transport-http_headers_raw__headers.test.ts @@ -14,6 +14,6 @@ test(`transport-http|transport-http_headers_raw__headers`, async () => { // 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/transport-http|transport-http_headers_raw__headers.output.txt`, + `../.././examples/__outputs__/transport-http|transport-http_headers_raw__headers.output.txt`, ) }) diff --git a/tests/examples/transport-http|transport-http_method-get.test.ts b/tests/examples/transport-http|transport-http_method-get.test.ts index e74682945..d751c33bc 100644 --- a/tests/examples/transport-http|transport-http_method-get.test.ts +++ b/tests/examples/transport-http|transport-http_method-get.test.ts @@ -14,6 +14,6 @@ test(`transport-http|transport-http_method-get`, async () => { // 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/transport-http|transport-http_method-get.output.txt`, + `../.././examples/__outputs__/transport-http|transport-http_method-get.output.txt`, ) }) diff --git a/tests/examples/transport-http|transport-http_raw.test.ts b/tests/examples/transport-http|transport-http_raw.test.ts index dfb1ca5eb..2b024df62 100644 --- a/tests/examples/transport-http|transport-http_raw.test.ts +++ b/tests/examples/transport-http|transport-http_raw.test.ts @@ -14,6 +14,6 @@ test(`transport-http|transport-http_raw`, async () => { // 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/transport-http|transport-http_raw.output.txt`, + `../.././examples/__outputs__/transport-http|transport-http_raw.output.txt`, ) }) diff --git a/website/content/examples/generated-arguments.md b/website/content/examples/generated-arguments.md index adfc839bf..0824098b1 100644 --- a/website/content/examples/generated-arguments.md +++ b/website/content/examples/generated-arguments.md @@ -4,6 +4,8 @@ aside: false # Arguments +This example shows how to use the TypeScript interface for GraphQL arguments. + ```ts twoslash // ---cut--- diff --git a/website/content/examples/other-transport-memory.md b/website/content/examples/other-transport-memory.md index b0974f35f..191d4831e 100644 --- a/website/content/examples/other-transport-memory.md +++ b/website/content/examples/other-transport-memory.md @@ -4,6 +4,8 @@ aside: false # Transport Memory +This example shows how you can send requests against an in-memory GraphQL schema instead of one hosted over HTTP. + ```ts twoslash import { GraphQLObjectType, GraphQLSchema, GraphQLString } from 'graphql' diff --git a/website/content/examples/output-default.md b/website/content/examples/output-default.md index bac025fc1..b8bbb1662 100644 --- a/website/content/examples/output-default.md +++ b/website/content/examples/output-default.md @@ -4,6 +4,8 @@ aside: false # Default +This example shows the default output behavior. + ```ts twoslash // ---cut--- diff --git a/website/content/examples/output-envelope.md b/website/content/examples/output-envelope.md index b69c6c8df..aa98d1ffa 100644 --- a/website/content/examples/output-envelope.md +++ b/website/content/examples/output-envelope.md @@ -4,6 +4,8 @@ aside: false # Envelope +This example shows how to configure output to use the envelope. + ```ts twoslash // ---cut--- @@ -46,7 +48,7 @@ console.log(result) headers: Headers { connection: 'keep-alive', 'content-length': '119', - 'x-served-by': 'cache-yul1970051-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 +61,13 @@ console.log(result) 'alt-svc': 'h3=":443"; ma=86400', 'access-control-allow-origin': '*', 'x-powered-by': 'Stellate', - age: '158583', + age: '175934', 'cache-control': 'public, s-maxage=2628000, stale-while-revalidate=2628000', 'x-cache': 'HIT', - 'x-cache-hits': '36', + 'x-cache-hits': '32', 'gcdn-cache': 'HIT', - 'stellate-rate-limit-budget-remaining': '44', - 'stellate-rate-limit-rules': '"IP limit";type="RequestCount";budget=50;limited=?0;remaining=44;refill=60', + 'stellate-rate-limit-budget-remaining': '43', + 'stellate-rate-limit-rules': '"IP limit";type="RequestCount";budget=50;limited=?0;remaining=43;refill=59', 'stellate-rate-limit-decision': 'pass', 'stellate-rate-limit-budget-required': '5', 'content-encoding': 'br' diff --git a/website/content/examples/raw-raw-string-typed.md b/website/content/examples/raw-raw-string-typed.md index 54b8638b7..86bb5649f 100644 --- a/website/content/examples/raw-raw-string-typed.md +++ b/website/content/examples/raw-raw-string-typed.md @@ -4,6 +4,10 @@ aside: false # Raw 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. + ```ts twoslash import { Graffle, type TypedDocumentString } from 'graffle' diff --git a/website/content/examples/raw-raw-string.md b/website/content/examples/raw-raw-string.md index 0aab4e052..39b0518c4 100644 --- a/website/content/examples/raw-raw-string.md +++ b/website/content/examples/raw-raw-string.md @@ -4,6 +4,8 @@ aside: false # Raw String +This example shows how to send a request using a string for the GraphQL document. + ```ts twoslash import { Graffle } from 'graffle' diff --git a/website/content/examples/raw-raw-typed.md b/website/content/examples/raw-raw-typed.md index fd7376279..3d7f1c789 100644 --- a/website/content/examples/raw-raw-typed.md +++ b/website/content/examples/raw-raw-typed.md @@ -4,6 +4,8 @@ aside: false # Raw 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. + ```ts twoslash import type { TypedQueryDocumentNode } from 'graphql' diff --git a/website/content/examples/raw-raw.md b/website/content/examples/raw-raw.md index f0f5789e3..9aaa2450f 100644 --- a/website/content/examples/raw-raw.md +++ b/website/content/examples/raw-raw.md @@ -4,6 +4,8 @@ aside: false # Raw +This example shows how to send a request using a Document instance for the GraphQL document. + ```ts twoslash import { gql, Graffle } from 'graffle' diff --git a/website/content/examples/transport-http-dynamic-headers.md b/website/content/examples/transport-http-dynamic-headers.md index 4003fa538..6252f1c55 100644 --- a/website/content/examples/transport-http-dynamic-headers.md +++ b/website/content/examples/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': '1725977788513' + 'x-sent-at-time': '1725995139086' }, signal: undefined, method: 'post',