-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathloader.ts
More file actions
40 lines (36 loc) · 732 Bytes
/
loader.ts
File metadata and controls
40 lines (36 loc) · 732 Bytes
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
34
35
36
37
38
39
40
import { parse } from "graphql";
import { gql, GraphQLClient } from "graphql-request";
export default async function (
endpoint: string,
_: unknown,
conf: Record<string, { bearerToken: string }>
) {
const graphQLClient = new GraphQLClient(endpoint, {
headers: {
authorization: `Bearer ${conf[endpoint].bearerToken}`,
},
});
const query = gql`
query CodeGenWebhooks {
Webhook: _Webhook {
list {
name
fragment
entity {
id
}
}
}
}
`;
const data = await graphQLClient.request<any>(query);
const fragments = data.Webhook.list;
return parse(
fragments
.map(
(f: any) =>
`fragment ${f.name} on ${f.entity.id} @register ${f.fragment}`
)
.join("\n")
);
}