From 15d554cc72799b45c7e74177e47dfa9354fd1941 Mon Sep 17 00:00:00 2001 From: Jason Kuhrt Date: Wed, 23 Oct 2024 12:06:32 -0400 Subject: [PATCH] feat(custom-scalars): overload method for easy inline add (#1212) --- examples/35_custom-scalar/custom-scalar.ts | 11 ++-- ...tension_headers__dynamicHeaders.output.txt | 2 +- .../20_output/output_envelope.output.txt | 2 +- ...on_opentelemetry__opentelemetry.output.txt | 58 +++++++++---------- src/layers/6_client/properties/scalar.ts | 28 +++++++-- .../custom-scalar/custom-scalar.detail.md | 11 ++-- .../examples/custom-scalar/custom-scalar.md | 11 ++-- .../extension/opentelemetry.detail.md | 58 +++++++++---------- .../examples/extension/opentelemetry.md | 58 +++++++++---------- .../examples/output/envelope.detail.md | 2 +- .../_snippets/examples/output/envelope.md | 2 +- .../transport-http/dynamic-headers.detail.md | 2 +- .../transport-http/dynamic-headers.md | 2 +- .../10_transport-http/dynamic-headers.md | 2 +- .../content/examples/20_output/envelope.md | 2 +- .../35_custom-scalar/custom-scalar.md | 11 ++-- .../examples/60_extension/opentelemetry.md | 58 +++++++++---------- 17 files changed, 164 insertions(+), 156 deletions(-) diff --git a/examples/35_custom-scalar/custom-scalar.ts b/examples/35_custom-scalar/custom-scalar.ts index d1ff4932..7acd4ee7 100644 --- a/examples/35_custom-scalar/custom-scalar.ts +++ b/examples/35_custom-scalar/custom-scalar.ts @@ -3,18 +3,15 @@ * have arguments and data automatically encoded and decoded respectively. */ -import { Graffle } from '../../src/entrypoints/__Graffle.js' import { Pokemon } from '../../tests/_/schemas/pokemon/graffle/__.js' import { show } from '../$/helpers.js' const graffle = Pokemon .create() - .scalar(Graffle.Scalars.create(`Date`, { - encode: (value: globalThis.Date) => value.toISOString(), - decode: (value: string) => { - return new globalThis.Date(value) - }, - })) + .scalar(`Date`, { + decode: (value) => new globalThis.Date(value), + encode: (value) => value.toISOString(), + }) const pokemons = await graffle.query.pokemons({ $: { filter: { birthday: { lte: new Date(`1987-01-13`) } } }, 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 0651788a..c79aa780 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': '1729695636061' + 'x-sent-at-time': '1729696838476' }, 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 4e56567b..cc680b83 100644 --- a/examples/__outputs__/20_output/output_envelope.output.txt +++ b/examples/__outputs__/20_output/output_envelope.output.txt @@ -18,7 +18,7 @@ headers: Headers { 'content-type': 'application/graphql-response+json; charset=utf-8', 'content-length': '142', - date: 'Wed, 23 Oct 2024 15:00:36 GMT', + date: 'Wed, 23 Oct 2024 15:20:39 GMT', connection: 'keep-alive', 'keep-alive': 'timeout=5' }, diff --git a/examples/__outputs__/60_extension/extension_opentelemetry__opentelemetry.output.txt b/examples/__outputs__/60_extension/extension_opentelemetry__opentelemetry.output.txt index e1e72cdd..7a1d936c 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: 'a06cc237fb19a0f3f72a6b58c7a1c197', - parentId: '996dbc7722cae52f', + traceId: '9d3e044ef7452a5b0e773ac8a7e6c8bd', + parentId: 'fdbedbd147dc630c', traceState: undefined, name: 'encode', - id: '013ccc636ba5ab5a', + id: '4f8b5fccd96cc062', kind: 0, - timestamp: 1729695637401000, - duration: 1347.708, + timestamp: 1729696839648000, + duration: 1705.875, attributes: {}, status: { code: 0 }, events: [], @@ -33,14 +33,14 @@ } }, instrumentationScope: { name: 'graffle', version: undefined, schemaUrl: undefined }, - traceId: 'a06cc237fb19a0f3f72a6b58c7a1c197', - parentId: '996dbc7722cae52f', + traceId: '9d3e044ef7452a5b0e773ac8a7e6c8bd', + parentId: 'fdbedbd147dc630c', traceState: undefined, name: 'pack', - id: '9f77c7eb28b781b8', + id: 'a2cb6c68bb391b81', kind: 0, - timestamp: 1729695637404000, - duration: 11403.833, + timestamp: 1729696839652000, + duration: 16711.541, attributes: {}, status: { code: 0 }, events: [], @@ -57,14 +57,14 @@ } }, instrumentationScope: { name: 'graffle', version: undefined, schemaUrl: undefined }, - traceId: 'a06cc237fb19a0f3f72a6b58c7a1c197', - parentId: '996dbc7722cae52f', + traceId: '9d3e044ef7452a5b0e773ac8a7e6c8bd', + parentId: 'fdbedbd147dc630c', traceState: undefined, name: 'exchange', - id: '37e8810021b4127d', + id: '95bc25186061869d', kind: 0, - timestamp: 1729695637416000, - duration: 28133.5, + timestamp: 1729696839669000, + duration: 21608.417, attributes: {}, status: { code: 0 }, events: [], @@ -81,14 +81,14 @@ } }, instrumentationScope: { name: 'graffle', version: undefined, schemaUrl: undefined }, - traceId: 'a06cc237fb19a0f3f72a6b58c7a1c197', - parentId: '996dbc7722cae52f', + traceId: '9d3e044ef7452a5b0e773ac8a7e6c8bd', + parentId: 'fdbedbd147dc630c', traceState: undefined, name: 'unpack', - id: '87bd4d2329beb31f', + id: 'f33a840d705729c6', kind: 0, - timestamp: 1729695637445000, - duration: 1657.667, + timestamp: 1729696839691000, + duration: 1755.75, attributes: {}, status: { code: 0 }, events: [], @@ -105,14 +105,14 @@ } }, instrumentationScope: { name: 'graffle', version: undefined, schemaUrl: undefined }, - traceId: 'a06cc237fb19a0f3f72a6b58c7a1c197', - parentId: '996dbc7722cae52f', + traceId: '9d3e044ef7452a5b0e773ac8a7e6c8bd', + parentId: 'fdbedbd147dc630c', traceState: undefined, name: 'decode', - id: 'e8b9d88dc53ff408', + id: 'd5abeead8c05a053', kind: 0, - timestamp: 1729695637447000, - duration: 214.875, + timestamp: 1729696839693000, + duration: 313.709, attributes: {}, status: { code: 0 }, events: [], @@ -129,14 +129,14 @@ } }, instrumentationScope: { name: 'graffle', version: undefined, schemaUrl: undefined }, - traceId: 'a06cc237fb19a0f3f72a6b58c7a1c197', + traceId: '9d3e044ef7452a5b0e773ac8a7e6c8bd', parentId: undefined, traceState: undefined, name: 'request', - id: '996dbc7722cae52f', + id: 'fdbedbd147dc630c', kind: 0, - timestamp: 1729695637401000, - duration: 46241.5, + timestamp: 1729696839647000, + duration: 46403, attributes: {}, status: { code: 0 }, events: [], diff --git a/src/layers/6_client/properties/scalar.ts b/src/layers/6_client/properties/scalar.ts index 425a7fa9..d26e8965 100644 --- a/src/layers/6_client/properties/scalar.ts +++ b/src/layers/6_client/properties/scalar.ts @@ -1,6 +1,6 @@ import type { ConfigManager } from '../../../lib/config-manager/__.js' import type { Fluent } from '../../../lib/fluent/__.js' -import type { Schema } from '../../../types/Schema/__.js' +import { Schema } from '../../../types/Schema/__.js' import { type ClientContext, defineProperties, type FnParametersProperty } from '../fluent.js' export interface ScalarFn extends Fluent.FnProperty<`scalar`> { @@ -12,8 +12,22 @@ export interface Scalar<$Args extends FnParametersProperty> { /** * TODO Docs. */ - // @ts-expect-error todo - <$Scalar extends Schema.Scalar.Scalar>(scalar: $Scalar): Fluent.IncrementWithStateSet(name: $Name, $Codec: { + decode: (value: string) => $Decoded + encode: (value: $Decoded) => string + }): Fluent.IncrementWithStateSet> + > + properties: $Args['state']['properties'] + }> + /** + * TODO Docs. + */ + <$Scalar extends Schema.Scalar>(scalar: $Scalar): Fluent.IncrementWithStateSet { }> } +type Arguments = [Schema.Scalar] | [string, { decode: (value: string) => any; encode: (value: any) => string }] + export const scalarProperties = defineProperties((builder, state) => { return { - scalar: (scalar: Schema.Scalar) => { + scalar: (...args: Arguments) => { + const scalar = Schema.Scalar.isScalar(args[0]) + ? args[0] + : Schema.Scalar.create(args[0], args[1]!) + return builder({ ...state, scalars: { diff --git a/website/content/_snippets/examples/custom-scalar/custom-scalar.detail.md b/website/content/_snippets/examples/custom-scalar/custom-scalar.detail.md index cf45ddc6..07359468 100644 --- a/website/content/_snippets/examples/custom-scalar/custom-scalar.detail.md +++ b/website/content/_snippets/examples/custom-scalar/custom-scalar.detail.md @@ -5,17 +5,14 @@ ```ts twoslash -import { Graffle } from 'graffle/__Graffle' import { Pokemon } from './pokemon/__.js' const graffle = Pokemon .create() - .scalar(Graffle.Scalars.create(`Date`, { - encode: (value: globalThis.Date) => value.toISOString(), - decode: (value: string) => { - return new globalThis.Date(value) - }, - })) + .scalar(`Date`, { + decode: (value) => new globalThis.Date(value), + encode: (value) => value.toISOString(), + }) const pokemons = await graffle.query.pokemons({ $: { filter: { birthday: { lte: new Date(`1987-01-13`) } } }, diff --git a/website/content/_snippets/examples/custom-scalar/custom-scalar.md b/website/content/_snippets/examples/custom-scalar/custom-scalar.md index c25297df..b5771666 100644 --- a/website/content/_snippets/examples/custom-scalar/custom-scalar.md +++ b/website/content/_snippets/examples/custom-scalar/custom-scalar.md @@ -3,17 +3,14 @@ ```ts twoslash -import { Graffle } from 'graffle/__Graffle' import { Pokemon } from './pokemon/__.js' const graffle = Pokemon .create() - .scalar(Graffle.Scalars.create(`Date`, { - encode: (value: globalThis.Date) => value.toISOString(), - decode: (value: string) => { - return new globalThis.Date(value) - }, - })) + .scalar(`Date`, { + decode: (value) => new globalThis.Date(value), + encode: (value) => value.toISOString(), + }) const pokemons = await graffle.query.pokemons({ $: { filter: { birthday: { lte: new Date(`1987-01-13`) } } }, diff --git a/website/content/_snippets/examples/extension/opentelemetry.detail.md b/website/content/_snippets/examples/extension/opentelemetry.detail.md index b92b120d..58e072f0 100644 --- a/website/content/_snippets/examples/extension/opentelemetry.detail.md +++ b/website/content/_snippets/examples/extension/opentelemetry.detail.md @@ -37,14 +37,14 @@ console.log(data) } }, instrumentationScope: { name: 'graffle', version: undefined, schemaUrl: undefined }, - traceId: 'a06cc237fb19a0f3f72a6b58c7a1c197', - parentId: '996dbc7722cae52f', + traceId: '9d3e044ef7452a5b0e773ac8a7e6c8bd', + parentId: 'fdbedbd147dc630c', traceState: undefined, name: 'encode', - id: '013ccc636ba5ab5a', + id: '4f8b5fccd96cc062', kind: 0, - timestamp: 1729695637401000, - duration: 1347.708, + timestamp: 1729696839648000, + duration: 1705.875, attributes: {}, status: { code: 0 }, events: [], @@ -64,14 +64,14 @@ console.log(data) } }, instrumentationScope: { name: 'graffle', version: undefined, schemaUrl: undefined }, - traceId: 'a06cc237fb19a0f3f72a6b58c7a1c197', - parentId: '996dbc7722cae52f', + traceId: '9d3e044ef7452a5b0e773ac8a7e6c8bd', + parentId: 'fdbedbd147dc630c', traceState: undefined, name: 'pack', - id: '9f77c7eb28b781b8', + id: 'a2cb6c68bb391b81', kind: 0, - timestamp: 1729695637404000, - duration: 11403.833, + timestamp: 1729696839652000, + duration: 16711.541, attributes: {}, status: { code: 0 }, events: [], @@ -91,14 +91,14 @@ console.log(data) } }, instrumentationScope: { name: 'graffle', version: undefined, schemaUrl: undefined }, - traceId: 'a06cc237fb19a0f3f72a6b58c7a1c197', - parentId: '996dbc7722cae52f', + traceId: '9d3e044ef7452a5b0e773ac8a7e6c8bd', + parentId: 'fdbedbd147dc630c', traceState: undefined, name: 'exchange', - id: '37e8810021b4127d', + id: '95bc25186061869d', kind: 0, - timestamp: 1729695637416000, - duration: 28133.5, + timestamp: 1729696839669000, + duration: 21608.417, attributes: {}, status: { code: 0 }, events: [], @@ -118,14 +118,14 @@ console.log(data) } }, instrumentationScope: { name: 'graffle', version: undefined, schemaUrl: undefined }, - traceId: 'a06cc237fb19a0f3f72a6b58c7a1c197', - parentId: '996dbc7722cae52f', + traceId: '9d3e044ef7452a5b0e773ac8a7e6c8bd', + parentId: 'fdbedbd147dc630c', traceState: undefined, name: 'unpack', - id: '87bd4d2329beb31f', + id: 'f33a840d705729c6', kind: 0, - timestamp: 1729695637445000, - duration: 1657.667, + timestamp: 1729696839691000, + duration: 1755.75, attributes: {}, status: { code: 0 }, events: [], @@ -145,14 +145,14 @@ console.log(data) } }, instrumentationScope: { name: 'graffle', version: undefined, schemaUrl: undefined }, - traceId: 'a06cc237fb19a0f3f72a6b58c7a1c197', - parentId: '996dbc7722cae52f', + traceId: '9d3e044ef7452a5b0e773ac8a7e6c8bd', + parentId: 'fdbedbd147dc630c', traceState: undefined, name: 'decode', - id: 'e8b9d88dc53ff408', + id: 'd5abeead8c05a053', kind: 0, - timestamp: 1729695637447000, - duration: 214.875, + timestamp: 1729696839693000, + duration: 313.709, attributes: {}, status: { code: 0 }, events: [], @@ -172,14 +172,14 @@ console.log(data) } }, instrumentationScope: { name: 'graffle', version: undefined, schemaUrl: undefined }, - traceId: 'a06cc237fb19a0f3f72a6b58c7a1c197', + traceId: '9d3e044ef7452a5b0e773ac8a7e6c8bd', parentId: undefined, traceState: undefined, name: 'request', - id: '996dbc7722cae52f', + id: 'fdbedbd147dc630c', kind: 0, - timestamp: 1729695637401000, - duration: 46241.5, + timestamp: 1729696839647000, + duration: 46403, attributes: {}, status: { code: 0 }, events: [], diff --git a/website/content/_snippets/examples/extension/opentelemetry.md b/website/content/_snippets/examples/extension/opentelemetry.md index dbb0a0ef..b7cec88a 100644 --- a/website/content/_snippets/examples/extension/opentelemetry.md +++ b/website/content/_snippets/examples/extension/opentelemetry.md @@ -35,14 +35,14 @@ console.log(data) } }, instrumentationScope: { name: 'graffle', version: undefined, schemaUrl: undefined }, - traceId: 'a06cc237fb19a0f3f72a6b58c7a1c197', - parentId: '996dbc7722cae52f', + traceId: '9d3e044ef7452a5b0e773ac8a7e6c8bd', + parentId: 'fdbedbd147dc630c', traceState: undefined, name: 'encode', - id: '013ccc636ba5ab5a', + id: '4f8b5fccd96cc062', kind: 0, - timestamp: 1729695637401000, - duration: 1347.708, + timestamp: 1729696839648000, + duration: 1705.875, attributes: {}, status: { code: 0 }, events: [], @@ -62,14 +62,14 @@ console.log(data) } }, instrumentationScope: { name: 'graffle', version: undefined, schemaUrl: undefined }, - traceId: 'a06cc237fb19a0f3f72a6b58c7a1c197', - parentId: '996dbc7722cae52f', + traceId: '9d3e044ef7452a5b0e773ac8a7e6c8bd', + parentId: 'fdbedbd147dc630c', traceState: undefined, name: 'pack', - id: '9f77c7eb28b781b8', + id: 'a2cb6c68bb391b81', kind: 0, - timestamp: 1729695637404000, - duration: 11403.833, + timestamp: 1729696839652000, + duration: 16711.541, attributes: {}, status: { code: 0 }, events: [], @@ -89,14 +89,14 @@ console.log(data) } }, instrumentationScope: { name: 'graffle', version: undefined, schemaUrl: undefined }, - traceId: 'a06cc237fb19a0f3f72a6b58c7a1c197', - parentId: '996dbc7722cae52f', + traceId: '9d3e044ef7452a5b0e773ac8a7e6c8bd', + parentId: 'fdbedbd147dc630c', traceState: undefined, name: 'exchange', - id: '37e8810021b4127d', + id: '95bc25186061869d', kind: 0, - timestamp: 1729695637416000, - duration: 28133.5, + timestamp: 1729696839669000, + duration: 21608.417, attributes: {}, status: { code: 0 }, events: [], @@ -116,14 +116,14 @@ console.log(data) } }, instrumentationScope: { name: 'graffle', version: undefined, schemaUrl: undefined }, - traceId: 'a06cc237fb19a0f3f72a6b58c7a1c197', - parentId: '996dbc7722cae52f', + traceId: '9d3e044ef7452a5b0e773ac8a7e6c8bd', + parentId: 'fdbedbd147dc630c', traceState: undefined, name: 'unpack', - id: '87bd4d2329beb31f', + id: 'f33a840d705729c6', kind: 0, - timestamp: 1729695637445000, - duration: 1657.667, + timestamp: 1729696839691000, + duration: 1755.75, attributes: {}, status: { code: 0 }, events: [], @@ -143,14 +143,14 @@ console.log(data) } }, instrumentationScope: { name: 'graffle', version: undefined, schemaUrl: undefined }, - traceId: 'a06cc237fb19a0f3f72a6b58c7a1c197', - parentId: '996dbc7722cae52f', + traceId: '9d3e044ef7452a5b0e773ac8a7e6c8bd', + parentId: 'fdbedbd147dc630c', traceState: undefined, name: 'decode', - id: 'e8b9d88dc53ff408', + id: 'd5abeead8c05a053', kind: 0, - timestamp: 1729695637447000, - duration: 214.875, + timestamp: 1729696839693000, + duration: 313.709, attributes: {}, status: { code: 0 }, events: [], @@ -170,14 +170,14 @@ console.log(data) } }, instrumentationScope: { name: 'graffle', version: undefined, schemaUrl: undefined }, - traceId: 'a06cc237fb19a0f3f72a6b58c7a1c197', + traceId: '9d3e044ef7452a5b0e773ac8a7e6c8bd', parentId: undefined, traceState: undefined, name: 'request', - id: '996dbc7722cae52f', + id: 'fdbedbd147dc630c', kind: 0, - timestamp: 1729695637401000, - duration: 46241.5, + timestamp: 1729696839647000, + duration: 46403, attributes: {}, status: { code: 0 }, events: [], diff --git a/website/content/_snippets/examples/output/envelope.detail.md b/website/content/_snippets/examples/output/envelope.detail.md index e0a02efa..cddb96a1 100644 --- a/website/content/_snippets/examples/output/envelope.detail.md +++ b/website/content/_snippets/examples/output/envelope.detail.md @@ -40,7 +40,7 @@ console.log(result) headers: Headers { 'content-type': 'application/graphql-response+json; charset=utf-8', 'content-length': '142', - date: 'Wed, 23 Oct 2024 15:00:36 GMT', + date: 'Wed, 23 Oct 2024 15:20:39 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 5d2cd326..c94614dc 100644 --- a/website/content/_snippets/examples/output/envelope.md +++ b/website/content/_snippets/examples/output/envelope.md @@ -38,7 +38,7 @@ console.log(result) headers: Headers { 'content-type': 'application/graphql-response+json; charset=utf-8', 'content-length': '142', - date: 'Wed, 23 Oct 2024 15:00:36 GMT', + date: 'Wed, 23 Oct 2024 15:20:39 GMT', connection: 'keep-alive', 'keep-alive': 'timeout=5' }, diff --git a/website/content/_snippets/examples/transport-http/dynamic-headers.detail.md b/website/content/_snippets/examples/transport-http/dynamic-headers.detail.md index 64c8a4c3..2faaffe0 100644 --- a/website/content/_snippets/examples/transport-http/dynamic-headers.detail.md +++ b/website/content/_snippets/examples/transport-http/dynamic-headers.detail.md @@ -38,7 +38,7 @@ await graffle.gql`{ pokemons { name } }`.send() headers: Headers { accept: 'application/graphql-response+json; charset=utf-8, application/json; charset=utf-8', 'content-type': 'application/json', - 'x-sent-at-time': '1729695636061' + 'x-sent-at-time': '1729696838476' }, 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 fe40d911..999dc394 100644 --- a/website/content/_snippets/examples/transport-http/dynamic-headers.md +++ b/website/content/_snippets/examples/transport-http/dynamic-headers.md @@ -36,7 +36,7 @@ await graffle.gql`{ pokemons { name } }`.send() headers: Headers { accept: 'application/graphql-response+json; charset=utf-8, application/json; charset=utf-8', 'content-type': 'application/json', - 'x-sent-at-time': '1729695636061' + 'x-sent-at-time': '1729696838476' }, signal: undefined, method: 'post', diff --git a/website/content/examples/10_transport-http/dynamic-headers.md b/website/content/examples/10_transport-http/dynamic-headers.md index 050a198a..15b30ef6 100644 --- a/website/content/examples/10_transport-http/dynamic-headers.md +++ b/website/content/examples/10_transport-http/dynamic-headers.md @@ -43,7 +43,7 @@ await graffle.gql`{ pokemons { name } }`.send() headers: Headers { accept: 'application/graphql-response+json; charset=utf-8, application/json; charset=utf-8', 'content-type': 'application/json', - 'x-sent-at-time': '1729695636061' + 'x-sent-at-time': '1729696838476' }, signal: undefined, method: 'post', diff --git a/website/content/examples/20_output/envelope.md b/website/content/examples/20_output/envelope.md index d4e87f41..db52fee2 100644 --- a/website/content/examples/20_output/envelope.md +++ b/website/content/examples/20_output/envelope.md @@ -45,7 +45,7 @@ console.log(result) headers: Headers { 'content-type': 'application/graphql-response+json; charset=utf-8', 'content-length': '142', - date: 'Wed, 23 Oct 2024 15:00:36 GMT', + date: 'Wed, 23 Oct 2024 15:20:39 GMT', connection: 'keep-alive', 'keep-alive': 'timeout=5' }, diff --git a/website/content/examples/35_custom-scalar/custom-scalar.md b/website/content/examples/35_custom-scalar/custom-scalar.md index 8f266de4..45544a0b 100644 --- a/website/content/examples/35_custom-scalar/custom-scalar.md +++ b/website/content/examples/35_custom-scalar/custom-scalar.md @@ -9,17 +9,14 @@ have arguments and data automatically encoded and decoded respectively. ```ts twoslash -import { Graffle } from 'graffle/__Graffle' import { Pokemon } from './pokemon/__.js' const graffle = Pokemon .create() - .scalar(Graffle.Scalars.create(`Date`, { - encode: (value: globalThis.Date) => value.toISOString(), - decode: (value: string) => { - return new globalThis.Date(value) - }, - })) + .scalar(`Date`, { + decode: (value) => new globalThis.Date(value), + encode: (value) => value.toISOString(), + }) const pokemons = await graffle.query.pokemons({ $: { filter: { birthday: { lte: new Date(`1987-01-13`) } } }, diff --git a/website/content/examples/60_extension/opentelemetry.md b/website/content/examples/60_extension/opentelemetry.md index ec887613..bd82e49b 100644 --- a/website/content/examples/60_extension/opentelemetry.md +++ b/website/content/examples/60_extension/opentelemetry.md @@ -40,14 +40,14 @@ console.log(data) } }, instrumentationScope: { name: 'graffle', version: undefined, schemaUrl: undefined }, - traceId: 'a06cc237fb19a0f3f72a6b58c7a1c197', - parentId: '996dbc7722cae52f', + traceId: '9d3e044ef7452a5b0e773ac8a7e6c8bd', + parentId: 'fdbedbd147dc630c', traceState: undefined, name: 'encode', - id: '013ccc636ba5ab5a', + id: '4f8b5fccd96cc062', kind: 0, - timestamp: 1729695637401000, - duration: 1347.708, + timestamp: 1729696839648000, + duration: 1705.875, attributes: {}, status: { code: 0 }, events: [], @@ -67,14 +67,14 @@ console.log(data) } }, instrumentationScope: { name: 'graffle', version: undefined, schemaUrl: undefined }, - traceId: 'a06cc237fb19a0f3f72a6b58c7a1c197', - parentId: '996dbc7722cae52f', + traceId: '9d3e044ef7452a5b0e773ac8a7e6c8bd', + parentId: 'fdbedbd147dc630c', traceState: undefined, name: 'pack', - id: '9f77c7eb28b781b8', + id: 'a2cb6c68bb391b81', kind: 0, - timestamp: 1729695637404000, - duration: 11403.833, + timestamp: 1729696839652000, + duration: 16711.541, attributes: {}, status: { code: 0 }, events: [], @@ -94,14 +94,14 @@ console.log(data) } }, instrumentationScope: { name: 'graffle', version: undefined, schemaUrl: undefined }, - traceId: 'a06cc237fb19a0f3f72a6b58c7a1c197', - parentId: '996dbc7722cae52f', + traceId: '9d3e044ef7452a5b0e773ac8a7e6c8bd', + parentId: 'fdbedbd147dc630c', traceState: undefined, name: 'exchange', - id: '37e8810021b4127d', + id: '95bc25186061869d', kind: 0, - timestamp: 1729695637416000, - duration: 28133.5, + timestamp: 1729696839669000, + duration: 21608.417, attributes: {}, status: { code: 0 }, events: [], @@ -121,14 +121,14 @@ console.log(data) } }, instrumentationScope: { name: 'graffle', version: undefined, schemaUrl: undefined }, - traceId: 'a06cc237fb19a0f3f72a6b58c7a1c197', - parentId: '996dbc7722cae52f', + traceId: '9d3e044ef7452a5b0e773ac8a7e6c8bd', + parentId: 'fdbedbd147dc630c', traceState: undefined, name: 'unpack', - id: '87bd4d2329beb31f', + id: 'f33a840d705729c6', kind: 0, - timestamp: 1729695637445000, - duration: 1657.667, + timestamp: 1729696839691000, + duration: 1755.75, attributes: {}, status: { code: 0 }, events: [], @@ -148,14 +148,14 @@ console.log(data) } }, instrumentationScope: { name: 'graffle', version: undefined, schemaUrl: undefined }, - traceId: 'a06cc237fb19a0f3f72a6b58c7a1c197', - parentId: '996dbc7722cae52f', + traceId: '9d3e044ef7452a5b0e773ac8a7e6c8bd', + parentId: 'fdbedbd147dc630c', traceState: undefined, name: 'decode', - id: 'e8b9d88dc53ff408', + id: 'd5abeead8c05a053', kind: 0, - timestamp: 1729695637447000, - duration: 214.875, + timestamp: 1729696839693000, + duration: 313.709, attributes: {}, status: { code: 0 }, events: [], @@ -175,14 +175,14 @@ console.log(data) } }, instrumentationScope: { name: 'graffle', version: undefined, schemaUrl: undefined }, - traceId: 'a06cc237fb19a0f3f72a6b58c7a1c197', + traceId: '9d3e044ef7452a5b0e773ac8a7e6c8bd', parentId: undefined, traceState: undefined, name: 'request', - id: '996dbc7722cae52f', + id: 'fdbedbd147dc630c', kind: 0, - timestamp: 1729695637401000, - duration: 46241.5, + timestamp: 1729696839647000, + duration: 46403, attributes: {}, status: { code: 0 }, events: [],