forked from wundergraph/wundergraph
-
Notifications
You must be signed in to change notification settings - Fork 0
/
client.ts
38 lines (36 loc) · 1.02 KB
/
client.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 fetch from 'node-fetch';
import { createClient } from './.wundergraph/generated/client';
async function main() {
const client = createClient({
// The URL of your WunderGraph server
baseURL: 'http://localhost:9991',
// The fetch implementation to use. Defaults to the global fetch.
// Fetch is provided by Node.js only with version 18.0.0 and above.
// This example use a polyfill for backwards compatibility.
customFetch: fetch as any,
// Additional headers to send with every request. Defaults to an empty object.
extraHeaders: {},
});
// graphql operation
const result = await client.query({
operationName: 'Countries',
input: {
filter: {
code: { eq: 'AD' },
},
},
});
// ts operation
const result2 = await client.query({
operationName: 'users/get',
input: {
id: '1',
},
});
const andorra = result.data?.countries_countries[0];
const user = result2.data;
console.log({ andorra, user });
}
main()
.then(() => console.log('done'))
.catch((err) => console.error('error', err));