@webresto/graphql 1.3.0
Sign up to get free protection for your applications and to get access to all the features.
- package/.editorconfig +10 -0
- package/index.d.ts +3 -0
- package/index.js +22 -0
- package/index.ts +14 -0
- package/lib/afterHook.d.ts +1 -0
- package/lib/afterHook.js +24 -0
- package/lib/afterHook.ts +26 -0
- package/lib/afterHook.ts___graphql-transport-ws +138 -0
- package/lib/afterHook.ts___graphql-ws +133 -0
- package/lib/defaults.js +12 -0
- package/lib/errorWrapper.d.ts +4 -0
- package/lib/errorWrapper.js +13 -0
- package/lib/errorWrapper.ts +12 -0
- package/lib/eventHelper.d.ts +21 -0
- package/lib/eventHelper.js +32 -0
- package/lib/eventHelper.ts +35 -0
- package/lib/graphqlHelper.d.ts +115 -0
- package/lib/graphqlHelper.js +596 -0
- package/lib/graphqlHelper.ts +692 -0
- package/lib/initialize.d.ts +1 -0
- package/lib/initialize.js +22 -0
- package/lib/initialize.ts +21 -0
- package/notes.md +1976 -0
- package/package.json +47 -0
- package/readme.md +258 -0
- package/restApi.http +11 -0
- package/src/additionalResolvers.d.ts +19 -0
- package/src/additionalResolvers.js +114 -0
- package/src/additionalResolvers.ts +111 -0
- package/src/graphql.d.ts +7 -0
- package/src/graphql.js +144 -0
- package/src/graphql.ts +160 -0
- package/src/resolvers/cart.d.ts +123 -0
- package/src/resolvers/cart.js +176 -0
- package/src/resolvers/cart.ts +256 -0
- package/src/resolvers/checkout.d.ts +30 -0
- package/src/resolvers/checkout.js +226 -0
- package/src/resolvers/checkout.ts +242 -0
- package/src/resolvers/dishAndModifier.d.ts +2 -0
- package/src/resolvers/dishAndModifier.js +35 -0
- package/src/resolvers/dishAndModifier.ts +38 -0
- package/src/resolvers/maintenance.d.ts +9 -0
- package/src/resolvers/maintenance.js +12 -0
- package/src/resolvers/maintenance.ts +11 -0
- package/src/resolvers/paymentMethod.d.ts +9 -0
- package/src/resolvers/paymentMethod.js +22 -0
- package/src/resolvers/paymentMethod.ts +20 -0
- package/src/resolvers/restrictions.d.ts +9 -0
- package/src/resolvers/restrictions.js +24 -0
- package/src/resolvers/restrictions.ts +22 -0
- package/src/resolvers/streets.d.ts +9 -0
- package/src/resolvers/streets.js +16 -0
- package/src/resolvers/streets.ts +13 -0
- package/src/resolvers/subscriptions.d.ts +33 -0
- package/src/resolvers/subscriptions.js +52 -0
- package/src/resolvers/subscriptions.ts +63 -0
- package/test/.eslintrc +8 -0
- package/test/_bootstrap.js +29 -0
- package/test/fixtures/v0.12-app/.gitignore +11 -0
- package/test/fixtures/v0.12-app/.sailsrc +11 -0
- package/test/fixtures/v0.12-app/api/controllers/.gitkeep +0 -0
- package/test/fixtures/v0.12-app/api/models/.gitkeep +0 -0
- package/test/fixtures/v0.12-app/api/models/TestModel.js +22 -0
- package/test/fixtures/v0.12-app/api/responses/badRequest.js +76 -0
- package/test/fixtures/v0.12-app/api/responses/created.js +60 -0
- package/test/fixtures/v0.12-app/api/responses/forbidden.js +89 -0
- package/test/fixtures/v0.12-app/api/responses/notFound.js +94 -0
- package/test/fixtures/v0.12-app/api/responses/ok.js +60 -0
- package/test/fixtures/v0.12-app/api/responses/serverError.js +89 -0
- package/test/fixtures/v0.12-app/api/services/.gitkeep +0 -0
- package/test/fixtures/v0.12-app/app.js +73 -0
- package/test/fixtures/v0.12-app/config/bootstrap.js +6 -0
- package/test/fixtures/v0.12-app/config/connections.js +5 -0
- package/test/fixtures/v0.12-app/config/cors.js +78 -0
- package/test/fixtures/v0.12-app/config/csrf.js +64 -0
- package/test/fixtures/v0.12-app/config/env/development.js +10 -0
- package/test/fixtures/v0.12-app/config/env/production.js +16 -0
- package/test/fixtures/v0.12-app/config/globals.js +63 -0
- package/test/fixtures/v0.12-app/config/hookTimeout.js +8 -0
- package/test/fixtures/v0.12-app/config/http.js +93 -0
- package/test/fixtures/v0.12-app/config/i18n.js +57 -0
- package/test/fixtures/v0.12-app/config/log.js +29 -0
- package/test/fixtures/v0.12-app/config/models.js +3 -0
- package/test/fixtures/v0.12-app/config/policies.js +51 -0
- package/test/fixtures/v0.12-app/config/restoapi.js +3 -0
- package/test/fixtures/v0.12-app/config/restocore.js +39 -0
- package/test/fixtures/v0.12-app/config/routes.js +49 -0
- package/test/fixtures/v0.12-app/config/session.js +100 -0
- package/test/fixtures/v0.12-app/config/sockets.js +141 -0
- package/test/fixtures/v0.12-app/config/stateflow.js +4 -0
- package/test/fixtures/v0.12-app/config/views.js +95 -0
- package/test/fixtures/v0.12-app/package.json +34 -0
- package/test/fixtures/v0.12-app/views/403.ejs +68 -0
- package/test/fixtures/v0.12-app/views/404.ejs +68 -0
- package/test/fixtures/v0.12-app/views/500.ejs +73 -0
- package/test/fixtures/v0.12-app/views/homepage.ejs +74 -0
- package/test/fixtures/v0.12-app/views/layout.ejs +91 -0
- package/test/mocha.opts +2 -0
- package/test/readme.md +0 -0
- package/test/todo +0 -0
- package/test/tslint.json +18 -0
- package/test/unit/first.test.js +11 -0
- package/test/unit/sails_not_crash.test.js +3 -0
- package/todo.md +1 -0
- package/tsconfig.json +10 -0
package/.editorconfig
ADDED
package/index.d.ts
ADDED
package/index.js
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
'use strict';
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
3
|
+
if (k2 === undefined) k2 = k;
|
4
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
5
|
+
}) : (function(o, m, k, k2) {
|
6
|
+
if (k2 === undefined) k2 = k;
|
7
|
+
o[k2] = m[k];
|
8
|
+
}));
|
9
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
10
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
11
|
+
};
|
12
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
13
|
+
const helper = require('./lib/graphqlHelper').default;
|
14
|
+
module.exports = function (sails) {
|
15
|
+
return {
|
16
|
+
defaults: require('./lib/defaults'),
|
17
|
+
initialize: require('./lib/initialize').default(sails)
|
18
|
+
};
|
19
|
+
};
|
20
|
+
__exportStar(require("./lib/eventHelper"), exports);
|
21
|
+
__exportStar(require("./lib/graphqlHelper"), exports);
|
22
|
+
__exportStar(require("./lib/errorWrapper"), exports);
|
package/index.ts
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
'use strict';
|
2
|
+
|
3
|
+
const helper = require('./lib/graphqlHelper').default;
|
4
|
+
|
5
|
+
module.exports = function (sails) {
|
6
|
+
return {
|
7
|
+
defaults: require('./lib/defaults'),
|
8
|
+
initialize: require('./lib/initialize').default(sails)
|
9
|
+
};
|
10
|
+
};
|
11
|
+
|
12
|
+
export * from './lib/eventHelper';
|
13
|
+
export * from './lib/graphqlHelper';
|
14
|
+
export * from './lib/errorWrapper';
|
@@ -0,0 +1 @@
|
|
1
|
+
export default function (): Promise<void>;
|
package/lib/afterHook.js
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
const graphql_1 = require("../src/graphql");
|
4
|
+
let cache = null;
|
5
|
+
async function default_1() {
|
6
|
+
try {
|
7
|
+
sails.log.verbose('>>> graphql hook starting');
|
8
|
+
sails.on('clear_cache', async function () {
|
9
|
+
cache = null;
|
10
|
+
});
|
11
|
+
sails.on('lifted', async function () {
|
12
|
+
const graphServer = await graphql_1.default.init();
|
13
|
+
// inject middleware into express app
|
14
|
+
sails.hooks.http.app.use(graphServer.getMiddleware());
|
15
|
+
let layer = sails.hooks.http.app._router.stack.slice(-1)[0];
|
16
|
+
sails.hooks.http.app._router.stack.splice(1, 0, layer);
|
17
|
+
graphServer.installSubscriptionHandlers(sails.hooks.http.server);
|
18
|
+
});
|
19
|
+
}
|
20
|
+
catch (e) {
|
21
|
+
sails.log.error('graphql > afterHook > error1', e);
|
22
|
+
}
|
23
|
+
}
|
24
|
+
exports.default = default_1;
|
package/lib/afterHook.ts
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
import graphql from '../src/graphql';
|
2
|
+
let cache = null;
|
3
|
+
|
4
|
+
export default async function () {
|
5
|
+
try {
|
6
|
+
|
7
|
+
sails.log.verbose('>>> graphql hook starting');
|
8
|
+
sails.on('clear_cache', async function (){
|
9
|
+
cache = null;
|
10
|
+
});
|
11
|
+
sails.on('lifted', async function (){
|
12
|
+
const graphServer = await graphql.init();
|
13
|
+
|
14
|
+
// inject middleware into express app
|
15
|
+
sails.hooks.http.app.use(graphServer.getMiddleware());
|
16
|
+
let layer = sails.hooks.http.app._router.stack.slice(-1)[0]
|
17
|
+
sails.hooks.http.app._router.stack.splice(1, 0, layer)
|
18
|
+
graphServer.installSubscriptionHandlers(sails.hooks.http.server);
|
19
|
+
})
|
20
|
+
|
21
|
+
|
22
|
+
} catch (e) {
|
23
|
+
sails.log.error('graphql > afterHook > error1', e);
|
24
|
+
}
|
25
|
+
}
|
26
|
+
|
@@ -0,0 +1,138 @@
|
|
1
|
+
import graphql from "../src/graphql";
|
2
|
+
import * as helper from "./graphqlHelper";
|
3
|
+
import { useServer } from 'graphql-ws/lib/use/ws';
|
4
|
+
import { execute, subscribe } from "graphql";
|
5
|
+
import * as WebSocket from 'ws';
|
6
|
+
|
7
|
+
|
8
|
+
import { createServer } from 'graphql-transport-ws';
|
9
|
+
|
10
|
+
import * as url from "url";
|
11
|
+
import { formatApolloErrors } from "apollo-server-errors";
|
12
|
+
|
13
|
+
export default async function () {
|
14
|
+
try {
|
15
|
+
sails.log.verbose(">>> graphql hook starting");
|
16
|
+
sails.on("lifted", async function () {
|
17
|
+
const graphServer = await graphql.init();
|
18
|
+
|
19
|
+
// inject middleware into express app
|
20
|
+
sails.hooks.http.app.use(graphServer.getMiddleware());
|
21
|
+
let layer = sails.hooks.http.app._router.stack.slice(-1)[0];
|
22
|
+
sails.hooks.http.app._router.stack.splice(1, 0, layer);
|
23
|
+
// graphServer.installSubscriptionHandlers(sails.hooks.http.server);
|
24
|
+
|
25
|
+
// WebSocket
|
26
|
+
|
27
|
+
const schema = graphServer.schema;
|
28
|
+
|
29
|
+
const graphqlWS = new WebSocket.Server({ noServer: true });
|
30
|
+
console.log(graphqlWS)
|
31
|
+
// serve graphql
|
32
|
+
// useServer({ schema }, graphqlWS);
|
33
|
+
|
34
|
+
// const subscriptionServer = createServer(
|
35
|
+
// {
|
36
|
+
// schema,
|
37
|
+
// execute,
|
38
|
+
// subscribe,
|
39
|
+
// onConnect() {
|
40
|
+
// console.log("SubscriptionServer ready!");
|
41
|
+
// }
|
42
|
+
// },
|
43
|
+
// {
|
44
|
+
// noServer: true,
|
45
|
+
// }
|
46
|
+
// );
|
47
|
+
|
48
|
+
|
49
|
+
// const subscriptionServer = SubscriptionServer.create(
|
50
|
+
// {
|
51
|
+
// schema,
|
52
|
+
// execute,
|
53
|
+
// subscribe,
|
54
|
+
// onConnect:(connectionParams: Object) => ({ ...connectionParams }),
|
55
|
+
// // onDisconnect: onDisconnect,
|
56
|
+
// onOperation: async (
|
57
|
+
// message: { payload: any },
|
58
|
+
// connection: ExecutionParams,
|
59
|
+
// ) => {
|
60
|
+
// connection.formatResponse = (value: any) => ({
|
61
|
+
// ...value,
|
62
|
+
// // errors:
|
63
|
+
// // value.errors &&
|
64
|
+
// // formatApolloErrors([...value.errors], {
|
65
|
+
// // formatter: this.requestOptions.formatError,
|
66
|
+
// // debug: this.requestOptions.debug,
|
67
|
+
// // }),
|
68
|
+
// });
|
69
|
+
|
70
|
+
// // connection.formatError = this.requestOptions.formatError;
|
71
|
+
// console.log("<><><><",this.context, connection)
|
72
|
+
// let context: any = this.context ? this.context : { connection };
|
73
|
+
|
74
|
+
// try {
|
75
|
+
// context =
|
76
|
+
// typeof this.context === 'function'
|
77
|
+
// ? await this.context({ connection, payload: message.payload })
|
78
|
+
// : context;
|
79
|
+
// } catch (e) {
|
80
|
+
// // throw formatApolloErrors([e], {
|
81
|
+
// // formatter: this.requestOptions.formatError,
|
82
|
+
// // debug: this.requestOptions.debug,
|
83
|
+
// // })[0];
|
84
|
+
// }
|
85
|
+
|
86
|
+
// return { ...connection, context };
|
87
|
+
// },
|
88
|
+
// // keepAlive,
|
89
|
+
// // validationRules: this.requestOptions.validationRules,
|
90
|
+
// },
|
91
|
+
// {
|
92
|
+
// noServer: true,
|
93
|
+
// }
|
94
|
+
// );
|
95
|
+
|
96
|
+
//@ts-ignore we need to access the private field which typescript does not like
|
97
|
+
// const wsServer: WebSocket.Server = subscriptionServer.wsServer;
|
98
|
+
const upgradeHandler = (req, socket, head) => {
|
99
|
+
if (!req.url) return;
|
100
|
+
const pathname = url.parse(req.url).pathname;
|
101
|
+
|
102
|
+
if (!pathname) return;
|
103
|
+
|
104
|
+
|
105
|
+
// if (pathname === '/graphql') {
|
106
|
+
// return graphqlWS.handleUpgrade(request, socket, head, (client) => {
|
107
|
+
// graphqlWS.emit('connection', client, request);
|
108
|
+
// });
|
109
|
+
// }
|
110
|
+
|
111
|
+
console.log(pathname)
|
112
|
+
if (pathname.startsWith("/graphql")) {
|
113
|
+
console.log(">>>>>>>>>>>>>>>>>>>..")
|
114
|
+
|
115
|
+
graphqlWS.handleUpgrade(req, socket, head, (ws) => {
|
116
|
+
console.log(">>>>>>>>>>>>>>>>>>>..111")
|
117
|
+
graphqlWS.emit('connection', ws, req);
|
118
|
+
});
|
119
|
+
}
|
120
|
+
};
|
121
|
+
|
122
|
+
sails.hooks.http.server.on("upgrade", upgradeHandler);
|
123
|
+
|
124
|
+
createServer(
|
125
|
+
{
|
126
|
+
schema,
|
127
|
+
execute,
|
128
|
+
subscribe,
|
129
|
+
},
|
130
|
+
graphqlWS,
|
131
|
+
);
|
132
|
+
|
133
|
+
|
134
|
+
});
|
135
|
+
} catch (e) {
|
136
|
+
sails.log.error("graphql > afterHook > error1", e);
|
137
|
+
}
|
138
|
+
}
|
@@ -0,0 +1,133 @@
|
|
1
|
+
import graphql from "../src/graphql";
|
2
|
+
import * as helper from "./graphqlHelper";
|
3
|
+
import { useServer } from 'graphql-ws/lib/use/ws';
|
4
|
+
import { execute, subscribe } from "graphql";
|
5
|
+
import * as ws from "ws";
|
6
|
+
const WebSocketServer = ws.Server
|
7
|
+
|
8
|
+
import * as url from "url";
|
9
|
+
import { formatApolloErrors } from "apollo-server-errors";
|
10
|
+
|
11
|
+
export default async function () {
|
12
|
+
try {
|
13
|
+
sails.log.verbose(">>> graphql hook starting");
|
14
|
+
sails.on("lifted", async function () {
|
15
|
+
const graphServer = await graphql.init();
|
16
|
+
|
17
|
+
// inject middleware into express app
|
18
|
+
sails.hooks.http.app.use(graphServer.getMiddleware());
|
19
|
+
let layer = sails.hooks.http.app._router.stack.slice(-1)[0];
|
20
|
+
sails.hooks.http.app._router.stack.splice(1, 0, layer);
|
21
|
+
// graphServer.installSubscriptionHandlers(sails.hooks.http.server);
|
22
|
+
|
23
|
+
// WebSocket
|
24
|
+
|
25
|
+
const schema = graphServer.schema;
|
26
|
+
|
27
|
+
const graphqlWS = new WebSocketServer({ noServer: true });
|
28
|
+
|
29
|
+
// serve graphql
|
30
|
+
useServer({ schema }, graphqlWS);
|
31
|
+
|
32
|
+
// const subscriptionServer = SubscriptionServer.create(
|
33
|
+
// {
|
34
|
+
// schema,
|
35
|
+
// execute,
|
36
|
+
// subscribe,
|
37
|
+
// onConnect() {
|
38
|
+
// console.log("SubscriptionServer ready!");
|
39
|
+
// },
|
40
|
+
// onOperation: async (
|
41
|
+
// message: { payload: any },
|
42
|
+
// connection: ExecutionParams
|
43
|
+
// ) => {
|
44
|
+
// connection.formatResponse = (value: any) => ({
|
45
|
+
// ...value
|
46
|
+
// });
|
47
|
+
// console.log("<><><><",this.context)
|
48
|
+
// let context: any = this.context ? this.context : { connection };
|
49
|
+
|
50
|
+
// try {
|
51
|
+
// context =
|
52
|
+
// typeof this.context === "function"
|
53
|
+
// ? await this.context({ connection, payload: message.payload })
|
54
|
+
// : context;
|
55
|
+
// } catch (e) {
|
56
|
+
// console.log(e)
|
57
|
+
// }
|
58
|
+
|
59
|
+
// return { ...connection, context };
|
60
|
+
// },
|
61
|
+
// },
|
62
|
+
// {
|
63
|
+
// noServer: true,
|
64
|
+
// }
|
65
|
+
// );
|
66
|
+
|
67
|
+
// const subscriptionServer = SubscriptionServer.create(
|
68
|
+
// {
|
69
|
+
// schema,
|
70
|
+
// execute,
|
71
|
+
// subscribe,
|
72
|
+
// onConnect:(connectionParams: Object) => ({ ...connectionParams }),
|
73
|
+
// // onDisconnect: onDisconnect,
|
74
|
+
// onOperation: async (
|
75
|
+
// message: { payload: any },
|
76
|
+
// connection: ExecutionParams,
|
77
|
+
// ) => {
|
78
|
+
// connection.formatResponse = (value: any) => ({
|
79
|
+
// ...value,
|
80
|
+
// // errors:
|
81
|
+
// // value.errors &&
|
82
|
+
// // formatApolloErrors([...value.errors], {
|
83
|
+
// // formatter: this.requestOptions.formatError,
|
84
|
+
// // debug: this.requestOptions.debug,
|
85
|
+
// // }),
|
86
|
+
// });
|
87
|
+
|
88
|
+
// // connection.formatError = this.requestOptions.formatError;
|
89
|
+
// console.log("<><><><",this.context, connection)
|
90
|
+
// let context: any = this.context ? this.context : { connection };
|
91
|
+
|
92
|
+
// try {
|
93
|
+
// context =
|
94
|
+
// typeof this.context === 'function'
|
95
|
+
// ? await this.context({ connection, payload: message.payload })
|
96
|
+
// : context;
|
97
|
+
// } catch (e) {
|
98
|
+
// // throw formatApolloErrors([e], {
|
99
|
+
// // formatter: this.requestOptions.formatError,
|
100
|
+
// // debug: this.requestOptions.debug,
|
101
|
+
// // })[0];
|
102
|
+
// }
|
103
|
+
|
104
|
+
// return { ...connection, context };
|
105
|
+
// },
|
106
|
+
// // keepAlive,
|
107
|
+
// // validationRules: this.requestOptions.validationRules,
|
108
|
+
// },
|
109
|
+
// {
|
110
|
+
// noServer: true,
|
111
|
+
// }
|
112
|
+
// );
|
113
|
+
|
114
|
+
//@ts-ignore we need to access the private field which typescript does not like
|
115
|
+
// const wsServer: WebSocket.Server = subscriptionServer.wsServer;
|
116
|
+
const upgradeHandler = (req, socket, head) => {
|
117
|
+
if (!req.url) return;
|
118
|
+
const pathname = url.parse(req.url).pathname;
|
119
|
+
|
120
|
+
if (!pathname) return;
|
121
|
+
|
122
|
+
if (pathname.startsWith("/graphql")) {
|
123
|
+
graphqlWS.handleUpgrade(req, socket, head, (ws) => {
|
124
|
+
graphqlWS.emit("connection", ws, req);
|
125
|
+
});
|
126
|
+
}
|
127
|
+
};
|
128
|
+
sails.hooks.http.server.on("upgrade", upgradeHandler);
|
129
|
+
});
|
130
|
+
} catch (e) {
|
131
|
+
sails.log.error("graphql > afterHook > error1", e);
|
132
|
+
}
|
133
|
+
}
|
package/lib/defaults.js
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.Error = void 0;
|
4
|
+
const apollo_server_errors_1 = require("apollo-server-errors");
|
5
|
+
class Error extends apollo_server_errors_1.ApolloError {
|
6
|
+
constructor(code, message) {
|
7
|
+
if (process.env.NODE_ENV == "production" && code === "INTERNAL_ERROR")
|
8
|
+
message = 'Что-то пошло не так';
|
9
|
+
super(message, code);
|
10
|
+
Object.defineProperty(this, 'name', { value: '' });
|
11
|
+
}
|
12
|
+
}
|
13
|
+
exports.Error = Error;
|
@@ -0,0 +1,12 @@
|
|
1
|
+
import { ApolloError } from 'apollo-server-errors';
|
2
|
+
|
3
|
+
export class Error extends ApolloError {
|
4
|
+
constructor(code?: string, message?: string) {
|
5
|
+
if (process.env.NODE_ENV == "production" && code === "INTERNAL_ERROR")
|
6
|
+
message = 'Что-то пошло не так';
|
7
|
+
super(message, code);
|
8
|
+
|
9
|
+
|
10
|
+
Object.defineProperty(this, 'name', { value: '' });
|
11
|
+
}
|
12
|
+
}
|
@@ -0,0 +1,21 @@
|
|
1
|
+
declare const _default: {
|
2
|
+
sendMessage: typeof sendMessage;
|
3
|
+
sendAction: typeof sendAction;
|
4
|
+
};
|
5
|
+
export default _default;
|
6
|
+
export { sendMessage, sendAction };
|
7
|
+
declare function sendMessage(orderId: String, message: any): void;
|
8
|
+
/**
|
9
|
+
*
|
10
|
+
* @param orderId
|
11
|
+
* @param action - obj {type: String, data: Json}
|
12
|
+
*
|
13
|
+
* @example
|
14
|
+
* {
|
15
|
+
* type: "PaymentRedirect",
|
16
|
+
* data: {
|
17
|
+
* url: "somelink.com/"
|
18
|
+
* }
|
19
|
+
* }
|
20
|
+
*/
|
21
|
+
declare function sendAction(orderId: String, action: any): void;
|
@@ -0,0 +1,32 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.sendAction = exports.sendMessage = void 0;
|
4
|
+
const graphql_1 = require("../src/graphql");
|
5
|
+
// import * as gql from '@webresto/graphql';
|
6
|
+
exports.default = {
|
7
|
+
sendMessage,
|
8
|
+
sendAction
|
9
|
+
};
|
10
|
+
function sendMessage(orderId, message) {
|
11
|
+
const pubsub = graphql_1.default.getPubsub();
|
12
|
+
pubsub.publish("message", { orderId, message });
|
13
|
+
}
|
14
|
+
exports.sendMessage = sendMessage;
|
15
|
+
/**
|
16
|
+
*
|
17
|
+
* @param orderId
|
18
|
+
* @param action - obj {type: String, data: Json}
|
19
|
+
*
|
20
|
+
* @example
|
21
|
+
* {
|
22
|
+
* type: "PaymentRedirect",
|
23
|
+
* data: {
|
24
|
+
* url: "somelink.com/"
|
25
|
+
* }
|
26
|
+
* }
|
27
|
+
*/
|
28
|
+
function sendAction(orderId, action) {
|
29
|
+
const pubsub = graphql_1.default.getPubsub();
|
30
|
+
pubsub.publish("action", { orderId, action });
|
31
|
+
}
|
32
|
+
exports.sendAction = sendAction;
|
@@ -0,0 +1,35 @@
|
|
1
|
+
import graphql from '../src/graphql';
|
2
|
+
// import * as gql from '@webresto/graphql';
|
3
|
+
|
4
|
+
export default {
|
5
|
+
sendMessage,
|
6
|
+
sendAction
|
7
|
+
}
|
8
|
+
export {
|
9
|
+
sendMessage,
|
10
|
+
sendAction
|
11
|
+
}
|
12
|
+
|
13
|
+
function sendMessage(orderId: String, message: any) {
|
14
|
+
const pubsub = graphql.getPubsub();
|
15
|
+
pubsub.publish("message", {orderId, message});
|
16
|
+
}
|
17
|
+
|
18
|
+
/**
|
19
|
+
*
|
20
|
+
* @param orderId
|
21
|
+
* @param action - obj {type: String, data: Json}
|
22
|
+
*
|
23
|
+
* @example
|
24
|
+
* {
|
25
|
+
* type: "PaymentRedirect",
|
26
|
+
* data: {
|
27
|
+
* url: "somelink.com/"
|
28
|
+
* }
|
29
|
+
* }
|
30
|
+
*/
|
31
|
+
|
32
|
+
function sendAction(orderId: String, action: any) {
|
33
|
+
const pubsub = graphql.getPubsub();
|
34
|
+
pubsub.publish("action", {orderId, action});
|
35
|
+
}
|
@@ -0,0 +1,115 @@
|
|
1
|
+
/// <reference types="@webresto/core/libs/globalTypes" />
|
2
|
+
/**
|
3
|
+
* Добавляет модель в список моделей для создания типов схемы graphql
|
4
|
+
*
|
5
|
+
*
|
6
|
+
* @param modelName string
|
7
|
+
* @returns void
|
8
|
+
*/
|
9
|
+
declare function addModel(modelName: string): void;
|
10
|
+
declare function addType(typeString: String): void;
|
11
|
+
/**
|
12
|
+
* Мержит новый резолвер с объектом резолверов. Новый резолвер заменит старый при совпадении имен
|
13
|
+
*
|
14
|
+
* @param resolvers
|
15
|
+
* resolverExample = {
|
16
|
+
* def: "user(id: String)",
|
17
|
+
* fn: function (parent, args, context) {
|
18
|
+
* return User.find({id: args.id})
|
19
|
+
* }
|
20
|
+
* }
|
21
|
+
*/
|
22
|
+
declare function addResolvers(resolvers: Object): void;
|
23
|
+
/**
|
24
|
+
* Сканирует все модели sails и добавляет их в список моделей для создания типов схемы graphql
|
25
|
+
*/
|
26
|
+
declare function addAllSailsModels(): void;
|
27
|
+
/**
|
28
|
+
* Добавляет массив с исключениями к текущему списку
|
29
|
+
* Варианты:
|
30
|
+
* 1. ["Order.field"] - исключает поле field в модели Order
|
31
|
+
* 2. ["Order"] - исключает модель Order полностью
|
32
|
+
* 3. ["field] - исключает поле field из всех моделей
|
33
|
+
*
|
34
|
+
* @param list array<string>
|
35
|
+
*/
|
36
|
+
declare function addToBlackList(list: Array<string>): void;
|
37
|
+
/**
|
38
|
+
* Добавляет в указаную модель новое поле
|
39
|
+
* Пример: addCustomField("Order", "customField: String")
|
40
|
+
*
|
41
|
+
* @param model string
|
42
|
+
* @param field string
|
43
|
+
*/
|
44
|
+
declare function addCustomField(model: any, field: any): void;
|
45
|
+
/**
|
46
|
+
* Добавляет в список автозамены поле.
|
47
|
+
* Пример: addToReplaceList("Dish.image", "image: [Image]");
|
48
|
+
*
|
49
|
+
* @param model string
|
50
|
+
* @param field string
|
51
|
+
*/
|
52
|
+
declare function addToReplaceList(model: any, field: any): void;
|
53
|
+
/**
|
54
|
+
* Сканирует указанную директорию и добавляет найденные резолверсы в схему graphql
|
55
|
+
*
|
56
|
+
* @param dir
|
57
|
+
*/
|
58
|
+
declare function addDirResolvers(dir: any): void;
|
59
|
+
/**
|
60
|
+
* Запускает генерацию схемы и резолверсов
|
61
|
+
* Возвращает готовые данные для использования при инициализации apollo server
|
62
|
+
*
|
63
|
+
* @returns {schemaTypes, schemaResolvers}
|
64
|
+
*/
|
65
|
+
declare function getSchema(): {
|
66
|
+
typeDefs: string;
|
67
|
+
resolvers: Resolvers;
|
68
|
+
};
|
69
|
+
/**
|
70
|
+
* Добавляет whiteList
|
71
|
+
* Пример: setWhiteList({
|
72
|
+
page: ['query'],
|
73
|
+
promotion: ['query'],
|
74
|
+
maintenance: ['query', 'subscription']
|
75
|
+
})
|
76
|
+
*
|
77
|
+
* @param list
|
78
|
+
*/
|
79
|
+
declare function setWhiteList(list: Object): void;
|
80
|
+
/**
|
81
|
+
* Генерирует резолвер для модели. Учитывает список исключений и whiteList
|
82
|
+
*
|
83
|
+
* @param modelname string
|
84
|
+
* @returns void
|
85
|
+
*/
|
86
|
+
declare function addModelResolver(modelname: any): void;
|
87
|
+
declare const _default: {
|
88
|
+
addModel: typeof addModel;
|
89
|
+
addType: typeof addType;
|
90
|
+
addResolvers: typeof addResolvers;
|
91
|
+
getSchema: typeof getSchema;
|
92
|
+
addToBlackList: typeof addToBlackList;
|
93
|
+
addCustomField: typeof addCustomField;
|
94
|
+
addToReplaceList: typeof addToReplaceList;
|
95
|
+
addAllSailsModels: typeof addAllSailsModels;
|
96
|
+
addDirResolvers: typeof addDirResolvers;
|
97
|
+
addModelResolver: typeof addModelResolver;
|
98
|
+
setWhiteList: typeof setWhiteList;
|
99
|
+
};
|
100
|
+
export default _default;
|
101
|
+
export { addModel, addType, addResolvers, getSchema, addToBlackList, addCustomField, addToReplaceList, addAllSailsModels, addDirResolvers, addModelResolver, setWhiteList };
|
102
|
+
interface Resolvers {
|
103
|
+
Query?: Resolver;
|
104
|
+
Mutation?: Resolver;
|
105
|
+
Subscription?: Resolver;
|
106
|
+
}
|
107
|
+
interface Resolver {
|
108
|
+
[name: string]: {
|
109
|
+
def?: string;
|
110
|
+
fn?: Object;
|
111
|
+
subscribe?: Object;
|
112
|
+
resolve?: Object;
|
113
|
+
[x: string]: Object;
|
114
|
+
};
|
115
|
+
}
|