@orion-js/graphql 3.3.24 → 3.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/buildSchema/getSubscriptions/index.js +2 -2
- package/lib/buildSchema/getType/getScalar.js +5 -1
- package/lib/getApolloOptions/index.d.ts +2 -2
- package/lib/getApolloOptions/index.js +12 -3
- package/lib/index.d.ts +1 -0
- package/lib/index.js +6 -1
- package/lib/service/index.js +5 -1
- package/lib/service/subscription.js +4 -1
- package/lib/service/subscription.test.js +1 -0
- package/lib/startGraphQL.js +15 -53
- package/lib/startGraphiQL.d.ts +2 -2
- package/lib/startWebsocket.d.ts +10 -3
- package/lib/startWebsocket.js +41 -23
- package/lib/startWebsocket.test.js +49 -17
- package/lib/subscription/index.js +4 -4
- package/lib/types/index.js +5 -1
- package/lib/types/startGraphQL.d.ts +4 -5
- package/lib/types/subscription.d.ts +3 -2
- package/package.json +27 -22
|
@@ -10,10 +10,10 @@ async function default_1(options) {
|
|
|
10
10
|
const fields = {};
|
|
11
11
|
for (const key of Object.keys(subscriptions)) {
|
|
12
12
|
const subscription = subscriptions[key];
|
|
13
|
-
subscription.
|
|
13
|
+
subscription.name = subscription.name || key;
|
|
14
14
|
const type = await (0, getType_1.default)(subscription.returns, options);
|
|
15
15
|
const args = await (0, getArgs_1.default)(subscription.params);
|
|
16
|
-
fields[
|
|
16
|
+
fields[subscription.name] = {
|
|
17
17
|
type,
|
|
18
18
|
args,
|
|
19
19
|
async subscribe(root, params, viewer) {
|
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
3
|
if (k2 === undefined) k2 = k;
|
|
4
|
-
Object.
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
5
9
|
}) : (function(o, m, k, k2) {
|
|
6
10
|
if (k2 === undefined) k2 = k;
|
|
7
11
|
o[k2] = m[k];
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { StartGraphQLOptions } from '../types/startGraphQL';
|
|
2
|
-
import {
|
|
3
|
-
export default function (options: StartGraphQLOptions): Promise<
|
|
2
|
+
import { ApolloServerOptions } from '@apollo/server';
|
|
3
|
+
export default function (options: StartGraphQLOptions): Promise<ApolloServerOptions<any>>;
|
|
@@ -5,13 +5,22 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
const buildSchema_1 = __importDefault(require("../buildSchema"));
|
|
7
7
|
const formatError_1 = __importDefault(require("./formatError"));
|
|
8
|
+
const lodash_1 = require("lodash");
|
|
8
9
|
async function default_1(options) {
|
|
9
10
|
const schema = await (0, buildSchema_1.default)(options);
|
|
11
|
+
const passedOptions = (0, lodash_1.omit)(options, [
|
|
12
|
+
'resolvers',
|
|
13
|
+
'modelResolvers',
|
|
14
|
+
'subscriptions',
|
|
15
|
+
'executeGraphQLCache',
|
|
16
|
+
'useGraphiql',
|
|
17
|
+
'app',
|
|
18
|
+
'pubsub'
|
|
19
|
+
]);
|
|
10
20
|
return {
|
|
21
|
+
...passedOptions,
|
|
11
22
|
schema,
|
|
12
|
-
formatError: formatError_1.default
|
|
13
|
-
schemaHash: 'deprecated',
|
|
14
|
-
...options
|
|
23
|
+
formatError: formatError_1.default
|
|
15
24
|
};
|
|
16
25
|
}
|
|
17
26
|
exports.default = default_1;
|
package/lib/index.d.ts
CHANGED
package/lib/index.js
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
3
|
if (k2 === undefined) k2 = k;
|
|
4
|
-
Object.
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
5
9
|
}) : (function(o, m, k, k2) {
|
|
6
10
|
if (k2 === undefined) k2 = k;
|
|
7
11
|
o[k2] = m[k];
|
|
@@ -44,3 +48,4 @@ const GraphQL = __importStar(require("graphql"));
|
|
|
44
48
|
exports.GraphQL = GraphQL;
|
|
45
49
|
__exportStar(require("./types"), exports);
|
|
46
50
|
__exportStar(require("./service"), exports);
|
|
51
|
+
__exportStar(require("./websockerViewer"), exports);
|
package/lib/service/index.js
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
3
|
if (k2 === undefined) k2 = k;
|
|
4
|
-
Object.
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
5
9
|
}) : (function(o, m, k, k2) {
|
|
6
10
|
if (k2 === undefined) k2 = k;
|
|
7
11
|
o[k2] = m[k];
|
|
@@ -14,7 +14,10 @@ function Subscriptions() {
|
|
|
14
14
|
exports.Subscriptions = Subscriptions;
|
|
15
15
|
function Subscription(options) {
|
|
16
16
|
return function (object, propertyName, index) {
|
|
17
|
-
const sub = (0, __1.subscription)(
|
|
17
|
+
const sub = (0, __1.subscription)({
|
|
18
|
+
name: propertyName,
|
|
19
|
+
...options
|
|
20
|
+
});
|
|
18
21
|
object.subscriptions = object.subscriptions || {};
|
|
19
22
|
object.subscriptions[propertyName] = sub;
|
|
20
23
|
services_1.Container.registerHandler({
|
|
@@ -49,6 +49,7 @@ describe('Subscriptions classes', () => {
|
|
|
49
49
|
expect(subscriptions.onUserCreated).toBeDefined();
|
|
50
50
|
const instance = (0, services_1.getInstance)(ExampleSubscriptionsService);
|
|
51
51
|
expect(instance.onUserCreated.publish).toBeDefined();
|
|
52
|
+
expect(instance.onUserCreated.name).toBe('onUserCreated');
|
|
52
53
|
// await instance.onUserCreated.publish({name: 'test'}, {name: 'test'})
|
|
53
54
|
});
|
|
54
55
|
});
|
package/lib/startGraphQL.js
CHANGED
|
@@ -6,65 +6,27 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
const startGraphiQL_1 = __importDefault(require("./startGraphiQL"));
|
|
7
7
|
const getApolloOptions_1 = __importDefault(require("./getApolloOptions"));
|
|
8
8
|
const startWebsocket_1 = __importDefault(require("./startWebsocket"));
|
|
9
|
-
const apollo_server_core_1 = require("apollo-server-core");
|
|
10
9
|
const http_1 = require("@orion-js/http");
|
|
10
|
+
const server_1 = require("@apollo/server");
|
|
11
|
+
const express4_1 = require("@apollo/server/express4");
|
|
12
|
+
const drainHttpServer_1 = require("@apollo/server/plugin/drainHttpServer");
|
|
13
|
+
const http_2 = require("@orion-js/http");
|
|
11
14
|
async function default_1(options) {
|
|
12
15
|
const apolloOptions = await (0, getApolloOptions_1.default)(options);
|
|
16
|
+
const app = options.app || (0, http_1.getApp)();
|
|
17
|
+
const httpServer = (0, http_1.getServer)();
|
|
13
18
|
if (options.useGraphiql) {
|
|
14
19
|
(0, startGraphiQL_1.default)(apolloOptions, options);
|
|
15
20
|
}
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
async
|
|
25
|
-
try {
|
|
26
|
-
const executeQuery = async () => {
|
|
27
|
-
return await (0, apollo_server_core_1.runHttpQuery)([req, res], {
|
|
28
|
-
method: req.method,
|
|
29
|
-
options: { ...apolloOptions, context: viewer },
|
|
30
|
-
query: req.method === 'POST' ? req.body : req.query,
|
|
31
|
-
request: (0, apollo_server_core_1.convertNodeHttpToRequest)(req)
|
|
32
|
-
});
|
|
33
|
-
};
|
|
34
|
-
if (options.executeGraphQLCache) {
|
|
35
|
-
try {
|
|
36
|
-
const result = await options.executeGraphQLCache(req, res, viewer, () => executeQuery().then(r => r.graphqlResponse));
|
|
37
|
-
if (result) {
|
|
38
|
-
return {
|
|
39
|
-
body: result,
|
|
40
|
-
headers: {
|
|
41
|
-
'Content-Type': 'application/json'
|
|
42
|
-
}
|
|
43
|
-
};
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
catch (error) {
|
|
47
|
-
console.log('Error executing GraphQL cache:', error);
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
const { graphqlResponse, responseInit } = await executeQuery();
|
|
51
|
-
return {
|
|
52
|
-
body: graphqlResponse,
|
|
53
|
-
headers: responseInit.headers,
|
|
54
|
-
statusCode: responseInit.status || 200
|
|
55
|
-
};
|
|
56
|
-
}
|
|
57
|
-
catch (error) {
|
|
58
|
-
if (!(0, apollo_server_core_1.isHttpQueryError)(error)) {
|
|
59
|
-
throw error;
|
|
60
|
-
}
|
|
61
|
-
return {
|
|
62
|
-
headers: error.headers,
|
|
63
|
-
statusCode: error.statusCode,
|
|
64
|
-
body: error.message
|
|
65
|
-
};
|
|
66
|
-
}
|
|
67
|
-
}
|
|
21
|
+
const subPlugins = (0, startWebsocket_1.default)(apolloOptions, options);
|
|
22
|
+
const drainPlugins = httpServer ? [(0, drainHttpServer_1.ApolloServerPluginDrainHttpServer)({ httpServer })] : [];
|
|
23
|
+
const server = new server_1.ApolloServer({
|
|
24
|
+
...apolloOptions,
|
|
25
|
+
plugins: [...(apolloOptions.plugins || []), ...drainPlugins, ...subPlugins]
|
|
26
|
+
});
|
|
27
|
+
await server.start();
|
|
28
|
+
app.use('/graphql', http_2.bodyParser.json(), (0, express4_1.expressMiddleware)(server, {
|
|
29
|
+
context: async ({ req }) => await (0, http_1.getViewer)(req)
|
|
68
30
|
}));
|
|
69
31
|
}
|
|
70
32
|
exports.default = default_1;
|
package/lib/startGraphiQL.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { GraphQLOptions } from 'apollo-server-core';
|
|
2
1
|
import { StartGraphQLOptions } from './types/startGraphQL';
|
|
3
|
-
|
|
2
|
+
import { ApolloServerOptions } from '@apollo/server';
|
|
3
|
+
export default function (apolloOptions: ApolloServerOptions<any>, options: StartGraphQLOptions): void;
|
package/lib/startWebsocket.d.ts
CHANGED
|
@@ -1,4 +1,11 @@
|
|
|
1
1
|
import { StartGraphQLOptions } from './types/startGraphQL';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
import { ApolloServerOptions } from '@apollo/server';
|
|
3
|
+
export default function (apolloOptions: ApolloServerOptions<any>, options: StartGraphQLOptions,
|
|
4
|
+
/**
|
|
5
|
+
* For testing purposes
|
|
6
|
+
*/
|
|
7
|
+
wsServer?: any): {
|
|
8
|
+
serverWillStart(): Promise<{
|
|
9
|
+
drainServer(): Promise<void>;
|
|
10
|
+
}>;
|
|
11
|
+
}[];
|
package/lib/startWebsocket.js
CHANGED
|
@@ -1,34 +1,52 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const graphql_1 = require("graphql");
|
|
4
|
-
const subscriptions_transport_ws_1 = require("subscriptions-transport-ws");
|
|
5
3
|
const graphql_subscriptions_1 = require("graphql-subscriptions");
|
|
6
4
|
const pubsub_1 = require("./pubsub");
|
|
7
|
-
const
|
|
5
|
+
const ws_1 = require("ws");
|
|
6
|
+
const ws_2 = require("graphql-ws/lib/use/ws");
|
|
8
7
|
const websockerViewer_1 = require("./websockerViewer");
|
|
9
|
-
|
|
8
|
+
const http_1 = require("@orion-js/http");
|
|
9
|
+
function default_1(apolloOptions, options,
|
|
10
|
+
/**
|
|
11
|
+
* For testing purposes
|
|
12
|
+
*/
|
|
13
|
+
wsServer) {
|
|
14
|
+
if (!options.subscriptions) {
|
|
15
|
+
return [];
|
|
16
|
+
}
|
|
10
17
|
const pubsub = options.pubsub || new graphql_subscriptions_1.PubSub();
|
|
11
18
|
(0, pubsub_1.setPubsub)(pubsub);
|
|
12
|
-
|
|
13
|
-
if (!
|
|
14
|
-
|
|
19
|
+
// Creating the WebSocket server
|
|
20
|
+
if (!wsServer) {
|
|
21
|
+
wsServer = new ws_1.WebSocketServer({
|
|
22
|
+
server: (0, http_1.getServer)(),
|
|
23
|
+
path: '/subscriptions',
|
|
24
|
+
port: Number(internalGetEnv('http_port', 'PORT'))
|
|
25
|
+
});
|
|
15
26
|
}
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
schema,
|
|
20
|
-
async
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
27
|
+
// Hand in the schema we just created and have the
|
|
28
|
+
// WebSocketServer start listening.
|
|
29
|
+
const serverCleanup = (0, ws_2.useServer)({
|
|
30
|
+
schema: apolloOptions.schema,
|
|
31
|
+
context: async (ctx, msg, args) => {
|
|
32
|
+
// This will be run every time the client sends a subscription request
|
|
33
|
+
return (0, websockerViewer_1.getWebsockerViewer)(ctx.connectionParams);
|
|
34
|
+
}
|
|
35
|
+
}, wsServer);
|
|
36
|
+
return [
|
|
37
|
+
// Proper shutdown for the WebSocket server.
|
|
38
|
+
{
|
|
39
|
+
async serverWillStart() {
|
|
40
|
+
return {
|
|
41
|
+
async drainServer() {
|
|
42
|
+
await serverCleanup.dispose();
|
|
43
|
+
}
|
|
44
|
+
};
|
|
24
45
|
}
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
const viewer = await (0, websockerViewer_1.getWebsockerViewer)({});
|
|
28
|
-
return viewer;
|
|
29
|
-
}
|
|
30
|
-
},
|
|
31
|
-
onDisconnect() { }
|
|
32
|
-
}, server);
|
|
46
|
+
}
|
|
47
|
+
];
|
|
33
48
|
}
|
|
34
49
|
exports.default = default_1;
|
|
50
|
+
function internalGetEnv(arg0, arg1) {
|
|
51
|
+
throw new Error('Function not implemented.');
|
|
52
|
+
}
|
|
@@ -1,10 +1,33 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
2
18
|
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
19
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
20
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
21
|
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
22
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
23
|
};
|
|
24
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
25
|
+
if (mod && mod.__esModule) return mod;
|
|
26
|
+
var result = {};
|
|
27
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
28
|
+
__setModuleDefault(result, mod);
|
|
29
|
+
return result;
|
|
30
|
+
};
|
|
8
31
|
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
32
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
33
|
};
|
|
@@ -16,14 +39,17 @@ const getApolloOptions_1 = __importDefault(require("./getApolloOptions"));
|
|
|
16
39
|
const startWebsocket_1 = __importDefault(require("./startWebsocket"));
|
|
17
40
|
const resolvers_1 = require("@orion-js/resolvers");
|
|
18
41
|
const _1 = require(".");
|
|
19
|
-
const mock_socket_with_protocol_1 = require("mock-socket-with-protocol");
|
|
20
42
|
const core_1 = require("@apollo/client/core");
|
|
21
|
-
const ws_1 = require("@apollo/client/link/ws");
|
|
22
43
|
const graphql_tag_1 = __importDefault(require("graphql-tag"));
|
|
23
44
|
const helpers_1 = require("@orion-js/helpers");
|
|
24
45
|
const lodash_1 = require("lodash");
|
|
25
46
|
const websockerViewer_1 = require("./websockerViewer");
|
|
26
47
|
const typed_model_1 = require("@orion-js/typed-model");
|
|
48
|
+
const subscriptions_1 = require("@apollo/client/link/subscriptions");
|
|
49
|
+
const graphql_ws_1 = require("graphql-ws");
|
|
50
|
+
const ws_1 = __importStar(require("ws"));
|
|
51
|
+
const crypto_1 = __importDefault(require("crypto"));
|
|
52
|
+
const http_1 = require("@orion-js/http");
|
|
27
53
|
const getStartServerOptions = async () => {
|
|
28
54
|
const resolvers = {
|
|
29
55
|
helloWorld: (0, resolvers_1.resolver)({
|
|
@@ -113,25 +139,31 @@ const gqClient = async () => {
|
|
|
113
139
|
const RANDOM_WS_PORT = (0, lodash_1.random)(10000, 65536);
|
|
114
140
|
// We pass customServer instead of typical configuration of a default WebSocket server
|
|
115
141
|
const { apolloOptions, subscriptions } = await getStartServerOptions();
|
|
116
|
-
const uri = `ws://localhost:${RANDOM_WS_PORT}`;
|
|
117
|
-
const
|
|
118
|
-
|
|
142
|
+
const uri = `ws://localhost:${RANDOM_WS_PORT}/subscriptions`;
|
|
143
|
+
const server = new ws_1.WebSocketServer({
|
|
144
|
+
server: (0, http_1.getServer)(),
|
|
145
|
+
path: '/subscriptions',
|
|
146
|
+
port: RANDOM_WS_PORT
|
|
147
|
+
});
|
|
148
|
+
(0, startWebsocket_1.default)({ schema: apolloOptions.schema }, { resolvers: {}, subscriptions: {} }, server);
|
|
119
149
|
const getConnectionParams = () => {
|
|
120
150
|
return { jwt: 'hi' };
|
|
121
151
|
};
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
152
|
+
const client = (0, graphql_ws_1.createClient)({
|
|
153
|
+
url: uri,
|
|
154
|
+
webSocketImpl: ws_1.default,
|
|
155
|
+
connectionParams: getConnectionParams,
|
|
156
|
+
lazy: false,
|
|
157
|
+
/**
|
|
158
|
+
* Generates a v4 UUID to be used as the ID.
|
|
159
|
+
* Reference: https://gist.github.com/jed/982883
|
|
160
|
+
*/
|
|
161
|
+
generateID: () =>
|
|
162
|
+
// @ts-expect-error this is the way to do it segun la doc
|
|
163
|
+
([1e7] + -1e3 + -4e3 + -8e3 + -1e11).replace(/[018]/g, c => (c ^ (crypto_1.default.randomBytes(1)[0] & (15 >> (c / 4)))).toString(16))
|
|
134
164
|
});
|
|
165
|
+
// The uri of the WebSocketLink has to match the customServer uri.
|
|
166
|
+
const wsLink = new subscriptions_1.GraphQLWsLink(client);
|
|
135
167
|
// Nothing new here
|
|
136
168
|
return {
|
|
137
169
|
client: new core_1.ApolloClient({
|
|
@@ -8,19 +8,19 @@ const getChannelName_1 = __importDefault(require("./getChannelName"));
|
|
|
8
8
|
const resolvers_1 = require("@orion-js/resolvers");
|
|
9
9
|
const createSubscription = function (options) {
|
|
10
10
|
const subscription = {
|
|
11
|
-
|
|
11
|
+
name: options.name
|
|
12
12
|
};
|
|
13
13
|
// the publish function
|
|
14
14
|
subscription.publish = async (params, data) => {
|
|
15
15
|
const pubsub = (0, pubsub_1.getPubsub)();
|
|
16
|
-
const channelName = (0, getChannelName_1.default)(subscription.
|
|
17
|
-
await pubsub.publish(channelName, { [subscription.
|
|
16
|
+
const channelName = (0, getChannelName_1.default)(subscription.name, params);
|
|
17
|
+
await pubsub.publish(channelName, { [subscription.name]: data });
|
|
18
18
|
};
|
|
19
19
|
subscription.subscribe = async (params, viewer) => {
|
|
20
20
|
const pubsub = (0, pubsub_1.getPubsub)();
|
|
21
21
|
try {
|
|
22
22
|
await (0, resolvers_1.checkPermissions)({ params, viewer }, options);
|
|
23
|
-
const channelName = (0, getChannelName_1.default)(subscription.
|
|
23
|
+
const channelName = (0, getChannelName_1.default)(subscription.name, params);
|
|
24
24
|
return pubsub.asyncIterator(channelName);
|
|
25
25
|
}
|
|
26
26
|
catch (error) {
|
package/lib/types/index.js
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
3
|
if (k2 === undefined) k2 = k;
|
|
4
|
-
Object.
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
5
9
|
}) : (function(o, m, k, k2) {
|
|
6
10
|
if (k2 === undefined) k2 = k;
|
|
7
11
|
o[k2] = m[k];
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import { GlobalResolversMap, ModelResolversMap } from '@orion-js/models';
|
|
2
2
|
import { express } from '@orion-js/http';
|
|
3
3
|
import { OrionSubscriptionsMap } from './subscription';
|
|
4
|
-
import { GraphQLOptions } from 'apollo-server-core';
|
|
5
4
|
import { PubSubEngine } from 'graphql-subscriptions';
|
|
6
|
-
|
|
5
|
+
import { ApolloServerOptions } from '@apollo/server';
|
|
6
|
+
export type ExecuteGraphQLCache = (req: express.Request, res: express.Response, viewer: object, executeQuery: () => Promise<string>) => Promise<string>;
|
|
7
7
|
export interface ModelsResolversMap {
|
|
8
8
|
[key: string]: ModelResolversMap;
|
|
9
9
|
}
|
|
10
|
-
|
|
11
|
-
export interface StartGraphQLOptions extends Omit<
|
|
10
|
+
type SchemaOmits = 'schema' | 'schemaHash' | 'context' | 'useGraphiql';
|
|
11
|
+
export interface StartGraphQLOptions extends Omit<ApolloServerOptions<any>, SchemaOmits> {
|
|
12
12
|
/**
|
|
13
13
|
* A map with all the global resolvers
|
|
14
14
|
*/
|
|
@@ -24,7 +24,6 @@ export interface StartGraphQLOptions extends Omit<GraphQLOptions, SchemaOmits> {
|
|
|
24
24
|
/**
|
|
25
25
|
* A function that executes the http level cache of graphql queries
|
|
26
26
|
*/
|
|
27
|
-
executeGraphQLCache?: ExecuteGraphQLCache;
|
|
28
27
|
/**
|
|
29
28
|
* Should use GraphiQL. Default to true
|
|
30
29
|
*/
|
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
import { ResolverOptions } from '@orion-js/resolvers';
|
|
2
2
|
export interface OrionSubscription<TParams = any, ReturnType = any> {
|
|
3
|
-
|
|
3
|
+
name: string;
|
|
4
4
|
params: object;
|
|
5
5
|
subscribe: (callParams: object, viewer: object) => {};
|
|
6
6
|
returns: ReturnType;
|
|
7
7
|
publish: (params: TParams, data: ReturnType) => Promise<void>;
|
|
8
8
|
}
|
|
9
|
-
export
|
|
9
|
+
export type CreateOrionSubscriptionFunction = <T = any, ReturnType = any>(options: OrionSubscriptionOptions) => OrionSubscription<T, ReturnType>;
|
|
10
10
|
export interface OrionSubscriptionsMap {
|
|
11
11
|
[key: string]: OrionSubscription;
|
|
12
12
|
}
|
|
13
13
|
export interface OrionSubscriptionOptions extends Omit<ResolverOptions, 'resolve'> {
|
|
14
|
+
name?: string;
|
|
14
15
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@orion-js/graphql",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.4.1",
|
|
4
4
|
"main": "lib/index.js",
|
|
5
5
|
"author": "nicolaslopezj",
|
|
6
6
|
"license": "MIT",
|
|
@@ -13,31 +13,36 @@
|
|
|
13
13
|
"upgrade-interactive": "yarn upgrade-interactive"
|
|
14
14
|
},
|
|
15
15
|
"dependencies": {
|
|
16
|
-
"@
|
|
17
|
-
"@
|
|
18
|
-
"@orion-js/
|
|
19
|
-
"@orion-js/
|
|
20
|
-
"@orion-js/
|
|
21
|
-
"@orion-js/
|
|
22
|
-
"@orion-js/
|
|
23
|
-
"
|
|
16
|
+
"@apollo/server": "^4.3.0",
|
|
17
|
+
"@graphql-tools/schema": "^9.0.12",
|
|
18
|
+
"@orion-js/helpers": "^3.4.1",
|
|
19
|
+
"@orion-js/http": "^3.4.1",
|
|
20
|
+
"@orion-js/models": "^3.4.1",
|
|
21
|
+
"@orion-js/resolvers": "^3.4.1",
|
|
22
|
+
"@orion-js/schema": "^3.4.1",
|
|
23
|
+
"@orion-js/services": "^3.4.1",
|
|
24
|
+
"@orion-js/typed-model": "^3.4.1",
|
|
24
25
|
"graphql-iso-date": "^3.6.1",
|
|
25
|
-
"graphql-subscriptions": "
|
|
26
|
+
"graphql-subscriptions": "2.0.0",
|
|
27
|
+
"graphql-ws": "^5.11.2",
|
|
26
28
|
"lodash": "^4.17.21",
|
|
27
|
-
"subscriptions-transport-ws": "^0.11.0"
|
|
29
|
+
"subscriptions-transport-ws": "^0.11.0",
|
|
30
|
+
"ws": "^8.11.0"
|
|
28
31
|
},
|
|
29
32
|
"devDependencies": {
|
|
30
|
-
"@apollo/client": "^3.
|
|
31
|
-
"@types/jest": "^
|
|
32
|
-
"@types/lodash": "4.14.
|
|
33
|
-
"@types/supertest": "2.0.
|
|
34
|
-
"
|
|
35
|
-
"
|
|
36
|
-
"
|
|
33
|
+
"@apollo/client": "^3.7.3",
|
|
34
|
+
"@types/jest": "^29.2.5",
|
|
35
|
+
"@types/lodash": "4.14.191",
|
|
36
|
+
"@types/supertest": "2.0.12",
|
|
37
|
+
"@types/ws": "^8.5.4",
|
|
38
|
+
"graphql": "^16.6.0",
|
|
39
|
+
"jest": "29.3.1",
|
|
40
|
+
"jest-websocket-mock": "^2.4.0",
|
|
37
41
|
"reflect-metadata": "^0.1.13",
|
|
38
|
-
"supertest": "^6.
|
|
39
|
-
"
|
|
40
|
-
"
|
|
42
|
+
"supertest": "^6.3.3",
|
|
43
|
+
"superwstest": "^2.0.3",
|
|
44
|
+
"ts-jest": "29.0.3",
|
|
45
|
+
"typescript": "^4.9.4"
|
|
41
46
|
},
|
|
42
47
|
"peerDependencies": {
|
|
43
48
|
"graphql": "^16.0.1"
|
|
@@ -45,5 +50,5 @@
|
|
|
45
50
|
"publishConfig": {
|
|
46
51
|
"access": "public"
|
|
47
52
|
},
|
|
48
|
-
"gitHead": "
|
|
53
|
+
"gitHead": "af7632797b76ad2acf19c2861a38d48abc58ec56"
|
|
49
54
|
}
|