-
Notifications
You must be signed in to change notification settings - Fork 3
/
index.ts
38 lines (33 loc) · 823 Bytes
/
index.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
import gql from 'graphql-tag';
import nodeFetch from 'node-fetch';
import { ApolloClient, HttpLink, InMemoryCache } from 'apollo-client-preset';
import * as dotenv from 'dotenv';
import { MyLoginQuery } from './schema';
dotenv.config();
(async () => {
try {
const client = new ApolloClient({
link: new HttpLink({
uri: 'https://api.github.com/graphql',
fetch: nodeFetch,
headers: {
authorization: `bearer ${process.env.GITHUB_TOKEN}`,
},
}),
cache: new InMemoryCache(),
});
const query = gql`
query MyLogin {
viewer {
login
}
}
`;
const response = await client.query<MyLoginQuery>({
query,
});
console.log(response.data.viewer.login);
} catch (err) {
console.log(err);
}
})();