Skip to content

Commit aec075d

Browse files
authored
feat(extension/or-throw): add new extension (#1087)
1 parent beb702e commit aec075d

File tree

262 files changed

+2470
-1658
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

262 files changed

+2470
-1658
lines changed

eslint.config.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,9 @@ export default tsEslint.config({
2020
},
2121
rules: {
2222
['@typescript-eslint/only-throw-error']: 'off',
23+
['@typescript-eslint/no-unsafe-assignment']: 'off',
24+
['@typescript-eslint/no-unsafe-call']: 'off',
25+
['@typescript-eslint/no-unsafe-member-access']: 'off',
26+
['@typescript-eslint/ban-types']: 'off',
2327
},
2428
})

examples/$/generated-clients/atlas/modules/SchemaIndex.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import type * as Schema from './SchemaBuildtime.js'
44

55
export interface Index {
66
name: 'Atlas'
7+
RootTypesPresent: ['Query']
78
Root: {
89
Query: Schema.Root.Query
910
Mutation: null

examples/$/generated-clients/atlas/modules/SchemaRuntime.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ export const Query = $.Object$(`Query`, {
100100

101101
export const $Index = {
102102
name: 'Atlas' as const,
103+
RootTypesPresent: ['Query'] as const,
103104
Root: {
104105
Query,
105106
Mutation: null,

examples/$/generated-clients/pokemon/modules/SchemaIndex.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import type * as Schema from './SchemaBuildtime.js'
44

55
export interface Index {
66
name: 'Pokemon'
7+
RootTypesPresent: ['Query', 'Mutation']
78
Root: {
89
Query: Schema.Root.Query
910
Mutation: Schema.Root.Mutation

examples/$/generated-clients/pokemon/modules/SchemaRuntime.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ export const Query = $.Object$(`Query`, {
4747

4848
export const $Index = {
4949
name: 'Pokemon' as const,
50+
RootTypesPresent: ['Query', 'Mutation'] as const,
5051
Root: {
5152
Query,
5253
Mutation,

examples/$/show.ts

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,28 +6,27 @@ type Logger = typeof console.log | typeof globalThis.process.stdout.write
66

77
export const show = <$Logger extends Logger = typeof console.log>(
88
value: unknown,
9-
logger?: $Logger,
9+
subTitle?: string,
1010
): ReturnType<$Logger> => {
11-
const write = logger ?? console.log
11+
const write = console.log
1212
const inspected = inspect(value, { depth: null, colors: true })
13-
const message = renderShow(inspected)
13+
const message = renderShow(inspected, subTitle)
1414
return write(message) as ReturnType<$Logger>
1515
}
1616

1717
export const showJson = <$Logger extends Logger = typeof console.log>(
1818
value: unknown,
19-
logger?: $Logger,
2019
): ReturnType<$Logger> => {
21-
const write = logger ?? console.log
20+
const write = console.log
2221
const encoded = JSON.stringify(value, null, 2)
2322
const message = renderShow(encoded)
2423
return write(message) as ReturnType<$Logger>
2524
}
2625

2726
export const showPartition = `---------------------------------------- SHOW ----------------------------------------`
2827

29-
const renderShow = (value: string) => {
30-
return showPartition + '\n' + value
28+
const renderShow = (value: string, subTitle?: string) => {
29+
return showPartition + (subTitle ? `\n${subTitle}` : '') + '\n' + value
3130
}
3231

3332
export const interceptAndShowOutput = (): void => {
@@ -37,3 +36,10 @@ export const interceptAndShowOutput = (): void => {
3736
return originalWrite(renderShow(value))
3837
}
3938
}
39+
40+
export const interceptAndShowUncaughtErrors = () => {
41+
process.on('uncaughtException', (error) => {
42+
show(error, 'UNCAUGHT EXCEPTION:\n')
43+
process.exit(1)
44+
})
45+
}

examples/__outputs__/extension|extension_opentelemetry.output.txt

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@
99
}
1010
},
1111
instrumentationScope: { name: 'graffle', version: undefined, schemaUrl: undefined },
12-
traceId: '93ece70aa164958fd1b3d3c6c89e9f70',
13-
parentId: 'e3b3fd57f531674b',
12+
traceId: '62449852d475be9dce6a74f0b0555f54',
13+
parentId: 'b3ba100af8bce057',
1414
traceState: undefined,
1515
name: 'encode',
16-
id: '0f8e4e2d2fa7a1d1',
16+
id: 'bcca0b855b22b8af',
1717
kind: 0,
18-
timestamp: 1726068743834000,
19-
duration: 442.792,
18+
timestamp: 1726346409548000,
19+
duration: 448.042,
2020
attributes: {},
2121
status: { code: 0 },
2222
events: [],
@@ -33,14 +33,14 @@
3333
}
3434
},
3535
instrumentationScope: { name: 'graffle', version: undefined, schemaUrl: undefined },
36-
traceId: '93ece70aa164958fd1b3d3c6c89e9f70',
37-
parentId: 'e3b3fd57f531674b',
36+
traceId: '62449852d475be9dce6a74f0b0555f54',
37+
parentId: 'b3ba100af8bce057',
3838
traceState: undefined,
3939
name: 'pack',
40-
id: '37766e2e0fa6ea2e',
40+
id: '884350df7488294f',
4141
kind: 0,
42-
timestamp: 1726068743836000,
43-
duration: 808.5,
42+
timestamp: 1726346409551000,
43+
duration: 1024.667,
4444
attributes: {},
4545
status: { code: 0 },
4646
events: [],
@@ -57,14 +57,14 @@
5757
}
5858
},
5959
instrumentationScope: { name: 'graffle', version: undefined, schemaUrl: undefined },
60-
traceId: '93ece70aa164958fd1b3d3c6c89e9f70',
61-
parentId: 'e3b3fd57f531674b',
60+
traceId: '62449852d475be9dce6a74f0b0555f54',
61+
parentId: 'b3ba100af8bce057',
6262
traceState: undefined,
6363
name: 'exchange',
64-
id: 'ed9ae7aad6fd1e69',
64+
id: 'c5b5c072b7c8c20d',
6565
kind: 0,
66-
timestamp: 1726068743837000,
67-
duration: 329989.458,
66+
timestamp: 1726346409553000,
67+
duration: 194155.958,
6868
attributes: {},
6969
status: { code: 0 },
7070
events: [],
@@ -81,14 +81,14 @@
8181
}
8282
},
8383
instrumentationScope: { name: 'graffle', version: undefined, schemaUrl: undefined },
84-
traceId: '93ece70aa164958fd1b3d3c6c89e9f70',
85-
parentId: 'e3b3fd57f531674b',
84+
traceId: '62449852d475be9dce6a74f0b0555f54',
85+
parentId: 'b3ba100af8bce057',
8686
traceState: undefined,
8787
name: 'unpack',
88-
id: 'd0d9cbd74e358490',
88+
id: '6956cc361339e79b',
8989
kind: 0,
90-
timestamp: 1726068744168000,
91-
duration: 1907.291,
90+
timestamp: 1726346409747000,
91+
duration: 4696.875,
9292
attributes: {},
9393
status: { code: 0 },
9494
events: [],
@@ -105,14 +105,14 @@
105105
}
106106
},
107107
instrumentationScope: { name: 'graffle', version: undefined, schemaUrl: undefined },
108-
traceId: '93ece70aa164958fd1b3d3c6c89e9f70',
109-
parentId: 'e3b3fd57f531674b',
108+
traceId: '62449852d475be9dce6a74f0b0555f54',
109+
parentId: 'b3ba100af8bce057',
110110
traceState: undefined,
111111
name: 'decode',
112-
id: '51a5859eae82dd62',
112+
id: '5093bc556bcde250',
113113
kind: 0,
114-
timestamp: 1726068744170000,
115-
duration: 97.958,
114+
timestamp: 1726346409753000,
115+
duration: 286.459,
116116
attributes: {},
117117
status: { code: 0 },
118118
events: [],
@@ -129,14 +129,14 @@
129129
}
130130
},
131131
instrumentationScope: { name: 'graffle', version: undefined, schemaUrl: undefined },
132-
traceId: '93ece70aa164958fd1b3d3c6c89e9f70',
132+
traceId: '62449852d475be9dce6a74f0b0555f54',
133133
parentId: undefined,
134134
traceState: undefined,
135135
name: 'request',
136-
id: 'e3b3fd57f531674b',
136+
id: 'b3ba100af8bce057',
137137
kind: 0,
138-
timestamp: 1726068743834000,
139-
duration: 336135.125,
138+
timestamp: 1726346409547000,
139+
duration: 205724.167,
140140
attributes: {},
141141
status: { code: 0 },
142142
events: [],
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
---------------------------------------- SHOW ----------------------------------------
2+
ContextualError: There was an error in the extension "anonymous" (use named functions to improve this error message) while running hook "encode".
3+
at runPipeline (/some/path/to/runPipeline.ts:XX:XX)
4+
at async Object.run (/some/path/to/main.ts:XX:XX)
5+
at async run (/some/path/to/client.ts:XX:XX)
6+
at async executeRootType (/some/path/to/client.ts:XX:XX)
7+
at async executeRootTypeField (/some/path/to/client.ts:XX:XX)
8+
at async <anonymous> (/some/path/to/extension|extension_or-throw.ts:XX:XX) {
9+
context: {
10+
hookName: 'encode',
11+
source: 'extension',
12+
extensionName: 'anonymous'
13+
},
14+
cause: Error: Something went wrong.
15+
at <anonymous> (/some/path/to/extension|extension_or-throw.ts:XX:XX)
16+
at applyBody (/some/path/to/main.ts:XX:XX)
17+
}
18+
---------------------------------------- SHOW ----------------------------------------
19+
UNCAUGHT EXCEPTION:
20+
21+
ContextualError: There was an error in the extension "anonymous" (use named functions to improve this error message) while running hook "encode".
22+
at runPipeline (/some/path/to/runPipeline.ts:XX:XX)
23+
at async Object.run (/some/path/to/main.ts:XX:XX)
24+
at async run (/some/path/to/client.ts:XX:XX)
25+
at async executeRootType (/some/path/to/client.ts:XX:XX)
26+
at async executeRootTypeField (/some/path/to/client.ts:XX:XX)
27+
at async <anonymous> (/some/path/to/extension|extension_or-throw.ts:XX:XX) {
28+
context: {
29+
hookName: 'encode',
30+
source: 'extension',
31+
extensionName: 'anonymous'
32+
},
33+
cause: Error: Something went wrong.
34+
at <anonymous> (/some/path/to/extension|extension_or-throw.ts:XX:XX)
35+
at applyBody (/some/path/to/main.ts:XX:XX)
36+
}
Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
---------------------------------------- SHOW ----------------------------------------
22
{
3-
"data": {
4-
"foo": "bar"
5-
}
3+
"foo": "bar"
64
}

examples/__outputs__/output|output_envelope.output.txt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
headers: Headers {
2020
connection: 'keep-alive',
2121
'content-length': '119',
22-
'x-served-by': 'cache-yul1970045-YUL',
22+
'x-served-by': 'cache-yul1970038-YUL',
2323
'accept-ranges': 'bytes',
2424
date: 'Sun, 08 Sep 2024 18:13:26 GMT',
2525
'content-type': 'application/graphql-response+json; charset=utf-8',
@@ -32,13 +32,13 @@
3232
'alt-svc': 'h3=":443"; ma=86400',
3333
'access-control-allow-origin': '*',
3434
'x-powered-by': 'Stellate',
35-
age: '249539',
35+
age: '527204',
3636
'cache-control': 'public, s-maxage=2628000, stale-while-revalidate=2628000',
3737
'x-cache': 'HIT',
38-
'x-cache-hits': '5',
38+
'x-cache-hits': '33',
3939
'gcdn-cache': 'HIT',
40-
'stellate-rate-limit-budget-remaining': '41',
41-
'stellate-rate-limit-rules': '"IP limit";type="RequestCount";budget=50;limited=?0;remaining=41;refill=60',
40+
'stellate-rate-limit-budget-remaining': '46',
41+
'stellate-rate-limit-rules': '"IP limit";type="RequestCount";budget=50;limited=?0;remaining=46;refill=60',
4242
'stellate-rate-limit-decision': 'pass',
4343
'stellate-rate-limit-budget-required': '5',
4444
'content-encoding': 'br'

0 commit comments

Comments
 (0)