-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathindex.js
50 lines (44 loc) · 1.26 KB
/
index.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
// Modules to control application life and handle IPC
const { app, ipcMain } = require("electron");
const gqlmapi = require("../bin/electron-gqlmapi");
let serviceStarted = false;
function startService() {
gqlmapi.startService();
serviceStarted = true;
}
function stopService() {
serviceStarted = false;
gqlmapi.stopService();
}
exports.startGraphQL = function() {
// Register the IPC callbacks
ipcMain.handle("startService", startService);
ipcMain.handle("stopService", stopService);
ipcMain.handle("parseQuery", (_event, query) => gqlmapi.parseQuery(query));
ipcMain.handle("discardQuery", (_event, queryId) =>
gqlmapi.discardQuery(queryId)
);
ipcMain.on("fetchQuery", (event, queryId, operationName, variables) =>
gqlmapi.fetchQuery(
queryId,
operationName,
variables,
(payload) => {
if (serviceStarted) {
event.reply("fetched", queryId, payload);
}
},
() => {
if (serviceStarted) {
event.reply("completed", queryId);
}
}
)
);
ipcMain.handle("unsubscribe", (_event, queryId) =>
gqlmapi.unsubscribe(queryId)
);
// Quit when all windows are closed.
app.on("window-all-closed", stopService);
};
exports.preloadPath = require.resolve('./preload');