Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(extension-system): transport now extensible #1272

Merged
merged 45 commits into from
Dec 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
b9a38a7
feat(extension-system): transport now extensible
jasonkuhrt Nov 22, 2024
c6b9724
work
jasonkuhrt Nov 24, 2024
d81bacc
Merge branch 'main' into feat/transport-extension
jasonkuhrt Nov 25, 2024
9f06716
fix
jasonkuhrt Nov 25, 2024
af83022
progress
jasonkuhrt Nov 25, 2024
e045e57
progress
jasonkuhrt Nov 25, 2024
3a46488
progress
jasonkuhrt Nov 25, 2024
42eaf35
entrypoints
jasonkuhrt Nov 25, 2024
e0b335d
improve
jasonkuhrt Nov 25, 2024
c2cf519
progress
jasonkuhrt Nov 25, 2024
374228a
work
jasonkuhrt Nov 25, 2024
a11bdb6
work
jasonkuhrt Nov 25, 2024
b49795a
work
jasonkuhrt Nov 25, 2024
d819721
work
jasonkuhrt Nov 25, 2024
5e0e007
rename
jasonkuhrt Nov 26, 2024
f84d919
work
jasonkuhrt Nov 26, 2024
f1a0a1b
static pipline
jasonkuhrt Nov 26, 2024
f241610
progress
jasonkuhrt Nov 26, 2024
ac6d693
fixes
jasonkuhrt Nov 26, 2024
06e7671
work
jasonkuhrt Nov 26, 2024
e9c0405
fixes
jasonkuhrt Nov 26, 2024
a7ba972
work
jasonkuhrt Nov 26, 2024
a34f858
work
jasonkuhrt Nov 27, 2024
41f9822
work
jasonkuhrt Nov 27, 2024
ce76e4c
fix gen
jasonkuhrt Nov 27, 2024
a9252b5
bring back examples
jasonkuhrt Nov 27, 2024
97380e5
fixes
jasonkuhrt Nov 27, 2024
35867b0
bring stuff back
jasonkuhrt Nov 27, 2024
d6250b9
types passing
jasonkuhrt Nov 29, 2024
73774d3
organize
jasonkuhrt Nov 30, 2024
012f6a0
organize
jasonkuhrt Nov 30, 2024
a97088d
gen graffle
jasonkuhrt Nov 30, 2024
e657063
fix types
jasonkuhrt Nov 30, 2024
1eb554a
fixes
jasonkuhrt Nov 30, 2024
a53a078
fixes
jasonkuhrt Nov 30, 2024
6321996
transport initial config
jasonkuhrt Dec 1, 2024
e764882
fix more tests
jasonkuhrt Dec 1, 2024
d7bd7ce
fixes
jasonkuhrt Dec 1, 2024
493919c
fixes
jasonkuhrt Dec 1, 2024
947f5c8
fix tests
jasonkuhrt Dec 1, 2024
220e597
lint
jasonkuhrt Dec 1, 2024
9286e85
boo
jasonkuhrt Dec 1, 2024
517918c
fixes
jasonkuhrt Dec 2, 2024
31a74f6
partial or undefined
jasonkuhrt Dec 2, 2024
e33c10e
docs
jasonkuhrt Dec 2, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export default tsEslint.config({
},
},
rules: {
['prefer-arrow/prefer-arrow-functions']: 'off',
['@typescript-eslint/only-throw-error']: 'off',
['@typescript-eslint/no-unsafe-assignment']: 'off',
['@typescript-eslint/no-unsafe-call']: 'off',
Expand Down
10 changes: 4 additions & 6 deletions examples/10_transport-http/transport-http_abort.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,13 @@ import { publicGraphQLSchemaEndpoints, show } from '../$/helpers.js'
const abortController = new AbortController()
// ^^^^^^^^^^^^^^^

const graffle = Graffle.create({
schema: publicGraphQLSchemaEndpoints.Pokemon,
const graffle = Graffle.create().transport({
url: publicGraphQLSchemaEndpoints.Pokemon,
})

graffle

const resultPromise = graffle
.with({ transport: { raw: { signal: abortController.signal } } })
// ^^^^^^^^^^^^^^^
.transport({ raw: { signal: abortController.signal } })
// ^^^^^^^^^^^^^^^
.gql`
{
pokemon {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ import { showJson } from '../$/helpers.js'
import { publicGraphQLSchemaEndpoints } from '../$/helpers.js'

const graffle = Graffle
.create({ schema: publicGraphQLSchemaEndpoints.Pokemon })
.create()
.transport({ url: publicGraphQLSchemaEndpoints.Pokemon })
.anyware(({ exchange }) =>
exchange({
using: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@ import { Graffle } from '../../src/entrypoints/main.js'
import { publicGraphQLSchemaEndpoints, show } from '../$/helpers.js'

const graffle = Graffle
.create({
schema: publicGraphQLSchemaEndpoints.Pokemon,
.create()
.transport({
url: publicGraphQLSchemaEndpoints.Pokemon,
})
.anyware(({ pack }) => {
// eslint-disable-next-line
if (pack.input.transportType !== `http`) return pack()
return pack({
input: {
Expand Down
24 changes: 12 additions & 12 deletions examples/10_transport-http/transport-http_headers_raw__headers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,24 @@ import { show } from '../$/helpers.js'
import { publicGraphQLSchemaEndpoints } from '../$/helpers.js'

const graffle = Graffle
.create({
schema: publicGraphQLSchemaEndpoints.Pokemon,
transport: {
.create()
.transport({
url: publicGraphQLSchemaEndpoints.Pokemon,
headers: {
authorization: `Bearer MY_TOKEN`,
'x-something-to-unset': `true`,
},
raw: {
headers: {
authorization: `Bearer MY_TOKEN`,
'x-something-to-unset': `true`,
},
raw: {
headers: {
'x-from-raw': `true`,
},
'x-from-raw': `true`,
},
},
})
.with({
transport: { headers: { 'x-something-to-unset': `` } },
.transport({
headers: { 'x-something-to-unset': `` },
})
.anyware(({ exchange }) => {
// eslint-disable-next-line
if (exchange.input.transportType !== `http`) return exchange()
show(exchange.input.request.headers)
return exchange()
Expand Down
9 changes: 4 additions & 5 deletions examples/10_transport-http/transport-http_method-get.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,10 @@ import { Graffle } from '../../tests/_/schemas/pokemon/graffle/__.js'
import { show } from '../$/helpers.js'

const graffle = Graffle
.create({
transport: {
methodMode: `getReads`, // [!code highlight]
headers: { tenant: `nano` },
},
.create()
.transport({
methodMode: `getReads`, // [!code highlight]
headers: { tenant: `nano` },
})
.anyware(async ({ exchange }) => {
show(exchange.input.request)
Expand Down
11 changes: 5 additions & 6 deletions examples/10_transport-http/transport-http_raw.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,11 @@ import { show } from '../$/helpers.js'
import { publicGraphQLSchemaEndpoints } from '../$/helpers.js'

const graffle = Graffle
.create({
schema: publicGraphQLSchemaEndpoints.Pokemon,
transport: {
raw: {
mode: `cors`,
},
.create()
.transport({
url: publicGraphQLSchemaEndpoints.Pokemon,
raw: {
mode: `cors`,
},
})
.anyware(async ({ exchange }) => {
Expand Down
7 changes: 3 additions & 4 deletions examples/20_output/output_preset__standard-graphql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@
import { Graffle, Preset } from '../../src/entrypoints/main.js'
import { show } from '../$/show.js'

const graffle = Graffle.create({
schema: `...`,
output: Preset.traditionalGraphqlOutput,
})
const graffle = Graffle
.create({ output: Preset.traditionalGraphqlOutput })
.transport({ url: `...` })

const result = await graffle.gql(`{ query { thisWillError } }`).send()

Expand Down
8 changes: 5 additions & 3 deletions examples/30_gql/gql_gql-document-node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@ import { Throws } from '../../src/entrypoints/extensions/throws/runtime.js'
import { Graffle } from '../../src/entrypoints/main.js'
import { publicGraphQLSchemaEndpoints, show } from '../$/helpers.js'

const graffle = Graffle.create({
schema: publicGraphQLSchemaEndpoints.Pokemon,
})
const graffle = Graffle
.create()
.transport({
url: publicGraphQLSchemaEndpoints.Pokemon,
})
.use(Throws())
.use(Opentelemetry())

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ import { parse, type TypedQueryDocumentNode } from 'graphql'
import { Graffle } from '../../src/entrypoints/main.js'
import { publicGraphQLSchemaEndpoints, show } from '../$/helpers.js'

const graffle = Graffle.create({
schema: publicGraphQLSchemaEndpoints.Pokemon,
})
const graffle = Graffle.create()
.transport({
url: publicGraphQLSchemaEndpoints.Pokemon,
})

type Document = TypedQueryDocumentNode<
{
Expand Down
4 changes: 1 addition & 3 deletions examples/30_gql/gql_gql-string.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@
import { Graffle } from '../../src/entrypoints/main.js'
import { publicGraphQLSchemaEndpoints, show } from '../$/helpers.js'

const graffle = Graffle.create({
schema: publicGraphQLSchemaEndpoints.Pokemon,
})
const graffle = Graffle.create().transport({ url: publicGraphQLSchemaEndpoints.Pokemon })

const data = await graffle.gql`
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@
import { Graffle, type TypedDocument } from '../../src/entrypoints/main.js'
import { publicGraphQLSchemaEndpoints, show } from '../$/helpers.js'

const graffle = Graffle.create({
schema: publicGraphQLSchemaEndpoints.Pokemon,
})
const graffle = Graffle.create().transport({ url: publicGraphQLSchemaEndpoints.Pokemon })

/**
* @remarks Typically this type would come from your code generation tool.
Expand Down
6 changes: 5 additions & 1 deletion examples/40_other/transport-memory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import { GraphQLObjectType, GraphQLSchema, GraphQLString } from 'graphql'
import { Graffle } from '../../src/entrypoints/main.js'
import { TransportMemory } from '../../src/extensions/TransportMemory/TransportMemory.js'
import { showJson } from '../$/helpers.js'

const schema = new GraphQLSchema({
Expand All @@ -18,7 +19,10 @@ const schema = new GraphQLSchema({
}),
})

const graffle = Graffle.create({ schema })
const graffle = Graffle
.create()
.use(TransportMemory({ schema }))
.transport(`memory`)

const data = await graffle.gql`
{
Expand Down
4 changes: 3 additions & 1 deletion examples/50_anyware/anyware_jump-start__jump-start.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@ import { Graffle } from '../../src/entrypoints/main.js'
import { publicGraphQLSchemaEndpoints } from '../$/helpers.js'

Graffle
.create({ schema: publicGraphQLSchemaEndpoints.Pokemon })
.create()
.transport({ url: publicGraphQLSchemaEndpoints.Pokemon })
// Notice how we **start** with the `exchange` hook, skipping the `encode` and `pack` hooks.
.anyware(async ({ exchange }) => {
// ^^^^^^^^
// eslint-disable-next-line
if (exchange.input.transportType !== `http`) return exchange()

const mergedHeaders = new Headers(exchange.input.request.headers)
Expand Down
4 changes: 3 additions & 1 deletion examples/50_anyware/anyware_short-circuit__short-circuit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@ import { Graffle } from '../../src/entrypoints/main.js'
import { publicGraphQLSchemaEndpoints } from '../$/helpers.js'

Graffle
.create({ schema: publicGraphQLSchemaEndpoints.Pokemon })
.create()
.transport({ url: publicGraphQLSchemaEndpoints.Pokemon })
.anyware(async ({ encode }) => {
const { pack } = await encode()
const { exchange } = await pack()

// eslint-disable-next-line
if (exchange.input.transportType !== `http`) return exchange()

const mergedHeaders = new Headers(exchange.input.request.headers)
Expand Down
3 changes: 2 additions & 1 deletion examples/50_anyware/anyware_slot_slot-body__slot-body.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import { Graffle } from '../../src/entrypoints/main.js'
import { publicGraphQLSchemaEndpoints, show } from '../$/helpers.js'

const graffle = Graffle
.create({ schema: publicGraphQLSchemaEndpoints.Pokemon })
.create()
.transport({ url: publicGraphQLSchemaEndpoints.Pokemon })
.anyware(async ({ pack }) => {
return await pack({
using: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import { Graffle } from '../../src/entrypoints/main.js'
import { publicGraphQLSchemaEndpoints, show } from '../$/helpers.js'

const graffle = Graffle
.create({ schema: publicGraphQLSchemaEndpoints.Pokemon, transport: { methodMode: `getReads` } })
.create()
.transport({ url: publicGraphQLSchemaEndpoints.Pokemon, methodMode: `getReads` })
.anyware(async ({ pack }) => {
return await pack({
using: {
Expand Down
3 changes: 2 additions & 1 deletion examples/50_anyware/anyware_slot_slot-fetch__slot-fetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import { Graffle } from '../../src/entrypoints/main.js'
import { publicGraphQLSchemaEndpoints, show } from '../$/helpers.js'

const graffle = Graffle
.create({ schema: publicGraphQLSchemaEndpoints.Pokemon })
.create()
.transport({ url: publicGraphQLSchemaEndpoints.Pokemon })
.anyware(async ({ exchange }) => {
return await exchange({
using: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ Headers {
'content-type': 'application/json',
authorization: 'Bearer MY_TOKEN',
'x-from-raw': 'true'
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ ContextualError: There was an error in the core implementation of hook "exchange
context: { hookName: 'exchange', source: 'implementation' },
[cause]: TypeError: Failed to parse URL from ...
at new Request (node:internal/deps/undici/undici:XX:XX)
at Object.run (/some/path/to/httpTransport.ts:XX:XX:27)
at Object.run (/some/path/to/TransportHttp.ts:XX:XX:31)
... 6 lines matching cause stack trace ...
at async Module.run (/some/path/to/run.ts:XX:XX:10)
at async Object.send (/some/path/to/gql.ts:XX:XX:26) {
[cause]: TypeError: Invalid URL
at new URL (node:internal/url:XX:XX)
at new Request (node:internal/deps/undici/undici:XX:XX)
at Object.run (/some/path/to/httpTransport.ts:XX:XX:27)
at Object.run (/some/path/to/TransportHttp.ts:XX:XX:31)
at Object.run (/some/path/to/Pipeline.ts:XX:XX:51)
at runStep (/some/path/to/runStep.ts:XX:XX:37)
at runPipeline (/some/path/to/runPipeline.ts:XX:XX:8)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
---------------------------------------- SHOW ----------------------------------------
ContextualError: There was an error in the interceptor "anonymous" (use named functions to improve this error message) while running hook "encode".
at runPipeline (/some/path/to/runPipeline.ts:XX:XX:18)
at async <anonymous> (/some/path/to/runner.ts:XX:XX:20)
at async Module.run (/some/path/to/run.ts:XX:XX:10)
at async executeDocument (/some/path/to/requestMethods.ts:XX:XX:18)
at async executeRootField (/some/path/to/requestMethods.ts:XX:XX:18)
at async <anonymous> (/some/path/to/extension_throws__throws.ts:XX:XX:17) {
context: {
hookName: 'encode',
source: 'extension',
interceptorName: 'anonymous'
},
cause: Error: Something went wrong.
at <anonymous> (/some/path/to/extension_throws__throws.ts:XX:XX:11)
at applyBody (/some/path/to/runner.ts:XX:XX:28)
}
Loading