-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgraphqlClient.js
245 lines (243 loc) · 4.75 KB
/
graphqlClient.js
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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
const { GraphQLClient, gql } = require("graphql-request");
const gClient = new GraphQLClient(process.env.GRAPHQL_ENDPOINT);
const GET_INVITE_BY_RAND = gql`
query InviteByRand($rand: String = "") {
portal_invite(where: {rand: {_eq: $rand}}) {
rand
data
id
}
}
`;
const QUERY_ROOM_LIST = gql`
query RoomList {
portal_room {
personal
active
id
name
members
}
}
`;
const QUERY_ROOM = gql`
query Room($id: String!) {
portal_room(where: { id: { _eq: $id } }) {
creator
personal
active
id
link
name
members
windows {
id
title
room
tabs {
title
id
url
icon
}
}
}
}
`;
const QUERY_WINDOW = gql`
query Window($id: uuid!) {
portal_window(where: { id: { _eq: $id } }) {
active
id
title
members
roomByRoom{
id
name
}
tabs {
title
id
url
icon
}
user{
id
level
username
}
}
}
`;
const WINDOW_LIST = gql`
query Windows($room: String!) {
portal_window(where: {room: {_eq: $room}},order_by: {updated_at: desc}) {
id
title
room
created_at
tabs {
id
icon
title
url
}
}
}
`;
const NEW_ROOM = gql`
mutation NewRoom($creator: String, $host: String!, $id: String!, $link: String, $members: jsonb, $name: String){
insert_portal_room(objects: {creator: $creator, host: $host, id: $id, link: $link, members: $members, name: $name}, on_conflict: {constraint: room_pkey, update_columns: [host,name,link]}) {
returning {
id
created_at
}
affected_rows
}
}
`;
const NEW_WINDOW = gql`
mutation NewWindow($room: String!, $title: String!){
insert_portal_window(objects: {room: $room, title: $title}) {
returning {
id
created_at
}
}
}
`;
const UPDATE_WIN_TITLE = gql`
mutation UpdateWinTitle($id: uuid!, $title: String!) {
update_portal_window(where: {id: {_eq: $id}}, _set: {title: $title}) {
affected_rows
returning {
id
title
}
}
}
`;
const UPDATE_ACTIVE = gql`
mutation UpdateActive($active: Boolean!, $id: String!) {
update_portal_room(_set: { active: $active }, where: { id: { _eq: $id } }) {
returning {
active
}
}
}
`;
const UPDATE_WINDOW_ACTIVE = gql`
mutation UpdateActive($active: Boolean!, $id: uuid!) {
update_portal_window(_set: { active: $active }, where: { id: { _eq: $id } }) {
returning {
active
}
}
}
`;
const REMOVE_WINDOW = gql`
mutation RemoveWindow($id: uuid!) {
delete_portal_window(where: {id: {_eq: $id}}) {
returning {
id
}
}
}
`;
const UPDATE_MEMBERS = gql`
mutation UpdateMembers($id: String!, $member: jsonb) {
update_portal_room(
_prepend: { members: $member }
where: { id: { _eq: $id } }
) {
returning {
members
}
}
}
`;
const UPDATE_WINDOW_MEMBERS = gql`
mutation UpdateMembers($id: uuid!, $member: jsonb) {
update_portal_window(
_prepend: { members: $member }
where: { id: { _eq: $id } }
) {
returning {
members
}
}
}
`;
const DELETE_TABS = gql`
mutation DeleteTabs($wid: uuid!) {
delete_portal_tab(where: {window: {_eq: $wid}}){
returning {
id
}
}
}
`;
const INSERT_TABS = gql`
mutation InsertTabs($tabs: [portal_tab_insert_input!]!) {
insert_portal_tab(objects: $tabs){
returning {
id
}
}
}
`;
const UPSERT_USER = gql`
mutation UpSertUser($objects: [portal_user_insert_input!]!) {
insert_portal_user(objects: $objects, on_conflict: {constraint: user_aid_key, update_columns: [username,email,nickname,avatar]}) {
affected_rows
returning {
aid
id
nickname
username
updated_at
created_at
avatar
}
}
}
`;
const UPDATE_USER_BY_AID = gql`
mutation UpsertByEmail($aid: String, $customer: String ) {
update_portal_user(where: {aid: {_eq: $aid}}, _set: {level: 1, customer: $customer}) {
affected_rows
returning {
aid
level
id
email
}
}
}
`;
const requestHeaders = {
"content-type": "application/json",
"x-hasura-admin-secret": process.env.GRAPHQL_SECRET,
};
const gRequest = (query, payload) =>
gClient.request(query, payload, requestHeaders);
module.exports = {
gRequest,
GET_INVITE_BY_RAND,
QUERY_ROOM_LIST,
WINDOW_LIST,
UPDATE_USER_BY_AID,
UPSERT_USER,
QUERY_ROOM,
QUERY_WINDOW,
UPDATE_ACTIVE,
UPDATE_WINDOW_ACTIVE,
UPDATE_MEMBERS,
UPDATE_WINDOW_MEMBERS,
NEW_ROOM,
NEW_WINDOW,
REMOVE_WINDOW,
DELETE_TABS,
INSERT_TABS,
UPDATE_WIN_TITLE
};