From 61ecd399f9baf389413382c3b4fa1ab2b0c12f10 Mon Sep 17 00:00:00 2001 From: Jason Kuhrt Date: Thu, 26 Sep 2024 12:23:53 -0400 Subject: [PATCH] refactor: document data type flow (#1130) --- examples/$/show.ts | 2 +- .../generated_arguments__arguments.ts | 3 +- .../transport-http_abort.output.txt | 2 +- ...tension_headers__dynamicHeaders.output.txt | 2 +- .../20_output/output_envelope.output.txt | 2 +- ..._envelope-error__envelope-error.output.txt | 2 +- ...ror-throw__envelope-error-throw.output.txt | 2 +- .../20_output/output_return-error.output.txt | 2 +- ...ecution__return-error-execution.output.txt | 4 +- ...on_opentelemetry__opentelemetry.output.txt | 58 ++-- src/entrypoints/_Print.ts | 1 + src/entrypoints/main.ts | 1 + src/layers/2_SelectionSet/print.test.ts | 4 +- src/layers/2_SelectionSet/print.ts | 69 ++--- src/layers/2_SelectionSet/types.ts | 18 +- src/layers/4_document/document.ts | 129 ++++++++ src/layers/4_document/print.ts | 42 ++- src/layers/5_core/core.ts | 23 +- src/layers/5_core/hooks.ts | 9 +- src/layers/6_client/client.ts | 99 ++---- .../6_client/requestMethods/document.test.ts | 18 +- .../6_client/requestMethods/document.ts | 15 +- src/lib/anyware/runHook.ts | 7 +- src/lib/graphql.ts | 5 +- website/.vitepress/theme/content.css | 41 +++ website/.vitepress/theme/custom.css | 281 ------------------ website/.vitepress/theme/examples.css | 116 ++++++++ website/.vitepress/theme/home.css | 123 ++++++++ website/.vitepress/theme/index.ts | 3 + .../extension/opentelemetry.detail.md | 58 ++-- .../examples/extension/opentelemetry.md | 58 ++-- .../examples/generated/arguments.detail.md | 2 +- .../_snippets/examples/generated/arguments.md | 2 +- .../output/envelope-error-throw.detail.md | 2 +- .../examples/output/envelope-error-throw.md | 2 +- .../examples/output/envelope-error.detail.md | 2 +- .../examples/output/envelope-error.md | 2 +- .../examples/output/envelope.detail.md | 2 +- .../_snippets/examples/output/envelope.md | 2 +- .../output/return-error-execution.detail.md | 4 +- .../examples/output/return-error-execution.md | 4 +- .../examples/output/return-error.detail.md | 2 +- .../_snippets/examples/output/return-error.md | 2 +- .../examples/transport-http/abort.detail.md | 2 +- .../examples/transport-http/abort.md | 2 +- .../transport-http/dynamic-headers.detail.md | 2 +- .../transport-http/dynamic-headers.md | 2 +- .../examples/10_transport-http/abort.md | 2 +- .../10_transport-http/dynamic-headers.md | 2 +- .../20_output/envelope-error-throw.md | 2 +- .../examples/20_output/envelope-error.md | 2 +- .../content/examples/20_output/envelope.md | 2 +- .../20_output/return-error-execution.md | 4 +- .../examples/20_output/return-error.md | 2 +- .../examples/55_generated/arguments.md | 2 +- .../examples/60_extension/opentelemetry.md | 58 ++-- 56 files changed, 708 insertions(+), 603 deletions(-) create mode 100644 src/entrypoints/_Print.ts create mode 100644 website/.vitepress/theme/content.css create mode 100644 website/.vitepress/theme/examples.css create mode 100644 website/.vitepress/theme/home.css diff --git a/examples/$/show.ts b/examples/$/show.ts index 5977d0fa4..c6d67c56a 100644 --- a/examples/$/show.ts +++ b/examples/$/show.ts @@ -9,7 +9,7 @@ export const show = <$Logger extends Logger = typeof console.log>( subTitle?: string, ): ReturnType<$Logger> => { const write = console.log - const inspected = inspect(value, { depth: null, colors: true }) + const inspected = typeof value === 'string' ? value : inspect(value, { depth: null, colors: true }) const message = renderShow(inspected, subTitle) return write(message) as ReturnType<$Logger> } diff --git a/examples/55_generated/generated_arguments__arguments.ts b/examples/55_generated/generated_arguments__arguments.ts index 79c9fc62b..0e4957c58 100644 --- a/examples/55_generated/generated_arguments__arguments.ts +++ b/examples/55_generated/generated_arguments__arguments.ts @@ -7,8 +7,9 @@ import { showJson } from '../$/helpers.js' const atlas = Pokemon.create() +// dprint-ignore const pokemons = await atlas.query.pokemons({ - $: { filter: { name: { in: [`Pikachu`, `Charizard`] } } }, + $: { filter: { name: { in: [`Pikachu`, `Charizard`] } } }, // [!code highlight] name: true, trainer: { name: true }, }) diff --git a/examples/__outputs__/10_transport-http/transport-http_abort.output.txt b/examples/__outputs__/10_transport-http/transport-http_abort.output.txt index 96e119c62..ed4bd75cd 100644 --- a/examples/__outputs__/10_transport-http/transport-http_abort.output.txt +++ b/examples/__outputs__/10_transport-http/transport-http_abort.output.txt @@ -1,2 +1,2 @@ ---------------------------------------- SHOW ---------------------------------------- -'This operation was aborted' \ No newline at end of file +This operation was aborted \ No newline at end of file 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 344286de1..903ca652f 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': '1727319638284' + 'x-sent-at-time': '1727365576054' }, 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 5291e2552..233b5675a 100644 --- a/examples/__outputs__/20_output/output_envelope.output.txt +++ b/examples/__outputs__/20_output/output_envelope.output.txt @@ -16,7 +16,7 @@ headers: Headers { 'content-type': 'application/graphql-response+json; charset=utf-8', 'content-length': '104', - date: 'Thu, 26 Sep 2024 03:00:38 GMT', + date: 'Thu, 26 Sep 2024 15:46:16 GMT', connection: 'keep-alive', 'keep-alive': 'timeout=5' }, diff --git a/examples/__outputs__/20_output/output_envelope_envelope-error__envelope-error.output.txt b/examples/__outputs__/20_output/output_envelope_envelope-error__envelope-error.output.txt index f17b80add..202ffbdaa 100644 --- a/examples/__outputs__/20_output/output_envelope_envelope-error__envelope-error.output.txt +++ b/examples/__outputs__/20_output/output_envelope_envelope-error__envelope-error.output.txt @@ -5,7 +5,7 @@ at runPipeline (/some/path/to/runPipeline.ts:XX:XX:18) at async Object.run (/some/path/to/main.ts:XX:XX:22) at async run (/some/path/to/client.ts:XX:XX:20) - at async executeRootType (/some/path/to/client.ts:XX:XX:12) + at async executeDocument (/some/path/to/client.ts:XX:XX:12) at async executeRootTypeField (/some/path/to/client.ts:XX:XX:20) at async (/some/path/to/output_envelope_envelope-error__envelope-error.ts:XX:XX:16) { context: { diff --git a/examples/__outputs__/20_output/output_envelope_envelope_error-throw__envelope-error-throw.output.txt b/examples/__outputs__/20_output/output_envelope_envelope_error-throw__envelope-error-throw.output.txt index 613f15351..07e0bdd33 100644 --- a/examples/__outputs__/20_output/output_envelope_envelope_error-throw__envelope-error-throw.output.txt +++ b/examples/__outputs__/20_output/output_envelope_envelope_error-throw__envelope-error-throw.output.txt @@ -7,7 +7,7 @@ ContextualError: There was an error in the extension "anonymous" (use named func at runPipeline (/some/path/to/runPipeline.ts:XX:XX:18) at async Object.run (/some/path/to/main.ts:XX:XX:22) at async run (/some/path/to/client.ts:XX:XX:20) - at async executeRootType (/some/path/to/client.ts:XX:XX:12) + at async executeDocument (/some/path/to/client.ts:XX:XX:12) at async executeRootTypeField (/some/path/to/client.ts:XX:XX:20) at async (/some/path/to/output_envelope_envelope_error-throw__envelope-error-throw.ts:XX:XX:1) { context: { diff --git a/examples/__outputs__/20_output/output_return-error.output.txt b/examples/__outputs__/20_output/output_return-error.output.txt index 071c51d4e..75405dc35 100644 --- a/examples/__outputs__/20_output/output_return-error.output.txt +++ b/examples/__outputs__/20_output/output_return-error.output.txt @@ -3,7 +3,7 @@ ContextualError: There was an error in the extension "anonymous" (use named func at runPipeline (/some/path/to/runPipeline.ts:XX:XX:18) at async Object.run (/some/path/to/main.ts:XX:XX:22) at async run (/some/path/to/client.ts:XX:XX:20) - at async executeRootType (/some/path/to/client.ts:XX:XX:12) + at async executeDocument (/some/path/to/client.ts:XX:XX:12) at async executeRootTypeField (/some/path/to/client.ts:XX:XX:20) at async (/some/path/to/output_return-error.ts:XX:XX:18) { context: { diff --git a/examples/__outputs__/20_output/output_return-error_return-error-execution__return-error-execution.output.txt b/examples/__outputs__/20_output/output_return-error_return-error-execution__return-error-execution.output.txt index fa568874a..7544a1380 100644 --- a/examples/__outputs__/20_output/output_return-error_return-error-execution__return-error-execution.output.txt +++ b/examples/__outputs__/20_output/output_return-error_return-error-execution__return-error-execution.output.txt @@ -3,7 +3,7 @@ ContextualAggregateError: One or more errors in the execution result. at handleOutput (/some/path/to/handleOutput.ts:XX:XX:19) at run (/some/path/to/client.ts:XX:XX:12) at process.processTicksAndRejections (node:internal/process/task_queues:XX:XX) - at async executeRootType (/some/path/to/client.ts:XX:XX:12) + at async executeDocument (/some/path/to/client.ts:XX:XX:12) at async executeRootTypeField (/some/path/to/client.ts:XX:XX:20) at async (/some/path/to/output_return-error_return-error-execution__return-error-execution.ts:XX:XX:16) { context: {}, @@ -40,7 +40,7 @@ ContextualError: There was an error in the extension "anonymous" (use named func at process.processTicksAndRejections (node:internal/process/task_queues:XX:XX) at async Object.run (/some/path/to/main.ts:XX:XX:22) at async run (/some/path/to/client.ts:XX:XX:20) - at async executeRootType (/some/path/to/client.ts:XX:XX:12) + at async executeDocument (/some/path/to/client.ts:XX:XX:12) at async executeRootTypeField (/some/path/to/client.ts:XX:XX:20) at async (/some/path/to/output_return-error_return-error-execution__return-error-execution.ts:XX:XX:3) { context: { diff --git a/examples/__outputs__/60_extension/extension_opentelemetry__opentelemetry.output.txt b/examples/__outputs__/60_extension/extension_opentelemetry__opentelemetry.output.txt index 66d4c9829..485a9e71a 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: '851f3f771b76e4969a2f8c084f85759d', - parentId: 'ebd5237ad56b820c', + traceId: '99a1b00f220469bd559f6fdc09b75cfc', + parentId: 'fb04e4436519eebf', traceState: undefined, name: 'encode', - id: 'ff492c55cf5462ff', + id: 'b9cc31cb6dcef7bb', kind: 0, - timestamp: 1727319638868000, - duration: 1170.584, + timestamp: 1727365576823000, + duration: 586.292, attributes: {}, status: { code: 0 }, events: [], @@ -33,14 +33,14 @@ } }, instrumentationScope: { name: 'graffle', version: undefined, schemaUrl: undefined }, - traceId: '851f3f771b76e4969a2f8c084f85759d', - parentId: 'ebd5237ad56b820c', + traceId: '99a1b00f220469bd559f6fdc09b75cfc', + parentId: 'fb04e4436519eebf', traceState: undefined, name: 'pack', - id: '9174a3424a228e28', + id: 'fb77c65e19244b1f', kind: 0, - timestamp: 1727319638871000, - duration: 36417.291, + timestamp: 1727365576831000, + duration: 19896.75, attributes: {}, status: { code: 0 }, events: [], @@ -57,14 +57,14 @@ } }, instrumentationScope: { name: 'graffle', version: undefined, schemaUrl: undefined }, - traceId: '851f3f771b76e4969a2f8c084f85759d', - parentId: 'ebd5237ad56b820c', + traceId: '99a1b00f220469bd559f6fdc09b75cfc', + parentId: 'fb04e4436519eebf', traceState: undefined, name: 'exchange', - id: '85de30bd471a1d11', + id: '7e3a75386432d606', kind: 0, - timestamp: 1727319638909000, - duration: 24460.084, + timestamp: 1727365576852000, + duration: 29439.625, attributes: {}, status: { code: 0 }, events: [], @@ -81,14 +81,14 @@ } }, instrumentationScope: { name: 'graffle', version: undefined, schemaUrl: undefined }, - traceId: '851f3f771b76e4969a2f8c084f85759d', - parentId: 'ebd5237ad56b820c', + traceId: '99a1b00f220469bd559f6fdc09b75cfc', + parentId: 'fb04e4436519eebf', traceState: undefined, name: 'unpack', - id: '81208c873ce84df5', + id: '6263aef06e4164d0', kind: 0, - timestamp: 1727319638933000, - duration: 1301.541, + timestamp: 1727365576881000, + duration: 1157, attributes: {}, status: { code: 0 }, events: [], @@ -105,14 +105,14 @@ } }, instrumentationScope: { name: 'graffle', version: undefined, schemaUrl: undefined }, - traceId: '851f3f771b76e4969a2f8c084f85759d', - parentId: 'ebd5237ad56b820c', + traceId: '99a1b00f220469bd559f6fdc09b75cfc', + parentId: 'fb04e4436519eebf', traceState: undefined, name: 'decode', - id: '0e084f67d12e45c7', + id: 'f6e875f59111e613', kind: 0, - timestamp: 1727319638935000, - duration: 199.208, + timestamp: 1727365576883000, + duration: 193.042, attributes: {}, status: { code: 0 }, events: [], @@ -129,14 +129,14 @@ } }, instrumentationScope: { name: 'graffle', version: undefined, schemaUrl: undefined }, - traceId: '851f3f771b76e4969a2f8c084f85759d', + traceId: '99a1b00f220469bd559f6fdc09b75cfc', parentId: undefined, traceState: undefined, name: 'request', - id: 'ebd5237ad56b820c', + id: 'fb04e4436519eebf', kind: 0, - timestamp: 1727319638867000, - duration: 68430.791, + timestamp: 1727365576822000, + duration: 61277.208, attributes: {}, status: { code: 0 }, events: [], diff --git a/src/entrypoints/_Print.ts b/src/entrypoints/_Print.ts new file mode 100644 index 000000000..9ed33738e --- /dev/null +++ b/src/entrypoints/_Print.ts @@ -0,0 +1 @@ +export { print as document } from '../layers/4_document/print.js' diff --git a/src/entrypoints/main.ts b/src/entrypoints/main.ts index 6212d530f..fbdecd9e5 100644 --- a/src/entrypoints/main.ts +++ b/src/entrypoints/main.ts @@ -9,3 +9,4 @@ export { type WithInput } from '../layers/6_client/Settings/inputIncrementable/i export * from '../lib/prelude.js' export * from './__Graffle.js' export * as Preset from './_Preset.js' +export * as Print from './_Print.js' diff --git a/src/layers/2_SelectionSet/print.test.ts b/src/layers/2_SelectionSet/print.test.ts index d86c41cfd..4d90b7445 100644 --- a/src/layers/2_SelectionSet/print.test.ts +++ b/src/layers/2_SelectionSet/print.test.ts @@ -5,7 +5,7 @@ import { $Index as schemaIndex } from '../../../tests/_/schema/generated/modules import type * as SelectionSets from '../../../tests/_/schema/generated/modules/SelectionSets.js' import { outputConfigDefault } from '../6_client/Settings/Config.js' import type { Context } from './print.js' -import { resolveRootType } from './print.js' +import { rootType } from './print.js' // eslint-disable-next-line // @ts-ignore @@ -30,7 +30,7 @@ const testEachArgs = [ initialInput: {} as any, }, } - const graphqlDocumentString = resolveRootType(context, schemaIndex[`Root`][`Query`], ss as any) + const graphqlDocumentString = rootType(context, schemaIndex[`Root`][`Query`], ss as any) // Should parse, ensures is syntactically valid graphql document. const document = parse(graphqlDocumentString) const graphqlDocumentStringFormatted = print(document) diff --git a/src/layers/2_SelectionSet/print.ts b/src/layers/2_SelectionSet/print.ts index 055eeb829..e05b87464 100644 --- a/src/layers/2_SelectionSet/print.ts +++ b/src/layers/2_SelectionSet/print.ts @@ -3,95 +3,72 @@ import { assertArray, assertObject, entriesStrict, lowerCaseFirstLetter } from ' import { Schema } from '../1_Schema/__.js' import { readMaybeThunk } from '../1_Schema/core/helpers.js' import type { Config } from '../6_client/Settings/Config.js' +import type { Indicator } from './_indicator.js' import { Directive } from './Directive/__.js' import { isSelectFieldName } from './helpers.js' -import type { Indicator } from './indicator.js' +// import type { Indicator } from './indicator.js' import { isIndicator, isPositiveIndicator } from './indicator.js' import { parseClientOn, toGraphQLOn } from './on.js' import { parseClientFieldItem } from './runtime/FieldItem.js' import { createFieldName } from './runtime/FieldName.js' -import { normalizeAlias } from './types.js' +import { type ArgValue, normalizeAlias, type ObjectLike, type SS } from './types.js' -interface SpecialFields extends Directive.$Fields { - // todo - this requires having the schema at runtime to know which fields to select. - // $scalars?: SelectionSet.Indicator - $?: Args -} - -type Args = { [k: string]: ArgValue } - -type ArgValue = string | boolean | null | number | Args - -export type DocumentObject = { - query?: Record - mutation?: Record -} - -export type GraphQLRootSelection = { query: GraphQLObjectSelection } | { mutation: GraphQLObjectSelection } - -// todo duplicaets the ObjectLike type in other module -export type GraphQLObjectSelection = Record - -export type SS = { - [k: string]: Indicator | SS -} & SpecialFields - -type FieldValue = SS | Indicator +type FieldValue = SS | Indicator.Indicator export interface Context { schemaIndex: Schema.Index config: Config } -export const resolveRootType = ( +export const rootType = ( context: Context, rootObjectDef: Schema.Output.RootType, - selectionSet: GraphQLObjectSelection, + selectionSet: ObjectLike, operationName: string = ``, ) => { const operationTypeName = lowerCaseFirstLetter(rootObjectDef.fields.__typename.type.type) return `${operationTypeName} ${operationName} { ${resolveObjectLikeField(context, rootObjectDef, selectionSet)} }` } -const resolveArgValue = ( +const argValue = ( context: Context, schemaArgTypeMaybeThunk: Schema.Input.Any, - argValue: ArgValue, + value: ArgValue, ): string => { - if (argValue === null) return String(null) // todo could check if index agrees is nullable. + if (value === null) return String(null) // todo could check if index agrees is nullable. const schemaArgType = readMaybeThunk(schemaArgTypeMaybeThunk) switch (schemaArgType.kind) { case `nullable`: - return resolveArgValue(context, schemaArgType.type, argValue) + return argValue(context, schemaArgType.type, value) case `list`: { - assertArray(argValue) - const value = argValue.map(_ => resolveArgValue(context, schemaArgType.type, _ as ArgValue)) - return `[${value.join(`, `)}]` + assertArray(value) + const values = value.map(_ => argValue(context, schemaArgType.type, _ as ArgValue)) + return `[${values.join(`, `)}]` } case `InputObject`: { - assertObject(argValue) - const entries = Object.entries(argValue).map(([argName, argValue]) => { - const schemaArgField = schemaArgType.fields[argName] as Schema.Input.Field | undefined - if (!schemaArgField) throw new Error(`Arg not found: ${argName}`) - return [argName, resolveArgValue(context, schemaArgField.type, argValue)] + assertObject(value) + const entries = Object.entries(value).map(([argName_, argValue_]) => { + const schemaArgField = schemaArgType.fields[argName_] as Schema.Input.Field | undefined + if (!schemaArgField) throw new Error(`Arg not found: ${argName_}`) + return [argName_, argValue(context, schemaArgField.type, argValue_)] }) return `{ ${entries.map(([k, v]) => `${k!}: ${v!}`).join(`, `)} }` } case `Enum`: { - return String(argValue) + return String(value) } case `Scalar`: { // @ts-expect-error fixme - return JSON.stringify(schemaArgType.codec.encode(argValue)) + return JSON.stringify(schemaArgType.codec.encode(value)) } default: throw new Error(`Unsupported arg kind: ${JSON.stringify(schemaArgType)}`) } } -const resolveArgs = (context: Context, schemaField: Schema.SomeField, ss: Indicator | SS) => { +const resolveArgs = (context: Context, schemaField: Schema.SomeField, ss: Indicator.Indicator | SS) => { if (isIndicator(ss)) return `` const { $ } = ss @@ -107,7 +84,7 @@ const resolveArgs = (context: Context, schemaField: Schema.SomeField, ss: Indica argEntries.map(([argFieldName, v]) => { const schemaArgField = schemaArgs.fields[argFieldName] as Schema.Input.Field | undefined if (!schemaArgField) throw new Error(`Arg field ${argFieldName} not found in schema.`) - const valueEncoded = resolveArgValue(context, schemaArgField.type, v) + const valueEncoded = argValue(context, schemaArgField.type, v) return `${argFieldName}: ${valueEncoded}` }).join(`, `) })` @@ -137,7 +114,7 @@ const resolveFieldValue = ( return `${args} ${directives}` } - const selection = Object.fromEntries(selects) as GraphQLObjectSelection + const selection = Object.fromEntries(selects) as ObjectLike // eslint-disable-next-line // @ts-ignore ID error diff --git a/src/layers/2_SelectionSet/types.ts b/src/layers/2_SelectionSet/types.ts index e97fed821..b0f121d3b 100644 --- a/src/layers/2_SelectionSet/types.ts +++ b/src/layers/2_SelectionSet/types.ts @@ -3,10 +3,24 @@ import type { OmitNullableFields, PickNullableFields, Schema } from '../1_Schema import type { Indicator } from './_indicator.js' import type { Directive } from './Directive/__.js' -export type ObjectLike = { - [fieldName: string]: Any +export type ArgValue = string | boolean | null | number | Args_ + +export type Args_ = { [k: string]: ArgValue } + +interface SpecialFields extends Directive.$Fields { + // todo - this requires having the schema at runtime to know which fields to select. + // $scalars?: SelectionSet.Indicator + $?: Args_ } +export type SS = { + [k: string]: Indicator.Indicator | SS +} & SpecialFields + +export type ObjectLike = Record + +export type GraphQLRootSelection = { query: ObjectLike } | { mutation: ObjectLike } + export type Any = AnyExceptAlias | AliasInput export type AnyExceptAlias = ObjectLike | Indicator.Any diff --git a/src/layers/4_document/document.ts b/src/layers/4_document/document.ts index 4085a7ffa..d304ae0cc 100644 --- a/src/layers/4_document/document.ts +++ b/src/layers/4_document/document.ts @@ -1,11 +1,17 @@ +import { type OperationTypeNameAll, RootTypeName, RootTypeNameToOperationName } from '../../lib/graphql.js' import { type OperationType, type RootTypeNameMutation, type RootTypeNameQuery } from '../../lib/graphql.js' import type { FirstNonUnknownNever, IsKeyInObjectOptional, Values } from '../../lib/prelude.js' +import type { SelectionSet } from '../2_SelectionSet/__.js' export type OperationName = string export interface SomeDocumentOperation { [k: string]: object } +export type DocumentObject = { + query?: Record + mutation?: Record +} export interface SomeDocument { mutation?: SomeDocumentOperation @@ -40,3 +46,126 @@ export type GetOperation<$Document extends SomeDocument, $Name extends string> = // @ts-expect-error could be unknown $Document[OperationType.Query][$Name] ]> + +interface OperationNormalized { + name: string + type: OperationTypeNameAll + rootType: RootTypeName + selectionSet: SelectionSet.ObjectLike +} + +export interface DocumentNormalized { + operations: Record + facts: { + hasMultipleOperations: boolean + hasRootType: { + query: boolean + mutation: boolean + subscription: boolean + } + } +} + +export const createDocumentNormalized = (document: DocumentNormalized) => document + +export const createDocumentNormalizedFromRootTypeSelection = ( + rootTypeName: RootTypeName, + selectionSet: SelectionSet.ObjectLike, +) => + createDocumentNormalized({ + operations: { + [defaultOperationName]: { + name: defaultOperationName, + type: RootTypeNameToOperationName[rootTypeName], + rootType: rootTypeName, + selectionSet, + }, + }, + facts: { + hasMultipleOperations: false, + hasRootType: { + query: rootTypeName === RootTypeName.Query, + mutation: rootTypeName === RootTypeName.Mutation, + subscription: rootTypeName === RootTypeName.Subscription, + }, + }, + }) + +export const normalizeOrThrow = (document: DocumentObject): DocumentNormalized => { + const queryOperations = Object.entries(document.query ?? {}).map(( + [name, selectionSet], + ): [name: string, OperationNormalized] => [name, { + name, + type: RootTypeNameToOperationName[RootTypeName.Query], + rootType: RootTypeName.Query, + selectionSet, + }]) + const mutationOperations = Object.entries(document.mutation ?? {}).map(( + [name, selectionSet], + ): [name: string, OperationNormalized] => [name, { + name, + type: RootTypeNameToOperationName[RootTypeName.Mutation], + rootType: RootTypeName.Mutation, + selectionSet, + }]) + const operations = [ + ...queryOperations, + ...mutationOperations, + ] + + // todo test case for this + const conflictingOperationNames = queryOperations.filter(([_, queryOp]) => + mutationOperations.some(([_, mutationOp]) => mutationOp.name === queryOp.name) + ) + + if (conflictingOperationNames.length > 0) { + throw { + errors: [ + new Error(`Document has multiple uses of operation name(s): ${conflictingOperationNames.join(`, `)}.`), + ], + } + } + + const hasMultipleOperations = operations.length > 1 + + const hasNoOperations = operations.length === 0 + + if (hasNoOperations) { + throw { + errors: [new Error(`Document has no operations.`)], + } + } + + return createDocumentNormalized({ + operations: Object.fromEntries(operations), + facts: { + hasMultipleOperations, + hasRootType: { + query: queryOperations.length > 0, + mutation: mutationOperations.length > 0, + subscription: false, + }, + }, + }) +} + +const defaultOperationName = `__default__` + +export const getOperationOrThrow = ( + document: DocumentNormalized, + operationName?: OperationName, +): OperationNormalized => { + if (!operationName) { + if (document.facts.hasMultipleOperations) { + throw new Error(`Must provide operation name if query contains multiple operations.`) + } + // The default operation may be named or not so instead of looking it up by name we rely on the fact that + // there is guaranteed to be exactly one operation in the document based on checks up to this point. + return Object.values(document.operations)[0]! + } + + if (!(operationName in document.operations)) { + throw new Error(`Unknown operation named "${operationName}".`) + } + return document.operations[operationName]! +} diff --git a/src/layers/4_document/print.ts b/src/layers/4_document/print.ts index 91fdd44ba..080aef428 100644 --- a/src/layers/4_document/print.ts +++ b/src/layers/4_document/print.ts @@ -1,39 +1,37 @@ -import { operationTypeNameToRootTypeName, OperationTypes } from '../../lib/graphql.js' +import { parse, print as graphqlPrint } from 'graphql' +import { operationTypeNameToRootTypeName } from '../../lib/graphql.js' import { SelectionSet } from '../2_SelectionSet/__.js' -import type { Context, DocumentObject } from '../2_SelectionSet/print.js' +import type { Context } from '../2_SelectionSet/print.js' +import type { DocumentNormalized } from './document.js' -// todo this is currently unused by graffle internally. Remove? export const print = ( context: Context, - document: DocumentObject, + document: DocumentNormalized, + options?: { + format?: boolean + }, ) => { - const operations = [ - ...(Object.entries(document.query || {}).map(([operationName, selectionSet]) => ({ - operationName, - selectionSet, - operationType: OperationTypes.query, - }))), - ...(Object.entries(document.mutation || {}).map(([operationName, selectionSet]) => ({ - operationName, - selectionSet, - operationType: OperationTypes.mutation, - }))), - ] + const operations = Object.values(document.operations) - return operations.map(({ operationName, selectionSet, operationType }) => { - const rootType = operationTypeNameToRootTypeName[operationType] + const documentString = operations.map(({ name, selectionSet, type }) => { + const rootType = operationTypeNameToRootTypeName[type] const rootTypeDocument = selectionSet const schemaRootType = context.schemaIndex[`Root`][rootType] if (!schemaRootType) throw new Error(`Schema has no ${rootType} root type`) - const documentString = SelectionSet.Print.resolveRootType( + return SelectionSet.Print.rootType( context, schemaRootType, rootTypeDocument, - operationName, + name, ) - - return documentString }).join(`\n\n`) + + let formatted = documentString + if (options?.format) { + formatted = graphqlPrint(parse(documentString)) + } + + return formatted } diff --git a/src/layers/5_core/core.ts b/src/layers/5_core/core.ts index 70a6935a0..8ab8eb6ad 100644 --- a/src/layers/5_core/core.ts +++ b/src/layers/5_core/core.ts @@ -15,8 +15,8 @@ import { import { mergeRequestInit, searchParamsAppendAll } from '../../lib/http.js' import { casesExhausted, getOptionalNullablePropertyOrThrow, throwNull } from '../../lib/prelude.js' import { execute } from '../0_functions/execute.js' -import { SelectionSet } from '../2_SelectionSet/__.js' import * as CustomScalars from '../3_ResultSet/decode.js' +import { Document } from '../4_document/__.js' import type { GraffleExecutionResultVar } from '../6_client/client.js' import type { Config } from '../6_client/Settings/Config.js' import { @@ -41,7 +41,6 @@ export const anyware = Anyware.create({ encode: ({ input }) => { let document: string let variables: StandardScalarVariables | undefined = undefined - let operationName: string | undefined = undefined switch (input.interface) { case `raw`: { @@ -50,18 +49,15 @@ export const anyware = Anyware.create({ : print(input.document) document = documentPrinted variables = input.variables - operationName = input.operationName break } case `typed`: { // todo turn inputs into variables variables = undefined - document = SelectionSet.Print.resolveRootType( - input.context, - getOptionalNullablePropertyOrThrow(input.context.schemaIndex.Root, input.rootTypeName), - // todo fixme - input.selection as any, - ) + document = Document.print({ + config: input.context.config, + schemaIndex: input.context.schemaIndex, + }, input.document) break } default: @@ -75,7 +71,6 @@ export const anyware = Anyware.create({ url: input.schema, query: document, variables, - operationName, } } case `memory`: { @@ -84,7 +79,6 @@ export const anyware = Anyware.create({ schema: input.schema, query: document, variables, - operationName, } } } @@ -233,12 +227,15 @@ export const anyware = Anyware.create({ } } case `typed`: { + const operation = Document.getOperationOrThrow(input.document, input.operationName) // todo optimize // 1. Generate a map of possible custom scalar paths (tree structure) // 2. When traversing the result, skip keys that are not in the map + // console.log(input.context.schemaIndex.Root) + // console.log(getOptionalNullablePropertyOrThrow(input.context.schemaIndex.Root, operation.rootType)) const dataDecoded = CustomScalars.decode( - getOptionalNullablePropertyOrThrow(input.context.schemaIndex.Root, input.rootTypeName), - input.selection, + getOptionalNullablePropertyOrThrow(input.context.schemaIndex.Root, operation.rootType), + operation.selectionSet, input.result.data, ) switch (input.transport) { diff --git a/src/layers/5_core/hooks.ts b/src/layers/5_core/hooks.ts index 3fb590a71..146af6013 100644 --- a/src/layers/5_core/hooks.ts +++ b/src/layers/5_core/hooks.ts @@ -1,8 +1,7 @@ import type { DocumentNode, ExecutionResult, GraphQLSchema } from 'graphql' import type { GraphQLRequestEncoded, GraphQLRequestInput, StandardScalarVariables } from '../../lib/graphql.js' import type { getRequestEncodeSearchParameters, postRequestEncodeBody } from '../../lib/graphqlHTTP.js' -import type { Schema } from '../1_Schema/__.js' -import type { SelectionSet } from '../2_SelectionSet/__.js' +import type { Document } from '../4_document/__.js' import type { InterfaceTypedRequestContext, RequestContext } from '../6_client/client.js' import type { Config } from '../6_client/Settings/Config.js' import type { CoreExchangeGetRequest, CoreExchangePostRequest } from '../6_client/transportHttp/request.js' @@ -12,8 +11,8 @@ type InterfaceInput = | ({ interface: InterfaceTyped context: InterfaceTypedRequestContext - rootTypeName: Schema.RootTypeName - selection: SelectionSet.ObjectLike + document: Document.DocumentNormalized + operationName?: string } & TypedProperties) | ({ interface: InterfaceRaw @@ -45,7 +44,7 @@ export type HookSequence = typeof hookNamesOrderedBySequence export type HookDefEncode<$Config extends Config> = { input: - & InterfaceInput<{}, GraphQLRequestInput> + & InterfaceInput<{ operationName?: string }, GraphQLRequestInput> & TransportInput<$Config, { schema: string | URL }, { schema: GraphQLSchema }> } diff --git a/src/layers/6_client/client.ts b/src/layers/6_client/client.ts index faa0e7ea4..a0d8db283 100644 --- a/src/layers/6_client/client.ts +++ b/src/layers/6_client/client.ts @@ -1,12 +1,13 @@ import { type ExecutionResult, GraphQLSchema } from 'graphql' import type { Errors } from '../../lib/errors/__.js' import type { Fluent } from '../../lib/fluent/__.js' -import { type RootTypeName, RootTypeNameToOperationName } from '../../lib/graphql.js' +import { type RootTypeName } from '../../lib/graphql.js' import { proxyGet } from '../../lib/prelude.js' import type { BaseInput_ } from '../0_functions/types.js' import { Schema } from '../1_Schema/__.js' import { readMaybeThunk } from '../1_Schema/core/helpers.js' -import type { DocumentObject, GraphQLObjectSelection } from '../2_SelectionSet/print.js' +import type { SelectionSet } from '../2_SelectionSet/__.js' +import { Document } from '../4_document/__.js' import type { GlobalRegistry } from '../4_generator/globalRegistry.js' import { Core } from '../5_core/__.js' import { type InterfaceRaw, type TransportHttp } from '../5_core/types.js' @@ -17,6 +18,7 @@ import { anywareProperties, type FnAnyware } from './properties/anyware.js' import type { FnInternal } from './properties/internal.js' import { type FnRetry, retryProperties } from './properties/retry.js' import { type FnWith, withProperties } from './properties/with.js' +import { createMethodDocument } from './requestMethods/document.js' import type { FnRequestMethods } from './requestMethods/requestMethods.js' import { type Config } from './Settings/Config.js' import { type InputStatic } from './Settings/Input.js' @@ -137,24 +139,38 @@ const createWithState = ( */ // const returnMode = input.returnMode ?? `data` as ReturnModeType - const executeRootType = async ( + const executeDocument = async ( context: InterfaceTypedRequestContext, - rootTypeName: RootTypeName, - rootTypeSelectionSet: GraphQLObjectSelection, + document: Document.DocumentNormalized, + operationName?: string, ) => { const transport = state.input.schema instanceof GraphQLSchema ? `memory` : `http` const interface_ = `typed` const anywareInitialInput = { interface: interface_, transport, - selection: rootTypeSelectionSet, - rootTypeName, schema: state.input.schema, context, + document, + operationName, } as Core.Hooks.HookDefEncode['input'] return await run(context, anywareInitialInput) } + const executeRootType = async ( + context: InterfaceTypedRequestContext, + rootTypeName: RootTypeName, + rootTypeSelectionSet: SelectionSet.ObjectLike, + ) => { + return executeDocument( + context, + Document.createDocumentNormalizedFromRootTypeSelection( + rootTypeName, + rootTypeSelectionSet, + ), + ) + } + const executeRootTypeField = async ( context: InterfaceTypedRequestContext, rootTypeName: RootTypeName, @@ -185,7 +201,7 @@ const createWithState = ( const result = await executeRootType(context, rootTypeName, { [rootTypeFieldName]: rootTypeFieldSelectionSet, - } as GraphQLObjectSelection) + } as SelectionSet.ObjectLike) if (result instanceof Error) return result return context.config.output.envelope.enabled @@ -194,14 +210,14 @@ const createWithState = ( : result[rootTypeFieldName] } - const createRootTypeMethods = (context: InterfaceTypedRequestContext, rootTypeName: RootTypeName) => { + const createMethodsRootType = (context: InterfaceTypedRequestContext, rootTypeName: RootTypeName) => { return new Proxy({}, { get: (_, key) => { if (typeof key === `symbol`) throw new Error(`Symbols not supported.`) if (key.startsWith(`$batch`)) { return async (selectionSetOrIndicator: SelectionSetOrIndicator) => - executeRootType(context, rootTypeName, selectionSetOrIndicator as GraphQLObjectSelection) + executeRootType(context, rootTypeName, selectionSetOrIndicator as SelectionSet.ObjectLike) } else { const fieldName = key return (selectionSetOrArgs: SelectionSetOrArgs) => @@ -263,66 +279,9 @@ const createWithState = ( } Object.assign(clientDirect, { - document: (documentObject: DocumentObject) => { - const queryOperationNames = Object.keys(documentObject.query ?? {}) - const mutationOperationNames = Object.keys(documentObject.mutation ?? {}) - const operationNames = [ - ...queryOperationNames, - ...mutationOperationNames, - ] - - // todo test case for this - const conflictingOperationNames = queryOperationNames.filter(_ => mutationOperationNames.includes(_)) - - if (conflictingOperationNames.length > 0) { - throw { - errors: [ - new Error(`Document has multiple uses of operation name(s): ${conflictingOperationNames.join(`, `)}.`), - ], - } - } - - const hasMultipleOperations = operationNames.length > 1 - - const hasNoOperations = operationNames.length === 0 - - if (hasNoOperations) { - throw { - errors: [new Error(`Document has no operations.`)], - } - } - - const defaultOperationName = operationNames[0]! - - const processInput = (maybeOperationName: string) => { - if (!maybeOperationName && hasMultipleOperations) { - throw { - errors: [new Error(`Must provide operation name if query contains multiple operations.`)], - } - } - if (maybeOperationName && !(operationNames.includes(maybeOperationName))) { - throw { - errors: [new Error(`Unknown operation named "${maybeOperationName}".`)], - } - } - const operationName = maybeOperationName ? maybeOperationName : defaultOperationName - const rootTypeName = queryOperationNames.includes(operationName) ? `Query` : `Mutation` - const selection = documentObject[RootTypeNameToOperationName[rootTypeName]]![operationName]! - return { - rootTypeName, - selection, - } as const - } - - return { - run: async (maybeOperationName: string) => { - const { selection, rootTypeName } = processInput(maybeOperationName) - return await executeRootType(typedContext, rootTypeName, selection) - }, - } - }, - query: createRootTypeMethods(typedContext, `Query`), - mutation: createRootTypeMethods(typedContext, `Mutation`), + document: createMethodDocument(typedContext, executeDocument), + query: createMethodsRootType(typedContext, `Query`), + mutation: createMethodsRootType(typedContext, `Mutation`), // todo // subscription: async () => {}, }) diff --git a/src/layers/6_client/requestMethods/document.test.ts b/src/layers/6_client/requestMethods/document.test.ts index fdaf66d00..7aab2aeb7 100644 --- a/src/layers/6_client/requestMethods/document.test.ts +++ b/src/layers/6_client/requestMethods/document.test.ts @@ -2,6 +2,7 @@ import { describe, expect, test } from 'vitest' import { db } from '../../../../tests/_/db.js' import { Graffle } from '../../../../tests/_/schema/generated/__.js' import { schema } from '../../../../tests/_/schema/schema.js' +import type { Errors } from '../../../lib/errors/__.js' // todo test with custom scalars @@ -39,14 +40,25 @@ describe(`document with two queries`, () => { test(`error if no operation name is provided`, async () => { const { run } = withTwo // @ts-expect-error - await expect(run()).rejects.toMatchObject({ - errors: [{ message: `Must provide operation name if query contains multiple operations.` }], + const error = await run().catch((e: unknown) => e) as Errors.ContextualError + // todo it doesn't really make sense that this happens in decode. If the schema didn't reject it than nor should we, + // and if schema will reject it than pre-send validation is what this really is. + expect(error).toMatchObject({ + message: `There was an error in the core implementation of hook "decode".`, + cause: { + message: `Must provide operation name if query contains multiple operations.`, + }, }) }) test(`error if wrong operation name is provided`, async () => { const { run } = withTwo // @ts-expect-error - await expect(run(`boo`)).rejects.toMatchObject({ errors: [{ message: `Unknown operation named "boo".` }] }) + await expect(run(`boo`)).rejects.toMatchObject({ + message: `There was an error in the core implementation of hook "decode".`, + cause: { + message: `Unknown operation named "boo".`, + }, + }) }) test(`error if no operations provided`, () => { expect(() => { diff --git a/src/layers/6_client/requestMethods/document.ts b/src/layers/6_client/requestMethods/document.ts index 80d4bb0fe..c7e734f73 100644 --- a/src/layers/6_client/requestMethods/document.ts +++ b/src/layers/6_client/requestMethods/document.ts @@ -2,7 +2,8 @@ import type { UnionToTuple } from 'type-fest' import type { IsTupleMultiple } from '../../../lib/prelude.js' import type { Schema } from '../../1_Schema/__.js' import type { ResultSet } from '../../3_ResultSet/__.js' -import type { Document } from '../../4_document/__.js' +import { Document } from '../../4_document/__.js' +import type { InterfaceTypedRequestContext } from '../client.js' import type { ResolveOutputReturnRootType } from '../handleOutput.js' import type { AddTypenameToSelectedRootTypeResultFields, Config } from '../Settings/Config.js' @@ -37,7 +38,6 @@ export type DocumentRunner< // todo maybe bring back these validations, but need to understand the perf impact -// // dprint-ignore // export type Document<$Index extends Schema.Index> = // { // [name: string]: @@ -53,7 +53,6 @@ export type DocumentRunner< // > // } -// // dprint-ignore // export type ValidateDocumentOperationNames<$Document> = // // This initial condition checks that the document is not already in an error state. // // Namely from for example { x: { mutation: { ... }}} where the schema has no mutations. @@ -65,3 +64,13 @@ export type DocumentRunner< // : keyof { [K in keyof $Document & string as Schema.Named.NameParse extends never ? K : never]: K } extends never // ? $Document // : TSError<'ValidateDocumentOperationNames', `One or more Invalid operation name in document: ${keyof { [K in keyof $Document & string as Schema.Named.NameParse extends never ? K : never]: K }}`> + +export const createMethodDocument = + (context: InterfaceTypedRequestContext, executeDocument: any) => (document: Document.DocumentObject) => { + const documentNormalized = Document.normalizeOrThrow(document) + return { + run: async (maybeOperationName?: string) => { + return await executeDocument(context, documentNormalized, maybeOperationName) + }, + } + } diff --git a/src/lib/anyware/runHook.ts b/src/lib/anyware/runHook.ts index 76d306e5e..555ccf08a 100644 --- a/src/lib/anyware/runHook.ts +++ b/src/lib/anyware/runHook.ts @@ -252,7 +252,12 @@ export const runHook = async ( case `hookInvokedButThrew`: debugExtension(`hook error`) // todo rename source to "hook" - done({ type: `error`, hookName: name, source: `implementation`, error: errorFromMaybeError(result) }) + done({ + type: `error`, + hookName: name, + source: `implementation`, + error: errorFromMaybeError(result), + }) return default: throw casesExhausted(branch) diff --git a/src/lib/graphql.ts b/src/lib/graphql.ts index eb3fcf82c..9ff825942 100644 --- a/src/lib/graphql.ts +++ b/src/lib/graphql.ts @@ -363,7 +363,8 @@ export const parseGraphQLOperationType = (request: GraphQLRequestEncoded): Opera line, operationType: match[0] as OperationTypeNameAll, } - }).filter(Boolean) + }).filter(_ => _ !== null) + // console.log(definedOperations) // Handle obviously invalid cases that are zero cost to compute. @@ -385,7 +386,7 @@ export const parseGraphQLOperationType = (request: GraphQLRequestEncoded): Opera // Continue to the full search. const definedOperationToAnalyze = operationName - ? definedOperations.find(o => o?.line.includes(operationName)) + ? definedOperations.find(o => o.line.includes(operationName)) : definedOperations[0] // Invalid: The given operation name does not show up in the document. diff --git a/website/.vitepress/theme/content.css b/website/.vitepress/theme/content.css new file mode 100644 index 000000000..e7231d912 --- /dev/null +++ b/website/.vitepress/theme/content.css @@ -0,0 +1,41 @@ +/* Improve the page outline aside. "On this page" is redundant IMO. */ + +.VPDocAsideOutline .content { + /* Because we can only hide, not remove (none) the title, it appears as an extended top boarder, just remove the border completely to fix that. */ + border: none; +} + +.outline-title { + /* If we make it display:none then we break the active border indicator alignment. So just visually hide. */ + opacity: 0; + margin-top: -1.6rem; +} + +.VPContent h6 { + opacity: 0.6; + font-size: 0.7rem; + /* text-transform: uppercase; */ + /* font-weight: 900; */ +} + +.VPContent h6 a { + opacity: 0.6; + /* font-size: 0.6rem; */ + /* text-transform: uppercase; */ + font-weight: 900; +} + +.VPContent h6 a:hover { + opacity: 1; +} + +/* Improve vertical alignment of badges. Mostly noticeable with big titles.*/ + +.vp-doc h1 > .VPBadge { + vertical-align: middle; + margin-top: auto; + text-transform: uppercase; + font-weight: bold; + letter-spacing: 0.025em; + +} diff --git a/website/.vitepress/theme/custom.css b/website/.vitepress/theme/custom.css index b0cacbe51..fb312eb9d 100644 --- a/website/.vitepress/theme/custom.css +++ b/website/.vitepress/theme/custom.css @@ -1,87 +1,3 @@ -/* The following styles fix dark theme styling for floating-vue */ - -.v-popper--theme-dropdown .v-popper__inner { - box-shadow: none; - border-radius: 3px; -} - -.dark .v-popper--theme-dropdown .v-popper__inner { - background-color: hsl(0, 0%, 8%); - border-color: rgb(33, 33, 33); -} - -.dark .v-popper--theme-dropdown .v-popper__arrow-inner { - border-bottom-color: hsl(0,0%,8%); -} - -.dark .v-popper--theme-dropdown .v-popper__arrow-outer { - /* border-color: black; */ - border-color: rgb(33, 33, 33); -} - -/* Improve vertical alignment of badges. Mostly noticeable with big titles.*/ - -.vp-doc h1 > .VPBadge { - vertical-align: middle; - margin-top: auto; - text-transform: uppercase; - font-weight: bold; - letter-spacing: 0.025em; - -} - -/* Improve the page outline aside. "On this page" is redundant IMO. */ - -.VPDocAsideOutline .content { - /* Because we can only hide, not remove (none) the title, it appears as an extended top boarder, just remove the border completely to fix that. */ - border: none; -} - -.outline-title { - /* If we make it display:none then we break the active border indicator alignment. So just visually hide. */ - opacity: 0; - margin-top: -1.6rem; -} - -.VPContent h6 { - opacity: 0.6; - font-size: 0.7rem; - /* text-transform: uppercase; */ - /* font-weight: 900; */ -} - -.VPContent h6 a { - opacity: 0.6; - /* font-size: 0.6rem; */ - /* text-transform: uppercase; */ - font-weight: 900; -} - -.VPContent h6 a:hover { - opacity: 1; -} - -/* Improve Code Blocks */ - -:root { - --vp-code-line-highlight-color: hsla(57.82, 100%, 63%, 0.37); -} - -.dark { - --vp-code-line-highlight-color: hsla(208.91, 100%, 84.25%, 0.05); -} - -.twoslash-highlighted { - --twoslash-highlighted-bg: hsla(58, 100%, 63%, 0.408); - --twoslash-highlighted-border: hsla(0,0%,0%,0); - padding: 1px 2px 3px 2px; -} - -.dark .twoslash-highlighted { - --twoslash-highlighted-bg: hsla(257, 85%, 51%, 0.38); -} - - /* Site wide banner */ :root { @@ -119,200 +35,3 @@ #graffle-warning-message a { text-decoration: underline; } - -/* Example Links */ -.ExampleLinks { - opacity: 0.6; - font-size: 0.7rem; -} - -.ExampleLinksSeparator { - - display: inline-block; - margin: auto 0.25rem; -} - -.ExampleLinksSeparator:before { - content: '•' -} - -.ExampleLinksTitleSeparator { - display: inline-block; - margin: auto 0.25rem; -} - -/* Home Page Hero Logo */ - -@keyframes rainbow-wave { - 0% { - /* background-position: 0% 50%; */ - filter: hue-rotate(0deg); - } - 50% { - /* background-position: 100% 50%; */ - filter: hue-rotate(180deg); - } - 100% { - /* background-position: 0% 50%; */ - filter: hue-rotate(360deg); - } -} - -@keyframes rotate-conic { - 0% { - transform: rotate(0deg); - } - 100% { - transform: rotate(360deg); - } -} - -:root { - --vp-home-hero-img-border-radius: 33px; -} - - - -.VPHomeHero .image-bg { - animation: rainbow-wave 30s linear infinite; - background-image: - linear-gradient(45deg, - #006994 0%, #0099cc 10%, #66ccff 20%, - #339966 30%, #33cccc 40%, #66ffff 50%, - #006994 60%, #0099cc 70%, #66ccff 80%, - #339966 90%, #33cccc 100% - ), - conic-gradient( - from 0deg at 0% 0%, - rgba(0, 105, 148, 0.2) 0deg, - rgba(102, 204, 255, 0.2) 90deg, - rgba(51, 153, 102, 0.2) 180deg, - rgba(51, 204, 204, 0.2) 270deg, - rgba(102, 255, 255, 0.2) 320deg, - rgba(0, 105, 148, 0.2) 360deg - ), - radial-gradient(circle at 50% 50%, - rgba(255,255,255,0.1) 0%, transparent 50% - ); - background-size: 200% 200%, 100% 100%, 200% 200%; - background-position: 0% 50%; - background-blend-mode: overlay, soft-light, overlay; - border-radius: calc(var(--vp-home-hero-img-border-radius) + 2px); - overflow: hidden; -} - -.VPHomeHero .image-bg::before { - content: ''; - position: absolute; - top: -50%; - left: -50%; - right: -50%; - bottom: -50%; - background: inherit; - background-blend-mode: inherit; - filter: inherit; - animation: rotate-conic 30s linear infinite; - z-index: -1; -} - -.dark .VPHomeHero img { - filter: invert(0) opacity(0.75); -} - -.VPHomeHero img { - border-radius: var(--vp-home-hero-img-border-radius); - filter: invert(1) opacity(0.8); - position: relative; - z-index: 1; -} - -@media (min-width: 767px) and (max-width: 960px) { -:root { - --vp-home-hero-img-border-radius: 28px; - } - .VPHomeHero .image-bg { - border-radius: calc(var(--vp-home-hero-img-border-radius) + 2px); - } - .VPHomeHero img { - border-radius: calc(var(--vp-home-hero-img-border-radius) + 0px); - } -} - -@media (max-width: 767px) { - :root { - --vp-home-hero-img-border-radius: 20px; - } - .VPHomeHero .image-bg { - border-radius: calc(var(--vp-home-hero-img-border-radius) + 2px); - } - .VPHomeHero img { - border-radius: calc(var(--vp-home-hero-img-border-radius) + 0px); - } -} - -/* Examples */ - -details a { - opacity:0.25; -} - -details a:before { - content: '⤤ '; - font-size: 1.25rem; -} - -details { - padding: 0!important; - background: none!important; -} - -.ExampleSnippet > div:not(:last-of-type), -details > div:not(:last-of-type) { - margin-bottom:1rem!important; -} - - - -details summary { - padding: 0.5rem 0; - margin: 0!important; -} - -details .plugin-tabs { - margin-top: 0!important; - background: none!important; -} - -details .plugin-tabs--tab-list { - padding: 0!important; - margin-bottom: 1rem; -} - -details .plugin-tabs--tab-list button:first-child { - margin-left: -10px; -} - -details .plugin-tabs--content { - padding: 0!important; -} - - - -details .plugin-tabs--content > div:not(:last-of-type) { - margin-bottom:1rem!important; -} - -.icon { - filter: sepia(0.75); - background:hsla(0,0%,0%,0.025)!important; -} - -.dark .icon { - background:hsla(0,0%,100%,0.025)!important; -} - -/* Sponsorship Button */ - -:root { - --vp-c-sponsor: var(--vp-c-brand-3); -} diff --git a/website/.vitepress/theme/examples.css b/website/.vitepress/theme/examples.css new file mode 100644 index 000000000..5cf231bf5 --- /dev/null +++ b/website/.vitepress/theme/examples.css @@ -0,0 +1,116 @@ +/* Examples */ + +/* Revealable Inline Code Examples */ + +details a { + opacity:0.25; +} + +details a:before { + content: '⤤ '; + font-size: 1.25rem; +} + +details { + padding: 0!important; + background: none!important; +} + +.ExampleSnippet > div:not(:last-of-type), +details > div:not(:last-of-type) { + margin-bottom:1rem!important; +} + +details summary { + padding: 0.5rem 0; + margin: 0!important; +} + +details .plugin-tabs { + margin-top: 0!important; + background: none!important; +} + +details .plugin-tabs--tab-list { + padding: 0!important; + margin-bottom: 1rem; +} + +details .plugin-tabs--tab-list button:first-child { + margin-left: -10px; +} + +details .plugin-tabs--content { + padding: 0!important; +} + + + +details .plugin-tabs--content > div:not(:last-of-type) { + margin-bottom:1rem!important; +} + +/* Link Roundup To Examples */ + +.ExampleLinks { + opacity: 0.6; + font-size: 0.7rem; +} + +.ExampleLinksSeparator { + + display: inline-block; + margin: auto 0.25rem; +} + +.ExampleLinksSeparator:before { + content: '•' +} + +.ExampleLinksTitleSeparator { + display: inline-block; + margin: auto 0.25rem; +} + +/* The following styles fix dark theme styling for floating-vue popups in twoslash */ + +.v-popper--theme-dropdown .v-popper__inner { + box-shadow: none; + border-radius: 3px; +} + +.dark .v-popper--theme-dropdown .v-popper__inner { + background-color: hsl(0, 0%, 8%); + border-color: rgb(33, 33, 33); +} + +.dark .v-popper--theme-dropdown .v-popper__arrow-inner { + border-bottom-color: hsl(0,0%,8%); +} + +.dark .v-popper--theme-dropdown .v-popper__arrow-outer { + /* border-color: black; */ + border-color: rgb(33, 33, 33); +} + +/* Improve Code Blocks */ + +:root { + /* --vp-code-line-highlight-color: hsla(57.82, 100%, 63%, 0.37); */ + --vp-code-line-highlight-color: hsla(58, 100%, 63%, 0.408) +} + +.dark { + /* --vp-code-line-highlight-color: hsla(208.91, 100%, 84.25%, 0.05); */ + --vp-code-line-highlight-color: hsla(257, 85%, 51%, 0.38); +} + +.twoslash-highlighted { + --twoslash-highlighted-bg: hsla(58, 100%, 63%, 0.408); + --twoslash-highlighted-border: hsla(0,0%,0%,0); + padding: 1px 2px 3px 2px; +} + +.dark .twoslash-highlighted { + --twoslash-highlighted-bg: hsla(257, 85%, 51%, 0.38); +} diff --git a/website/.vitepress/theme/home.css b/website/.vitepress/theme/home.css new file mode 100644 index 000000000..07a595b40 --- /dev/null +++ b/website/.vitepress/theme/home.css @@ -0,0 +1,123 @@ +/* Feature Blocks */ + +.icon { + filter: sepia(0.75); + background:hsla(0,0%,0%,0.025)!important; +} + +.dark .icon { + background:hsla(0,0%,100%,0.025)!important; +} + +/* Sponsorship Button */ + +:root { + --vp-c-sponsor: var(--vp-c-brand-3); +} + +/* Logo */ + +@keyframes rainbow-wave { + 0% { + /* background-position: 0% 50%; */ + filter: hue-rotate(0deg); + } + 50% { + /* background-position: 100% 50%; */ + filter: hue-rotate(180deg); + } + 100% { + /* background-position: 0% 50%; */ + filter: hue-rotate(360deg); + } +} + +@keyframes rotate-conic { + 0% { + transform: rotate(0deg); + } + 100% { + transform: rotate(360deg); + } +} + +:root { + --vp-home-hero-img-border-radius: 33px; +} + +.VPHomeHero .image-bg { + animation: rainbow-wave 30s linear infinite; + background-image: + linear-gradient(45deg, + #006994 0%, #0099cc 10%, #66ccff 20%, + #339966 30%, #33cccc 40%, #66ffff 50%, + #006994 60%, #0099cc 70%, #66ccff 80%, + #339966 90%, #33cccc 100% + ), + conic-gradient( + from 0deg at 0% 0%, + rgba(0, 105, 148, 0.2) 0deg, + rgba(102, 204, 255, 0.2) 90deg, + rgba(51, 153, 102, 0.2) 180deg, + rgba(51, 204, 204, 0.2) 270deg, + rgba(102, 255, 255, 0.2) 320deg, + rgba(0, 105, 148, 0.2) 360deg + ), + radial-gradient(circle at 50% 50%, + rgba(255,255,255,0.1) 0%, transparent 50% + ); + background-size: 200% 200%, 100% 100%, 200% 200%; + background-position: 0% 50%; + background-blend-mode: overlay, soft-light, overlay; + border-radius: calc(var(--vp-home-hero-img-border-radius) + 2px); + overflow: hidden; +} + +.VPHomeHero .image-bg::before { + content: ''; + position: absolute; + top: -50%; + left: -50%; + right: -50%; + bottom: -50%; + background: inherit; + background-blend-mode: inherit; + filter: inherit; + animation: rotate-conic 30s linear infinite; + z-index: -1; +} + +.dark .VPHomeHero img { + filter: invert(0) opacity(0.75); +} + +.VPHomeHero img { + border-radius: var(--vp-home-hero-img-border-radius); + filter: invert(1) opacity(0.8); + position: relative; + z-index: 1; +} + +@media (min-width: 767px) and (max-width: 960px) { +:root { + --vp-home-hero-img-border-radius: 28px; + } + .VPHomeHero .image-bg { + border-radius: calc(var(--vp-home-hero-img-border-radius) + 2px); + } + .VPHomeHero img { + border-radius: calc(var(--vp-home-hero-img-border-radius) + 0px); + } +} + +@media (max-width: 767px) { + :root { + --vp-home-hero-img-border-radius: 20px; + } + .VPHomeHero .image-bg { + border-radius: calc(var(--vp-home-hero-img-border-radius) + 2px); + } + .VPHomeHero img { + border-radius: calc(var(--vp-home-hero-img-border-radius) + 0px); + } +} diff --git a/website/.vitepress/theme/index.ts b/website/.vitepress/theme/index.ts index 8058d6be8..a4b6d7510 100644 --- a/website/.vitepress/theme/index.ts +++ b/website/.vitepress/theme/index.ts @@ -2,6 +2,9 @@ import type { EnhanceAppContext } from 'vitepress' import { enhanceAppWithTabs } from 'vitepress-plugin-tabs/client' import DefaultTheme from 'vitepress/theme' import './custom.css' +import './home.css' +import './examples.css' +import './content.css' import GeneratedClientBadge from './components/GeneratedClientBadge.vue' import MyLayout from './components/MyLayout.vue' diff --git a/website/content/_snippets/examples/extension/opentelemetry.detail.md b/website/content/_snippets/examples/extension/opentelemetry.detail.md index aac79c0d3..e2af1bd7a 100644 --- a/website/content/_snippets/examples/extension/opentelemetry.detail.md +++ b/website/content/_snippets/examples/extension/opentelemetry.detail.md @@ -38,14 +38,14 @@ console.log(data) } }, instrumentationScope: { name: 'graffle', version: undefined, schemaUrl: undefined }, - traceId: '851f3f771b76e4969a2f8c084f85759d', - parentId: 'ebd5237ad56b820c', + traceId: '99a1b00f220469bd559f6fdc09b75cfc', + parentId: 'fb04e4436519eebf', traceState: undefined, name: 'encode', - id: 'ff492c55cf5462ff', + id: 'b9cc31cb6dcef7bb', kind: 0, - timestamp: 1727319638868000, - duration: 1170.584, + timestamp: 1727365576823000, + duration: 586.292, attributes: {}, status: { code: 0 }, events: [], @@ -65,14 +65,14 @@ console.log(data) } }, instrumentationScope: { name: 'graffle', version: undefined, schemaUrl: undefined }, - traceId: '851f3f771b76e4969a2f8c084f85759d', - parentId: 'ebd5237ad56b820c', + traceId: '99a1b00f220469bd559f6fdc09b75cfc', + parentId: 'fb04e4436519eebf', traceState: undefined, name: 'pack', - id: '9174a3424a228e28', + id: 'fb77c65e19244b1f', kind: 0, - timestamp: 1727319638871000, - duration: 36417.291, + timestamp: 1727365576831000, + duration: 19896.75, attributes: {}, status: { code: 0 }, events: [], @@ -92,14 +92,14 @@ console.log(data) } }, instrumentationScope: { name: 'graffle', version: undefined, schemaUrl: undefined }, - traceId: '851f3f771b76e4969a2f8c084f85759d', - parentId: 'ebd5237ad56b820c', + traceId: '99a1b00f220469bd559f6fdc09b75cfc', + parentId: 'fb04e4436519eebf', traceState: undefined, name: 'exchange', - id: '85de30bd471a1d11', + id: '7e3a75386432d606', kind: 0, - timestamp: 1727319638909000, - duration: 24460.084, + timestamp: 1727365576852000, + duration: 29439.625, attributes: {}, status: { code: 0 }, events: [], @@ -119,14 +119,14 @@ console.log(data) } }, instrumentationScope: { name: 'graffle', version: undefined, schemaUrl: undefined }, - traceId: '851f3f771b76e4969a2f8c084f85759d', - parentId: 'ebd5237ad56b820c', + traceId: '99a1b00f220469bd559f6fdc09b75cfc', + parentId: 'fb04e4436519eebf', traceState: undefined, name: 'unpack', - id: '81208c873ce84df5', + id: '6263aef06e4164d0', kind: 0, - timestamp: 1727319638933000, - duration: 1301.541, + timestamp: 1727365576881000, + duration: 1157, attributes: {}, status: { code: 0 }, events: [], @@ -146,14 +146,14 @@ console.log(data) } }, instrumentationScope: { name: 'graffle', version: undefined, schemaUrl: undefined }, - traceId: '851f3f771b76e4969a2f8c084f85759d', - parentId: 'ebd5237ad56b820c', + traceId: '99a1b00f220469bd559f6fdc09b75cfc', + parentId: 'fb04e4436519eebf', traceState: undefined, name: 'decode', - id: '0e084f67d12e45c7', + id: 'f6e875f59111e613', kind: 0, - timestamp: 1727319638935000, - duration: 199.208, + timestamp: 1727365576883000, + duration: 193.042, attributes: {}, status: { code: 0 }, events: [], @@ -173,14 +173,14 @@ console.log(data) } }, instrumentationScope: { name: 'graffle', version: undefined, schemaUrl: undefined }, - traceId: '851f3f771b76e4969a2f8c084f85759d', + traceId: '99a1b00f220469bd559f6fdc09b75cfc', parentId: undefined, traceState: undefined, name: 'request', - id: 'ebd5237ad56b820c', + id: 'fb04e4436519eebf', kind: 0, - timestamp: 1727319638867000, - duration: 68430.791, + timestamp: 1727365576822000, + duration: 61277.208, attributes: {}, status: { code: 0 }, events: [], diff --git a/website/content/_snippets/examples/extension/opentelemetry.md b/website/content/_snippets/examples/extension/opentelemetry.md index a077f3fa2..e0f04bf97 100644 --- a/website/content/_snippets/examples/extension/opentelemetry.md +++ b/website/content/_snippets/examples/extension/opentelemetry.md @@ -36,14 +36,14 @@ console.log(data) } }, instrumentationScope: { name: 'graffle', version: undefined, schemaUrl: undefined }, - traceId: '851f3f771b76e4969a2f8c084f85759d', - parentId: 'ebd5237ad56b820c', + traceId: '99a1b00f220469bd559f6fdc09b75cfc', + parentId: 'fb04e4436519eebf', traceState: undefined, name: 'encode', - id: 'ff492c55cf5462ff', + id: 'b9cc31cb6dcef7bb', kind: 0, - timestamp: 1727319638868000, - duration: 1170.584, + timestamp: 1727365576823000, + duration: 586.292, attributes: {}, status: { code: 0 }, events: [], @@ -63,14 +63,14 @@ console.log(data) } }, instrumentationScope: { name: 'graffle', version: undefined, schemaUrl: undefined }, - traceId: '851f3f771b76e4969a2f8c084f85759d', - parentId: 'ebd5237ad56b820c', + traceId: '99a1b00f220469bd559f6fdc09b75cfc', + parentId: 'fb04e4436519eebf', traceState: undefined, name: 'pack', - id: '9174a3424a228e28', + id: 'fb77c65e19244b1f', kind: 0, - timestamp: 1727319638871000, - duration: 36417.291, + timestamp: 1727365576831000, + duration: 19896.75, attributes: {}, status: { code: 0 }, events: [], @@ -90,14 +90,14 @@ console.log(data) } }, instrumentationScope: { name: 'graffle', version: undefined, schemaUrl: undefined }, - traceId: '851f3f771b76e4969a2f8c084f85759d', - parentId: 'ebd5237ad56b820c', + traceId: '99a1b00f220469bd559f6fdc09b75cfc', + parentId: 'fb04e4436519eebf', traceState: undefined, name: 'exchange', - id: '85de30bd471a1d11', + id: '7e3a75386432d606', kind: 0, - timestamp: 1727319638909000, - duration: 24460.084, + timestamp: 1727365576852000, + duration: 29439.625, attributes: {}, status: { code: 0 }, events: [], @@ -117,14 +117,14 @@ console.log(data) } }, instrumentationScope: { name: 'graffle', version: undefined, schemaUrl: undefined }, - traceId: '851f3f771b76e4969a2f8c084f85759d', - parentId: 'ebd5237ad56b820c', + traceId: '99a1b00f220469bd559f6fdc09b75cfc', + parentId: 'fb04e4436519eebf', traceState: undefined, name: 'unpack', - id: '81208c873ce84df5', + id: '6263aef06e4164d0', kind: 0, - timestamp: 1727319638933000, - duration: 1301.541, + timestamp: 1727365576881000, + duration: 1157, attributes: {}, status: { code: 0 }, events: [], @@ -144,14 +144,14 @@ console.log(data) } }, instrumentationScope: { name: 'graffle', version: undefined, schemaUrl: undefined }, - traceId: '851f3f771b76e4969a2f8c084f85759d', - parentId: 'ebd5237ad56b820c', + traceId: '99a1b00f220469bd559f6fdc09b75cfc', + parentId: 'fb04e4436519eebf', traceState: undefined, name: 'decode', - id: '0e084f67d12e45c7', + id: 'f6e875f59111e613', kind: 0, - timestamp: 1727319638935000, - duration: 199.208, + timestamp: 1727365576883000, + duration: 193.042, attributes: {}, status: { code: 0 }, events: [], @@ -171,14 +171,14 @@ console.log(data) } }, instrumentationScope: { name: 'graffle', version: undefined, schemaUrl: undefined }, - traceId: '851f3f771b76e4969a2f8c084f85759d', + traceId: '99a1b00f220469bd559f6fdc09b75cfc', parentId: undefined, traceState: undefined, name: 'request', - id: 'ebd5237ad56b820c', + id: 'fb04e4436519eebf', kind: 0, - timestamp: 1727319638867000, - duration: 68430.791, + timestamp: 1727365576822000, + duration: 61277.208, attributes: {}, status: { code: 0 }, events: [], diff --git a/website/content/_snippets/examples/generated/arguments.detail.md b/website/content/_snippets/examples/generated/arguments.detail.md index 2b1fc638b..9386a74ad 100644 --- a/website/content/_snippets/examples/generated/arguments.detail.md +++ b/website/content/_snippets/examples/generated/arguments.detail.md @@ -11,7 +11,7 @@ import { Pokemon } from './pokemon/__.js' const atlas = Pokemon.create() const pokemons = await atlas.query.pokemons({ - $: { filter: { name: { in: [`Pikachu`, `Charizard`] } } }, + $: { filter: { name: { in: [`Pikachu`, `Charizard`] } } }, // [!code highlight] name: true, trainer: { name: true }, }) diff --git a/website/content/_snippets/examples/generated/arguments.md b/website/content/_snippets/examples/generated/arguments.md index 49797f217..239dd3a1e 100644 --- a/website/content/_snippets/examples/generated/arguments.md +++ b/website/content/_snippets/examples/generated/arguments.md @@ -9,7 +9,7 @@ import { Pokemon } from './pokemon/__.js' const atlas = Pokemon.create() const pokemons = await atlas.query.pokemons({ - $: { filter: { name: { in: [`Pikachu`, `Charizard`] } } }, + $: { filter: { name: { in: [`Pikachu`, `Charizard`] } } }, // [!code highlight] name: true, trainer: { name: true }, }) diff --git a/website/content/_snippets/examples/output/envelope-error-throw.detail.md b/website/content/_snippets/examples/output/envelope-error-throw.detail.md index ed4dfb55a..c6e354c42 100644 --- a/website/content/_snippets/examples/output/envelope-error-throw.detail.md +++ b/website/content/_snippets/examples/output/envelope-error-throw.detail.md @@ -39,7 +39,7 @@ ContextualError: There was an error in the extension "anonymous" (use named func at runPipeline (/some/path/to/runPipeline.ts:XX:XX:18) at async Object.run (/some/path/to/main.ts:XX:XX:22) at async run (/some/path/to/client.ts:XX:XX:20) - at async executeRootType (/some/path/to/client.ts:XX:XX:12) + at async executeDocument (/some/path/to/client.ts:XX:XX:12) at async executeRootTypeField (/some/path/to/client.ts:XX:XX:20) at async (/some/path/to/output_envelope_envelope_error-throw__envelope-error-throw.ts:XX:XX:1) { context: { diff --git a/website/content/_snippets/examples/output/envelope-error-throw.md b/website/content/_snippets/examples/output/envelope-error-throw.md index a0f1810ec..c5d726b07 100644 --- a/website/content/_snippets/examples/output/envelope-error-throw.md +++ b/website/content/_snippets/examples/output/envelope-error-throw.md @@ -37,7 +37,7 @@ ContextualError: There was an error in the extension "anonymous" (use named func at runPipeline (/some/path/to/runPipeline.ts:XX:XX:18) at async Object.run (/some/path/to/main.ts:XX:XX:22) at async run (/some/path/to/client.ts:XX:XX:20) - at async executeRootType (/some/path/to/client.ts:XX:XX:12) + at async executeDocument (/some/path/to/client.ts:XX:XX:12) at async executeRootTypeField (/some/path/to/client.ts:XX:XX:20) at async (/some/path/to/output_envelope_envelope_error-throw__envelope-error-throw.ts:XX:XX:1) { context: { diff --git a/website/content/_snippets/examples/output/envelope-error.detail.md b/website/content/_snippets/examples/output/envelope-error.detail.md index 3c7189d16..b498f7e60 100644 --- a/website/content/_snippets/examples/output/envelope-error.detail.md +++ b/website/content/_snippets/examples/output/envelope-error.detail.md @@ -39,7 +39,7 @@ console.log(result) at runPipeline (/some/path/to/runPipeline.ts:XX:XX:18) at async Object.run (/some/path/to/main.ts:XX:XX:22) at async run (/some/path/to/client.ts:XX:XX:20) - at async executeRootType (/some/path/to/client.ts:XX:XX:12) + at async executeDocument (/some/path/to/client.ts:XX:XX:12) at async executeRootTypeField (/some/path/to/client.ts:XX:XX:20) at async (/some/path/to/output_envelope_envelope-error__envelope-error.ts:XX:XX:16) { context: { diff --git a/website/content/_snippets/examples/output/envelope-error.md b/website/content/_snippets/examples/output/envelope-error.md index f900176de..0af8a680d 100644 --- a/website/content/_snippets/examples/output/envelope-error.md +++ b/website/content/_snippets/examples/output/envelope-error.md @@ -37,7 +37,7 @@ console.log(result) at runPipeline (/some/path/to/runPipeline.ts:XX:XX:18) at async Object.run (/some/path/to/main.ts:XX:XX:22) at async run (/some/path/to/client.ts:XX:XX:20) - at async executeRootType (/some/path/to/client.ts:XX:XX:12) + at async executeDocument (/some/path/to/client.ts:XX:XX:12) at async executeRootTypeField (/some/path/to/client.ts:XX:XX:20) at async (/some/path/to/output_envelope_envelope-error__envelope-error.ts:XX:XX:16) { context: { diff --git a/website/content/_snippets/examples/output/envelope.detail.md b/website/content/_snippets/examples/output/envelope.detail.md index 8ef1dfe84..f315fced4 100644 --- a/website/content/_snippets/examples/output/envelope.detail.md +++ b/website/content/_snippets/examples/output/envelope.detail.md @@ -39,7 +39,7 @@ console.log(result) headers: Headers { 'content-type': 'application/graphql-response+json; charset=utf-8', 'content-length': '104', - date: 'Thu, 26 Sep 2024 03:00:38 GMT', + date: 'Thu, 26 Sep 2024 15:46:16 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 887910ba1..ddd0322b3 100644 --- a/website/content/_snippets/examples/output/envelope.md +++ b/website/content/_snippets/examples/output/envelope.md @@ -37,7 +37,7 @@ console.log(result) headers: Headers { 'content-type': 'application/graphql-response+json; charset=utf-8', 'content-length': '104', - date: 'Thu, 26 Sep 2024 03:00:38 GMT', + date: 'Thu, 26 Sep 2024 15:46:16 GMT', connection: 'keep-alive', 'keep-alive': 'timeout=5' }, diff --git a/website/content/_snippets/examples/output/return-error-execution.detail.md b/website/content/_snippets/examples/output/return-error-execution.detail.md index 4e4e417ab..f6fadb8c0 100644 --- a/website/content/_snippets/examples/output/return-error-execution.detail.md +++ b/website/content/_snippets/examples/output/return-error-execution.detail.md @@ -49,7 +49,7 @@ ContextualAggregateError: One or more errors in the execution result. at handleOutput (/some/path/to/handleOutput.ts:XX:XX:19) at run (/some/path/to/client.ts:XX:XX:12) at process.processTicksAndRejections (node:internal/process/task_queues:XX:XX) - at async executeRootType (/some/path/to/client.ts:XX:XX:12) + at async executeDocument (/some/path/to/client.ts:XX:XX:12) at async executeRootTypeField (/some/path/to/client.ts:XX:XX:20) at async (/some/path/to/output_return-error_return-error-execution__return-error-execution.ts:XX:XX:16) { context: {}, @@ -89,7 +89,7 @@ ContextualError: There was an error in the extension "anonymous" (use named func at process.processTicksAndRejections (node:internal/process/task_queues:XX:XX) at async Object.run (/some/path/to/main.ts:XX:XX:22) at async run (/some/path/to/client.ts:XX:XX:20) - at async executeRootType (/some/path/to/client.ts:XX:XX:12) + at async executeDocument (/some/path/to/client.ts:XX:XX:12) at async executeRootTypeField (/some/path/to/client.ts:XX:XX:20) at async (/some/path/to/output_return-error_return-error-execution__return-error-execution.ts:XX:XX:3) { context: { diff --git a/website/content/_snippets/examples/output/return-error-execution.md b/website/content/_snippets/examples/output/return-error-execution.md index f4c8e7f24..f60bfea43 100644 --- a/website/content/_snippets/examples/output/return-error-execution.md +++ b/website/content/_snippets/examples/output/return-error-execution.md @@ -47,7 +47,7 @@ ContextualAggregateError: One or more errors in the execution result. at handleOutput (/some/path/to/handleOutput.ts:XX:XX:19) at run (/some/path/to/client.ts:XX:XX:12) at process.processTicksAndRejections (node:internal/process/task_queues:XX:XX) - at async executeRootType (/some/path/to/client.ts:XX:XX:12) + at async executeDocument (/some/path/to/client.ts:XX:XX:12) at async executeRootTypeField (/some/path/to/client.ts:XX:XX:20) at async (/some/path/to/output_return-error_return-error-execution__return-error-execution.ts:XX:XX:16) { context: {}, @@ -87,7 +87,7 @@ ContextualError: There was an error in the extension "anonymous" (use named func at process.processTicksAndRejections (node:internal/process/task_queues:XX:XX) at async Object.run (/some/path/to/main.ts:XX:XX:22) at async run (/some/path/to/client.ts:XX:XX:20) - at async executeRootType (/some/path/to/client.ts:XX:XX:12) + at async executeDocument (/some/path/to/client.ts:XX:XX:12) at async executeRootTypeField (/some/path/to/client.ts:XX:XX:20) at async (/some/path/to/output_return-error_return-error-execution__return-error-execution.ts:XX:XX:3) { context: { diff --git a/website/content/_snippets/examples/output/return-error.detail.md b/website/content/_snippets/examples/output/return-error.detail.md index 0977958a2..c233dea64 100644 --- a/website/content/_snippets/examples/output/return-error.detail.md +++ b/website/content/_snippets/examples/output/return-error.detail.md @@ -36,7 +36,7 @@ ContextualError: There was an error in the extension "anonymous" (use named func at runPipeline (/some/path/to/runPipeline.ts:XX:XX:18) at async Object.run (/some/path/to/main.ts:XX:XX:22) at async run (/some/path/to/client.ts:XX:XX:20) - at async executeRootType (/some/path/to/client.ts:XX:XX:12) + at async executeDocument (/some/path/to/client.ts:XX:XX:12) at async executeRootTypeField (/some/path/to/client.ts:XX:XX:20) at async (/some/path/to/output_return-error.ts:XX:XX:18) { context: { diff --git a/website/content/_snippets/examples/output/return-error.md b/website/content/_snippets/examples/output/return-error.md index 1129d70ae..15c222168 100644 --- a/website/content/_snippets/examples/output/return-error.md +++ b/website/content/_snippets/examples/output/return-error.md @@ -34,7 +34,7 @@ ContextualError: There was an error in the extension "anonymous" (use named func at runPipeline (/some/path/to/runPipeline.ts:XX:XX:18) at async Object.run (/some/path/to/main.ts:XX:XX:22) at async run (/some/path/to/client.ts:XX:XX:20) - at async executeRootType (/some/path/to/client.ts:XX:XX:12) + at async executeDocument (/some/path/to/client.ts:XX:XX:12) at async executeRootTypeField (/some/path/to/client.ts:XX:XX:20) at async (/some/path/to/output_return-error.ts:XX:XX:18) { context: { diff --git a/website/content/_snippets/examples/transport-http/abort.detail.md b/website/content/_snippets/examples/transport-http/abort.detail.md index 953cdb100..16ee55d7b 100644 --- a/website/content/_snippets/examples/transport-http/abort.detail.md +++ b/website/content/_snippets/examples/transport-http/abort.detail.md @@ -38,7 +38,7 @@ console.log(result) ```txt -'This operation was aborted' +This operation was aborted ``` diff --git a/website/content/_snippets/examples/transport-http/abort.md b/website/content/_snippets/examples/transport-http/abort.md index e08e6291b..ea8ab3519 100644 --- a/website/content/_snippets/examples/transport-http/abort.md +++ b/website/content/_snippets/examples/transport-http/abort.md @@ -36,7 +36,7 @@ console.log(result) ```txt -'This operation was aborted' +This operation was aborted ``` 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 1af143d7c..4bc21d9be 100644 --- a/website/content/_snippets/examples/transport-http/dynamic-headers.detail.md +++ b/website/content/_snippets/examples/transport-http/dynamic-headers.detail.md @@ -38,7 +38,7 @@ await graffle.rawString({ document: `{ pokemons { name } }` }) headers: Headers { accept: 'application/graphql-response+json; charset=utf-8, application/json; charset=utf-8', 'content-type': 'application/json', - 'x-sent-at-time': '1727319638284' + 'x-sent-at-time': '1727365576054' }, 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 2a67fdfec..ee7e707c3 100644 --- a/website/content/_snippets/examples/transport-http/dynamic-headers.md +++ b/website/content/_snippets/examples/transport-http/dynamic-headers.md @@ -36,7 +36,7 @@ await graffle.rawString({ document: `{ pokemons { name } }` }) headers: Headers { accept: 'application/graphql-response+json; charset=utf-8, application/json; charset=utf-8', 'content-type': 'application/json', - 'x-sent-at-time': '1727319638284' + 'x-sent-at-time': '1727365576054' }, signal: undefined, method: 'post', diff --git a/website/content/examples/10_transport-http/abort.md b/website/content/examples/10_transport-http/abort.md index 8ce752c99..696282155 100644 --- a/website/content/examples/10_transport-http/abort.md +++ b/website/content/examples/10_transport-http/abort.md @@ -43,6 +43,6 @@ console.log(result) ```txt -'This operation was aborted' +This operation was aborted ``` diff --git a/website/content/examples/10_transport-http/dynamic-headers.md b/website/content/examples/10_transport-http/dynamic-headers.md index 125254f6b..e0d97693b 100644 --- a/website/content/examples/10_transport-http/dynamic-headers.md +++ b/website/content/examples/10_transport-http/dynamic-headers.md @@ -43,7 +43,7 @@ await graffle.rawString({ document: `{ pokemons { name } }` }) headers: Headers { accept: 'application/graphql-response+json; charset=utf-8, application/json; charset=utf-8', 'content-type': 'application/json', - 'x-sent-at-time': '1727319638284' + 'x-sent-at-time': '1727365576054' }, signal: undefined, method: 'post', diff --git a/website/content/examples/20_output/envelope-error-throw.md b/website/content/examples/20_output/envelope-error-throw.md index 2134a17c2..96d22a962 100644 --- a/website/content/examples/20_output/envelope-error-throw.md +++ b/website/content/examples/20_output/envelope-error-throw.md @@ -44,7 +44,7 @@ ContextualError: There was an error in the extension "anonymous" (use named func at runPipeline (/some/path/to/runPipeline.ts:XX:XX:18) at async Object.run (/some/path/to/main.ts:XX:XX:22) at async run (/some/path/to/client.ts:XX:XX:20) - at async executeRootType (/some/path/to/client.ts:XX:XX:12) + at async executeDocument (/some/path/to/client.ts:XX:XX:12) at async executeRootTypeField (/some/path/to/client.ts:XX:XX:20) at async (/some/path/to/output_envelope_envelope_error-throw__envelope-error-throw.ts:XX:XX:1) { context: { diff --git a/website/content/examples/20_output/envelope-error.md b/website/content/examples/20_output/envelope-error.md index a9dc5a57b..bbe8bb10c 100644 --- a/website/content/examples/20_output/envelope-error.md +++ b/website/content/examples/20_output/envelope-error.md @@ -44,7 +44,7 @@ console.log(result) at runPipeline (/some/path/to/runPipeline.ts:XX:XX:18) at async Object.run (/some/path/to/main.ts:XX:XX:22) at async run (/some/path/to/client.ts:XX:XX:20) - at async executeRootType (/some/path/to/client.ts:XX:XX:12) + at async executeDocument (/some/path/to/client.ts:XX:XX:12) at async executeRootTypeField (/some/path/to/client.ts:XX:XX:20) at async (/some/path/to/output_envelope_envelope-error__envelope-error.ts:XX:XX:16) { context: { diff --git a/website/content/examples/20_output/envelope.md b/website/content/examples/20_output/envelope.md index 84062ead1..1c1245700 100644 --- a/website/content/examples/20_output/envelope.md +++ b/website/content/examples/20_output/envelope.md @@ -44,7 +44,7 @@ console.log(result) headers: Headers { 'content-type': 'application/graphql-response+json; charset=utf-8', 'content-length': '104', - date: 'Thu, 26 Sep 2024 03:00:38 GMT', + date: 'Thu, 26 Sep 2024 15:46:16 GMT', connection: 'keep-alive', 'keep-alive': 'timeout=5' }, diff --git a/website/content/examples/20_output/return-error-execution.md b/website/content/examples/20_output/return-error-execution.md index e44b2e16a..782578511 100644 --- a/website/content/examples/20_output/return-error-execution.md +++ b/website/content/examples/20_output/return-error-execution.md @@ -54,7 +54,7 @@ ContextualAggregateError: One or more errors in the execution result. at handleOutput (/some/path/to/handleOutput.ts:XX:XX:19) at run (/some/path/to/client.ts:XX:XX:12) at process.processTicksAndRejections (node:internal/process/task_queues:XX:XX) - at async executeRootType (/some/path/to/client.ts:XX:XX:12) + at async executeDocument (/some/path/to/client.ts:XX:XX:12) at async executeRootTypeField (/some/path/to/client.ts:XX:XX:20) at async (/some/path/to/output_return-error_return-error-execution__return-error-execution.ts:XX:XX:16) { context: {}, @@ -94,7 +94,7 @@ ContextualError: There was an error in the extension "anonymous" (use named func at process.processTicksAndRejections (node:internal/process/task_queues:XX:XX) at async Object.run (/some/path/to/main.ts:XX:XX:22) at async run (/some/path/to/client.ts:XX:XX:20) - at async executeRootType (/some/path/to/client.ts:XX:XX:12) + at async executeDocument (/some/path/to/client.ts:XX:XX:12) at async executeRootTypeField (/some/path/to/client.ts:XX:XX:20) at async (/some/path/to/output_return-error_return-error-execution__return-error-execution.ts:XX:XX:3) { context: { diff --git a/website/content/examples/20_output/return-error.md b/website/content/examples/20_output/return-error.md index dcff50336..397f54f5b 100644 --- a/website/content/examples/20_output/return-error.md +++ b/website/content/examples/20_output/return-error.md @@ -41,7 +41,7 @@ ContextualError: There was an error in the extension "anonymous" (use named func at runPipeline (/some/path/to/runPipeline.ts:XX:XX:18) at async Object.run (/some/path/to/main.ts:XX:XX:22) at async run (/some/path/to/client.ts:XX:XX:20) - at async executeRootType (/some/path/to/client.ts:XX:XX:12) + at async executeDocument (/some/path/to/client.ts:XX:XX:12) at async executeRootTypeField (/some/path/to/client.ts:XX:XX:20) at async (/some/path/to/output_return-error.ts:XX:XX:18) { context: { diff --git a/website/content/examples/55_generated/arguments.md b/website/content/examples/55_generated/arguments.md index 9dc24900f..1241f97fc 100644 --- a/website/content/examples/55_generated/arguments.md +++ b/website/content/examples/55_generated/arguments.md @@ -14,7 +14,7 @@ import { Pokemon } from './pokemon/__.js' const atlas = Pokemon.create() const pokemons = await atlas.query.pokemons({ - $: { filter: { name: { in: [`Pikachu`, `Charizard`] } } }, + $: { filter: { name: { in: [`Pikachu`, `Charizard`] } } }, // [!code highlight] name: true, trainer: { name: true }, }) diff --git a/website/content/examples/60_extension/opentelemetry.md b/website/content/examples/60_extension/opentelemetry.md index 32205f828..b67953677 100644 --- a/website/content/examples/60_extension/opentelemetry.md +++ b/website/content/examples/60_extension/opentelemetry.md @@ -41,14 +41,14 @@ console.log(data) } }, instrumentationScope: { name: 'graffle', version: undefined, schemaUrl: undefined }, - traceId: '851f3f771b76e4969a2f8c084f85759d', - parentId: 'ebd5237ad56b820c', + traceId: '99a1b00f220469bd559f6fdc09b75cfc', + parentId: 'fb04e4436519eebf', traceState: undefined, name: 'encode', - id: 'ff492c55cf5462ff', + id: 'b9cc31cb6dcef7bb', kind: 0, - timestamp: 1727319638868000, - duration: 1170.584, + timestamp: 1727365576823000, + duration: 586.292, attributes: {}, status: { code: 0 }, events: [], @@ -68,14 +68,14 @@ console.log(data) } }, instrumentationScope: { name: 'graffle', version: undefined, schemaUrl: undefined }, - traceId: '851f3f771b76e4969a2f8c084f85759d', - parentId: 'ebd5237ad56b820c', + traceId: '99a1b00f220469bd559f6fdc09b75cfc', + parentId: 'fb04e4436519eebf', traceState: undefined, name: 'pack', - id: '9174a3424a228e28', + id: 'fb77c65e19244b1f', kind: 0, - timestamp: 1727319638871000, - duration: 36417.291, + timestamp: 1727365576831000, + duration: 19896.75, attributes: {}, status: { code: 0 }, events: [], @@ -95,14 +95,14 @@ console.log(data) } }, instrumentationScope: { name: 'graffle', version: undefined, schemaUrl: undefined }, - traceId: '851f3f771b76e4969a2f8c084f85759d', - parentId: 'ebd5237ad56b820c', + traceId: '99a1b00f220469bd559f6fdc09b75cfc', + parentId: 'fb04e4436519eebf', traceState: undefined, name: 'exchange', - id: '85de30bd471a1d11', + id: '7e3a75386432d606', kind: 0, - timestamp: 1727319638909000, - duration: 24460.084, + timestamp: 1727365576852000, + duration: 29439.625, attributes: {}, status: { code: 0 }, events: [], @@ -122,14 +122,14 @@ console.log(data) } }, instrumentationScope: { name: 'graffle', version: undefined, schemaUrl: undefined }, - traceId: '851f3f771b76e4969a2f8c084f85759d', - parentId: 'ebd5237ad56b820c', + traceId: '99a1b00f220469bd559f6fdc09b75cfc', + parentId: 'fb04e4436519eebf', traceState: undefined, name: 'unpack', - id: '81208c873ce84df5', + id: '6263aef06e4164d0', kind: 0, - timestamp: 1727319638933000, - duration: 1301.541, + timestamp: 1727365576881000, + duration: 1157, attributes: {}, status: { code: 0 }, events: [], @@ -149,14 +149,14 @@ console.log(data) } }, instrumentationScope: { name: 'graffle', version: undefined, schemaUrl: undefined }, - traceId: '851f3f771b76e4969a2f8c084f85759d', - parentId: 'ebd5237ad56b820c', + traceId: '99a1b00f220469bd559f6fdc09b75cfc', + parentId: 'fb04e4436519eebf', traceState: undefined, name: 'decode', - id: '0e084f67d12e45c7', + id: 'f6e875f59111e613', kind: 0, - timestamp: 1727319638935000, - duration: 199.208, + timestamp: 1727365576883000, + duration: 193.042, attributes: {}, status: { code: 0 }, events: [], @@ -176,14 +176,14 @@ console.log(data) } }, instrumentationScope: { name: 'graffle', version: undefined, schemaUrl: undefined }, - traceId: '851f3f771b76e4969a2f8c084f85759d', + traceId: '99a1b00f220469bd559f6fdc09b75cfc', parentId: undefined, traceState: undefined, name: 'request', - id: 'ebd5237ad56b820c', + id: 'fb04e4436519eebf', kind: 0, - timestamp: 1727319638867000, - duration: 68430.791, + timestamp: 1727365576822000, + duration: 61277.208, attributes: {}, status: { code: 0 }, events: [],