forked from graffle-js/graffle
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy patherror-handling.ts
33 lines (29 loc) · 918 Bytes
/
error-handling.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import { request } from '../mod.ts'
; (async function () {
const endpoint = 'https://fruits-api.netlify.app/graphql'
const query = /* GraphQL */ `
{
filterFruitsFam(family: "Rosaceae") {
id
treename # "Cannot query field 'treename' on type 'Actor'. Did you mean 'tree_name'?"
fruit_name
family
}
}`
interface Fruit {
"id": string;
"tree_name": string;
"fruit_name": string;
"family": string;
}
interface TData {
filterFruitsFam: Fruit[]
}
try {
const data = await request<TData>(endpoint, query)
console.log(JSON.stringify(data, undefined, 2))
} catch (error) {
console.error(JSON.stringify(error, undefined, 2))
Deno.exit(0) // We use 0 instead of 1 because we don't want to cause an error in the github actions workflow
}
})().catch((error) => console.error(error))