-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathGQLClient.ts
31 lines (27 loc) · 1.02 KB
/
GQLClient.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
import { NetworkFactory } from './Networking';
import { build_mutation_query, build_query } from './gqlquery/common';
export interface GQLClientInterface {
query(operation: string, variables: any, fields: string): Promise<any>
}
export class GQLNow implements GQLClientInterface {
private _url: string
private _headers: Object
constructor(url: string,headers:Object = {} ) {
this._url = url;
this._headers = headers
}
async query(operation: string, variables: any, fields: string): Promise<any> {
let q = await build_query(operation, variables, fields);
return this.network_request(q);
}
async mutation(operation: string, variables: any, fields: string): Promise<any> {
let q = await build_mutation_query(operation, variables, fields);
return this.network_request(q);
}
private async network_request(q: string) {
let net = NetworkFactory.createSimpleClient();
net.setHttpHeaders(this._headers);
let result = await net.post(this._url, { query: q });
return result.data;
}
}