This repository was archived by the owner on Apr 15, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathapiServerClient.js
More file actions
119 lines (109 loc) · 3.83 KB
/
Copy pathapiServerClient.js
File metadata and controls
119 lines (109 loc) · 3.83 KB
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
import _ from 'lodash';
// eslint-disable-next-line import/no-unresolved
import { GraphQLClient, gql } from 'graphql-request';
import { defaultHeaders } from './apiutils.js';
export default (class ApiServerClient {
constructor(cortexUrl) {
this.cortexUrl = cortexUrl;
this.endpoint = `${cortexUrl}/fabric/v4/graphql`;
}
_client(token) {
return new GraphQLClient(this.endpoint, {
headers: defaultHeaders(token),
redirect: 'error',
});
}
/**
* Query project using graphql
* @param token
* @param projectId
* @return {Promise<any>}
*/
async getProject(token, projectId) {
const fetched = await this._client(token)
.request(gql`query { projectByName( name: "${projectId}" ){name, title, description}}`);
return _.get(fetched, 'projectByName');
}
/**
* Query project using graphql
* @param token
* @return {Promise<any>}
*/
async listProjects(token, filter, limit, skip, sort) {
const fetched = await this._client(token)
.request(gql`{
projects ( filter: "${filter}", limit: "${limit}", skip: "${skip}", sort: "${sort}" ) { name, title, description} }
`);
return _.get(fetched, 'projects', []);
}
/**
* Query project using graphql
* @param token
* @param projDef
* @return {Promise<any>}
*/
async createProject(token, projDef) {
const fetched = await this._client(token)
.request(gql`mutation NewProject($input: CreateProjectInput!) { createProject(input: $input){name}}`, { input: projDef });
return _.get(fetched, 'createProject', {});
}
/**
* Delete project using graphql
* @param token
* @param projectId
* @return {Promise<any>}
*/
async deleteProject(token, projectId) {
const fetched = await this._client(token)
.request(gql`mutation { deleteProject(name: "${projectId}") }`);
return _.get(fetched, 'deleteProject', {});
}
/**
* Fetch campaign using graphql
* @param projectId
* @param token
* @param campaignId
* @return {Promise<any>}
*/
async getCampaign(projectId, token, campaignId) {
const fetched = await this._client(token)
.request(gql`query { campaignByName( project: "${projectId}", name: "${campaignId}" ){name, title, description}}`);
return _.get(fetched, 'campaignByName');
}
/**
* Query campaign using graphql
* @param projectId
* @param token
* @return {Promise<any>}
*/
async listCampaigns(projectId, token, filter, limit, skip, sort) {
const fetched = await this._client(token)
.request(gql`{ campaigns ( project: "${projectId}", filter: "${filter}", limit: "${limit}", skip: "${skip}", sort: "${sort}" ) { name, title, description} }`);
return _.get(fetched, 'campaigns', []);
}
/**
* Query model list using graphql
* @param projectId
* @param offset
* @param limit
* @param token
* @return {Promise<any>}
*/
async listModels(projectId, offset, limit, token) {
const fetched = await this._client(token)
.request(gql`{ models ( project: "${projectId}", offset: ${offset}, limit: ${limit} ) { name, title, description } }`);
return _.get(fetched, 'models', []);
}
/**
* Query model description using graphql
* @param projectId
* @param name
* @param token
* @return {Promise<any>}
*/
async descModels(projectId, name, token) {
const fetched = await this._client(token)
.request(gql`{ modelByName ( project: "${projectId}", name: "${name}" ) { name, description, model_mode, source, status, title, type } }`);
return _.get(fetched, 'modelByName', []);
}
});