-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlist.ts
50 lines (44 loc) · 1.48 KB
/
list.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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import { InMemoryCache, IntrospectionFragmentMatcher } from 'apollo-cache-inmemory';
import { ApolloClient } from 'apollo-client';
import { setContext } from 'apollo-link-context';
import { HttpLink } from 'apollo-link-http';
import 'cross-fetch/polyfill';
import { organizationQuery } from './queries/organization';
if (!process.env.KITEMAKER_TOKEN) {
console.error(
'Could not find Kitemaker token. Make sure the KITEMAKER_TOKEN environment variable is set.'
);
process.exit(-1);
}
const host = process.env.KITEMAKER_HOST ?? 'https://toil.kitemaker.co';
const httpLink = new HttpLink({
uri: `${host}/developers/graphql`,
});
const authLink = setContext((_, { headers }) => {
return {
headers: {
...headers,
authorization: `Bearer ${process.env.KITEMAKER_TOKEN}`,
},
};
});
const fragmentMatcher = new IntrospectionFragmentMatcher({
introspectionQueryResultData: { __schema: { types: [] } },
});
const client = new ApolloClient({
link: authLink.concat(httpLink),
cache: new InMemoryCache({ fragmentMatcher }),
});
async function list() {
try {
const result = await client.query({ query: organizationQuery });
if (result.errors) {
console.error('Unable to dump spaces and labels', JSON.stringify(result.errors, null, ' '));
process.exit(-1);
}
console.log(JSON.stringify(result.data.organization, null, ' '));
} catch (e) {
console.error('Error dumping spaces and labels', e.message, JSON.stringify(e, null, ' '));
}
}
list();