@orion-js/graphql 3.11.15 → 4.0.0-alpha.2
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/dist/index.cjs +107839 -0
- package/dist/index.d.ts +570 -0
- package/dist/index.js +107812 -0
- package/package.json +30 -21
- package/LICENSE +0 -21
- package/jest.config.js +0 -8
- package/lib/buildSchema/getArgs/getField.d.ts +0 -1
- package/lib/buildSchema/getArgs/getField.js +0 -49
- package/lib/buildSchema/getArgs/index.d.ts +0 -1
- package/lib/buildSchema/getArgs/index.js +0 -24
- package/lib/buildSchema/getMutation.d.ts +0 -3
- package/lib/buildSchema/getMutation.js +0 -18
- package/lib/buildSchema/getQuery.d.ts +0 -3
- package/lib/buildSchema/getQuery.js +0 -18
- package/lib/buildSchema/getResolvers/index.d.ts +0 -3
- package/lib/buildSchema/getResolvers/index.js +0 -43
- package/lib/buildSchema/getResolvers/index.test.d.ts +0 -1
- package/lib/buildSchema/getResolvers/index.test.js +0 -65
- package/lib/buildSchema/getResolvers/resolversStore.d.ts +0 -3
- package/lib/buildSchema/getResolvers/resolversStore.js +0 -5
- package/lib/buildSchema/getSubscription.d.ts +0 -3
- package/lib/buildSchema/getSubscription.js +0 -17
- package/lib/buildSchema/getSubscriptions/index.d.ts +0 -2
- package/lib/buildSchema/getSubscriptions/index.js +0 -26
- package/lib/buildSchema/getSubscriptions/index.test.d.ts +0 -1
- package/lib/buildSchema/getSubscriptions/index.test.js +0 -52
- package/lib/buildSchema/getType/BigIntScalar.d.ts +0 -3
- package/lib/buildSchema/getType/BigIntScalar.js +0 -35
- package/lib/buildSchema/getType/DateScalar.d.ts +0 -3
- package/lib/buildSchema/getType/DateScalar.js +0 -10
- package/lib/buildSchema/getType/JSONScalar.d.ts +0 -3
- package/lib/buildSchema/getType/JSONScalar.js +0 -42
- package/lib/buildSchema/getType/enum.test.d.ts +0 -1
- package/lib/buildSchema/getType/enum.test.js +0 -80
- package/lib/buildSchema/getType/getScalar.d.ts +0 -1
- package/lib/buildSchema/getType/getScalar.js +0 -58
- package/lib/buildSchema/getType/getTypeAsResolver.d.ts +0 -10
- package/lib/buildSchema/getType/getTypeAsResolver.js +0 -26
- package/lib/buildSchema/getType/index.d.ts +0 -2
- package/lib/buildSchema/getType/index.js +0 -86
- package/lib/buildSchema/index.d.ts +0 -3
- package/lib/buildSchema/index.js +0 -17
- package/lib/cleanResolvers.d.ts +0 -1
- package/lib/cleanResolvers.js +0 -8
- package/lib/errorHandler.d.ts +0 -1
- package/lib/errorHandler.js +0 -42
- package/lib/getApolloOptions/formatError.d.ts +0 -1
- package/lib/getApolloOptions/formatError.js +0 -14
- package/lib/getApolloOptions/index.d.ts +0 -3
- package/lib/getApolloOptions/index.js +0 -26
- package/lib/index.d.ts +0 -12
- package/lib/index.js +0 -51
- package/lib/pubsub.d.ts +0 -3
- package/lib/pubsub.js +0 -12
- package/lib/resolversSchemas/ResolverParamsInfo.d.ts +0 -9
- package/lib/resolversSchemas/ResolverParamsInfo.js +0 -47
- package/lib/resolversSchemas/getBasicResultQuery.d.ts +0 -1
- package/lib/resolversSchemas/getBasicResultQuery.js +0 -24
- package/lib/resolversSchemas/getDynamicFields.d.ts +0 -2
- package/lib/resolversSchemas/getDynamicFields.js +0 -19
- package/lib/resolversSchemas/getField.d.ts +0 -1
- package/lib/resolversSchemas/getField.js +0 -50
- package/lib/resolversSchemas/getField.test.d.ts +0 -1
- package/lib/resolversSchemas/getField.test.js +0 -56
- package/lib/resolversSchemas/getModelLoadedResolvers.d.ts +0 -3
- package/lib/resolversSchemas/getModelLoadedResolvers.js +0 -21
- package/lib/resolversSchemas/getStaticFields.d.ts +0 -3
- package/lib/resolversSchemas/getStaticFields.js +0 -20
- package/lib/resolversSchemas/index.d.ts +0 -7
- package/lib/resolversSchemas/index.js +0 -9
- package/lib/resolversSchemas/params.d.ts +0 -5
- package/lib/resolversSchemas/params.js +0 -31
- package/lib/resolversSchemas/params.test.d.ts +0 -1
- package/lib/resolversSchemas/params.test.js +0 -131
- package/lib/resolversSchemas/serializeSchema.d.ts +0 -2
- package/lib/resolversSchemas/serializeSchema.js +0 -22
- package/lib/resolversSchemas/serializeSchema.test.d.ts +0 -1
- package/lib/resolversSchemas/serializeSchema.test.js +0 -56
- package/lib/service/global.d.ts +0 -10
- package/lib/service/global.js +0 -60
- package/lib/service/index.d.ts +0 -4
- package/lib/service/index.js +0 -20
- package/lib/service/index.test.d.ts +0 -1
- package/lib/service/index.test.js +0 -63
- package/lib/service/middlewares.test.d.ts +0 -1
- package/lib/service/middlewares.test.js +0 -125
- package/lib/service/model.d.ts +0 -14
- package/lib/service/model.js +0 -48
- package/lib/service/model.test.d.ts +0 -1
- package/lib/service/model.test.js +0 -126
- package/lib/service/otherParams.d.ts +0 -7
- package/lib/service/otherParams.js +0 -28
- package/lib/service/subscription.d.ts +0 -6
- package/lib/service/subscription.js +0 -43
- package/lib/service/subscription.test.d.ts +0 -1
- package/lib/service/subscription.test.js +0 -55
- package/lib/startGraphQL.d.ts +0 -2
- package/lib/startGraphQL.js +0 -43
- package/lib/startGraphQL.test.d.ts +0 -1
- package/lib/startGraphQL.test.js +0 -414
- package/lib/startGraphiQL.d.ts +0 -3
- package/lib/startGraphiQL.js +0 -207
- package/lib/startWebsocket.d.ts +0 -11
- package/lib/startWebsocket.js +0 -48
- package/lib/startWebsocket.test.d.ts +0 -1
- package/lib/startWebsocket.test.js +0 -303
- package/lib/subscription/getChannelName.d.ts +0 -1
- package/lib/subscription/getChannelName.js +0 -9
- package/lib/subscription/getChannelName.test.d.ts +0 -1
- package/lib/subscription/getChannelName.test.js +0 -26
- package/lib/subscription/index.d.ts +0 -3
- package/lib/subscription/index.js +0 -34
- package/lib/types/index.d.ts +0 -3
- package/lib/types/index.js +0 -19
- package/lib/types/startGraphQL.d.ts +0 -41
- package/lib/types/startGraphQL.js +0 -2
- package/lib/types/subscription.d.ts +0 -15
- package/lib/types/subscription.js +0 -2
- package/lib/websockerViewer.d.ts +0 -2
- package/lib/websockerViewer.js +0 -20
- package/tsconfig.json +0 -20
- package/yarn-error.log +0 -3949
|
@@ -1,303 +0,0 @@
|
|
|
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
|
-
});
|
|
18
|
-
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
19
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
20
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
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;
|
|
22
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
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
|
-
};
|
|
31
|
-
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
32
|
-
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
33
|
-
};
|
|
34
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
35
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
36
|
-
};
|
|
37
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
38
|
-
const getApolloOptions_1 = __importDefault(require("./getApolloOptions"));
|
|
39
|
-
const startWebsocket_1 = __importDefault(require("./startWebsocket"));
|
|
40
|
-
const resolvers_1 = require("@orion-js/resolvers");
|
|
41
|
-
const _1 = require(".");
|
|
42
|
-
const core_1 = require("@apollo/client/core");
|
|
43
|
-
const graphql_tag_1 = __importDefault(require("graphql-tag"));
|
|
44
|
-
const helpers_1 = require("@orion-js/helpers");
|
|
45
|
-
const lodash_1 = require("lodash");
|
|
46
|
-
const websockerViewer_1 = require("./websockerViewer");
|
|
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");
|
|
53
|
-
const getStartServerOptions = async () => {
|
|
54
|
-
const resolvers = {
|
|
55
|
-
helloWorld: (0, resolvers_1.resolver)({
|
|
56
|
-
params: {
|
|
57
|
-
name: {
|
|
58
|
-
type: 'string'
|
|
59
|
-
}
|
|
60
|
-
},
|
|
61
|
-
returns: 'string',
|
|
62
|
-
async resolve({ name }) {
|
|
63
|
-
return `Hello ${name}`;
|
|
64
|
-
}
|
|
65
|
-
})
|
|
66
|
-
};
|
|
67
|
-
const onNewGreeting = (0, _1.subscription)({
|
|
68
|
-
params: {
|
|
69
|
-
name: {
|
|
70
|
-
type: 'string'
|
|
71
|
-
}
|
|
72
|
-
},
|
|
73
|
-
returns: 'string'
|
|
74
|
-
});
|
|
75
|
-
const withPermissionsSub = (0, _1.subscription)({
|
|
76
|
-
returns: 'string',
|
|
77
|
-
checkPermission: async () => null
|
|
78
|
-
});
|
|
79
|
-
const withoutPermissionsSub = (0, _1.subscription)({
|
|
80
|
-
returns: 'string',
|
|
81
|
-
checkPermission: async () => 'notAllowed'
|
|
82
|
-
});
|
|
83
|
-
const withGlobalPermissionsSub = (0, _1.subscription)({
|
|
84
|
-
returns: 'string',
|
|
85
|
-
permissionsOptions: {
|
|
86
|
-
role: 'user'
|
|
87
|
-
}
|
|
88
|
-
});
|
|
89
|
-
const withoutGlobalPermissionsSub = (0, _1.subscription)({
|
|
90
|
-
returns: 'string',
|
|
91
|
-
permissionsOptions: {
|
|
92
|
-
role: 'admin'
|
|
93
|
-
}
|
|
94
|
-
});
|
|
95
|
-
let TestParams = class TestParams {
|
|
96
|
-
};
|
|
97
|
-
__decorate([
|
|
98
|
-
(0, typed_model_1.Prop)({ type: 'ID' }),
|
|
99
|
-
__metadata("design:type", String)
|
|
100
|
-
], TestParams.prototype, "userId", void 0);
|
|
101
|
-
TestParams = __decorate([
|
|
102
|
-
(0, typed_model_1.TypedSchema)()
|
|
103
|
-
], TestParams);
|
|
104
|
-
let TestModel = class TestModel {
|
|
105
|
-
};
|
|
106
|
-
__decorate([
|
|
107
|
-
(0, typed_model_1.Prop)(),
|
|
108
|
-
__metadata("design:type", String)
|
|
109
|
-
], TestModel.prototype, "name", void 0);
|
|
110
|
-
__decorate([
|
|
111
|
-
(0, typed_model_1.Prop)(),
|
|
112
|
-
__metadata("design:type", Number)
|
|
113
|
-
], TestModel.prototype, "age", void 0);
|
|
114
|
-
TestModel = __decorate([
|
|
115
|
-
(0, typed_model_1.TypedSchema)()
|
|
116
|
-
], TestModel);
|
|
117
|
-
const modelSub = (0, _1.subscription)({
|
|
118
|
-
params: (0, typed_model_1.getModelForClass)(TestParams),
|
|
119
|
-
returns: (0, typed_model_1.getModelForClass)(TestModel)
|
|
120
|
-
});
|
|
121
|
-
const subscriptions = {
|
|
122
|
-
onNewGreeting,
|
|
123
|
-
withPermissionsSub,
|
|
124
|
-
withoutPermissionsSub,
|
|
125
|
-
withGlobalPermissionsSub,
|
|
126
|
-
withoutGlobalPermissionsSub,
|
|
127
|
-
modelSub
|
|
128
|
-
};
|
|
129
|
-
const apolloOptions = await (0, getApolloOptions_1.default)({
|
|
130
|
-
resolvers,
|
|
131
|
-
subscriptions
|
|
132
|
-
});
|
|
133
|
-
return { apolloOptions, resolvers, subscriptions };
|
|
134
|
-
};
|
|
135
|
-
const gqClient = async () => {
|
|
136
|
-
// To make the point clear that we are not opening any ports here we use a randomized string that will not produce a correct port number.
|
|
137
|
-
// This example of WebSocket client/server uses string matching to know to what server connect a given client.
|
|
138
|
-
// We are randomizing because we should use different string for every test to not share state.
|
|
139
|
-
const RANDOM_WS_PORT = (0, lodash_1.random)(10000, 65536);
|
|
140
|
-
// We pass customServer instead of typical configuration of a default WebSocket server
|
|
141
|
-
const { apolloOptions, subscriptions } = await getStartServerOptions();
|
|
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);
|
|
149
|
-
const getConnectionParams = () => {
|
|
150
|
-
return { jwt: 'hi' };
|
|
151
|
-
};
|
|
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))
|
|
164
|
-
});
|
|
165
|
-
// The uri of the WebSocketLink has to match the customServer uri.
|
|
166
|
-
const wsLink = new subscriptions_1.GraphQLWsLink(client);
|
|
167
|
-
// Nothing new here
|
|
168
|
-
return {
|
|
169
|
-
client: new core_1.ApolloClient({
|
|
170
|
-
link: wsLink,
|
|
171
|
-
cache: new core_1.InMemoryCache()
|
|
172
|
-
}),
|
|
173
|
-
subscriptions
|
|
174
|
-
};
|
|
175
|
-
};
|
|
176
|
-
describe('Test GraphQL Subscriptions', () => {
|
|
177
|
-
it('Should connect to the graphql subscription server correctly', async () => {
|
|
178
|
-
const { client, subscriptions } = await gqClient();
|
|
179
|
-
client
|
|
180
|
-
.subscribe({
|
|
181
|
-
query: (0, graphql_tag_1.default) `
|
|
182
|
-
subscription ($name: String) {
|
|
183
|
-
info: onNewGreeting(name: $name)
|
|
184
|
-
}
|
|
185
|
-
`,
|
|
186
|
-
variables: { name: 'Nico' }
|
|
187
|
-
})
|
|
188
|
-
.subscribe({
|
|
189
|
-
next({ data }) {
|
|
190
|
-
expect(data.info).toEqual('finally');
|
|
191
|
-
}
|
|
192
|
-
});
|
|
193
|
-
await (0, helpers_1.sleep)(50);
|
|
194
|
-
expect.assertions(2);
|
|
195
|
-
await subscriptions.onNewGreeting.publish({ name: 'Nico' }, 'finally');
|
|
196
|
-
await subscriptions.onNewGreeting.publish({ name: 'Nico' }, 'finally');
|
|
197
|
-
await (0, helpers_1.sleep)(50);
|
|
198
|
-
});
|
|
199
|
-
it('Should execute subscriptions permissions correctly', async () => {
|
|
200
|
-
const { client, subscriptions } = await gqClient();
|
|
201
|
-
client
|
|
202
|
-
.subscribe({
|
|
203
|
-
query: (0, graphql_tag_1.default) `
|
|
204
|
-
subscription {
|
|
205
|
-
info: withPermissionsSub
|
|
206
|
-
}
|
|
207
|
-
`
|
|
208
|
-
})
|
|
209
|
-
.subscribe({
|
|
210
|
-
next({ data }) {
|
|
211
|
-
expect(data.info).toEqual('yes');
|
|
212
|
-
}
|
|
213
|
-
});
|
|
214
|
-
client
|
|
215
|
-
.subscribe({
|
|
216
|
-
query: (0, graphql_tag_1.default) `
|
|
217
|
-
subscription {
|
|
218
|
-
info: withoutPermissionsSub
|
|
219
|
-
}
|
|
220
|
-
`
|
|
221
|
-
})
|
|
222
|
-
.subscribe({
|
|
223
|
-
next({ data }) {
|
|
224
|
-
expect(data.info).toEqual('no');
|
|
225
|
-
}
|
|
226
|
-
});
|
|
227
|
-
await (0, helpers_1.sleep)(50);
|
|
228
|
-
expect.assertions(1); // only with should be called
|
|
229
|
-
await subscriptions.withPermissionsSub.publish({}, 'yes');
|
|
230
|
-
await subscriptions.withoutPermissionsSub.publish({}, 'no');
|
|
231
|
-
await (0, helpers_1.sleep)(50);
|
|
232
|
-
});
|
|
233
|
-
it('Should execute subscriptions with global permissions correctly using custom get viewer and custom global permission checker', async () => {
|
|
234
|
-
const { client, subscriptions } = await gqClient();
|
|
235
|
-
(0, websockerViewer_1.setGetWebsockerViewer)((connectionParams) => {
|
|
236
|
-
return {
|
|
237
|
-
role: 'user'
|
|
238
|
-
};
|
|
239
|
-
});
|
|
240
|
-
(0, resolvers_1.addPermissionChecker)(async ({ resolver, viewer }) => {
|
|
241
|
-
if (!resolver.permissionsOptions)
|
|
242
|
-
return null;
|
|
243
|
-
if (resolver.permissionsOptions.role === viewer.role)
|
|
244
|
-
return null;
|
|
245
|
-
return 'notAllowed';
|
|
246
|
-
});
|
|
247
|
-
client
|
|
248
|
-
.subscribe({
|
|
249
|
-
query: (0, graphql_tag_1.default) `
|
|
250
|
-
subscription {
|
|
251
|
-
info: withGlobalPermissionsSub
|
|
252
|
-
}
|
|
253
|
-
`
|
|
254
|
-
})
|
|
255
|
-
.subscribe({
|
|
256
|
-
next({ data }) {
|
|
257
|
-
expect(data.info).toEqual('yes');
|
|
258
|
-
}
|
|
259
|
-
});
|
|
260
|
-
client
|
|
261
|
-
.subscribe({
|
|
262
|
-
query: (0, graphql_tag_1.default) `
|
|
263
|
-
subscription {
|
|
264
|
-
info: withoutGlobalPermissionsSub
|
|
265
|
-
}
|
|
266
|
-
`
|
|
267
|
-
})
|
|
268
|
-
.subscribe({
|
|
269
|
-
next({ data }) {
|
|
270
|
-
expect(data.info).toEqual('no');
|
|
271
|
-
}
|
|
272
|
-
});
|
|
273
|
-
await (0, helpers_1.sleep)(50);
|
|
274
|
-
expect.assertions(1); // only with should be called
|
|
275
|
-
await subscriptions.withGlobalPermissionsSub.publish({}, 'yes');
|
|
276
|
-
await subscriptions.withoutGlobalPermissionsSub.publish({}, 'no');
|
|
277
|
-
await (0, helpers_1.sleep)(50);
|
|
278
|
-
});
|
|
279
|
-
it('Should work with typed model subscriptions', async () => {
|
|
280
|
-
const { client, subscriptions } = await gqClient();
|
|
281
|
-
client
|
|
282
|
-
.subscribe({
|
|
283
|
-
query: (0, graphql_tag_1.default) `
|
|
284
|
-
subscription ($userId: ID) {
|
|
285
|
-
info: modelSub(userId: $userId) {
|
|
286
|
-
name
|
|
287
|
-
}
|
|
288
|
-
}
|
|
289
|
-
`,
|
|
290
|
-
variables: { userId: '1' }
|
|
291
|
-
})
|
|
292
|
-
.subscribe({
|
|
293
|
-
next({ data }) {
|
|
294
|
-
expect(data.info).toEqual({ name: 'Nico', __typename: 'TestModel' });
|
|
295
|
-
}
|
|
296
|
-
});
|
|
297
|
-
await (0, helpers_1.sleep)(50);
|
|
298
|
-
expect.assertions(2);
|
|
299
|
-
await subscriptions.modelSub.publish({ userId: '1' }, { name: 'Nico', age: 20 });
|
|
300
|
-
await subscriptions.modelSub.publish({ userId: '1' }, { name: 'Nico', age: 20 });
|
|
301
|
-
await (0, helpers_1.sleep)(50);
|
|
302
|
-
});
|
|
303
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export default function (name: string, params: any): string;
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const helpers_1 = require("@orion-js/helpers");
|
|
4
|
-
function default_1(name, params) {
|
|
5
|
-
const hash = (0, helpers_1.hashObject)(params);
|
|
6
|
-
const channelName = `${name}_${hash}`;
|
|
7
|
-
return channelName;
|
|
8
|
-
}
|
|
9
|
-
exports.default = default_1;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const getChannelName_1 = __importDefault(require("./getChannelName"));
|
|
7
|
-
describe('Test channel name generation', () => {
|
|
8
|
-
it('Should return different channel names with different params', () => {
|
|
9
|
-
const channelName1 = (0, getChannelName_1.default)('test', {
|
|
10
|
-
hello: 'world'
|
|
11
|
-
});
|
|
12
|
-
const channelName2 = (0, getChannelName_1.default)('test', {
|
|
13
|
-
hello: 'country'
|
|
14
|
-
});
|
|
15
|
-
expect(channelName1).not.toEqual(channelName2);
|
|
16
|
-
});
|
|
17
|
-
it('Should return same channel names with same params', () => {
|
|
18
|
-
const channelName1 = (0, getChannelName_1.default)('test', {
|
|
19
|
-
hello: 'world'
|
|
20
|
-
});
|
|
21
|
-
const channelName2 = (0, getChannelName_1.default)('test', {
|
|
22
|
-
hello: 'world'
|
|
23
|
-
});
|
|
24
|
-
expect(channelName1).toEqual(channelName2);
|
|
25
|
-
});
|
|
26
|
-
});
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const pubsub_1 = require("../pubsub");
|
|
7
|
-
const getChannelName_1 = __importDefault(require("./getChannelName"));
|
|
8
|
-
const resolvers_1 = require("@orion-js/resolvers");
|
|
9
|
-
const createSubscription = function (options) {
|
|
10
|
-
const subscription = {
|
|
11
|
-
name: options.name
|
|
12
|
-
};
|
|
13
|
-
// the publish function
|
|
14
|
-
subscription.publish = async (params, data) => {
|
|
15
|
-
const pubsub = (0, pubsub_1.getPubsub)();
|
|
16
|
-
const channelName = (0, getChannelName_1.default)(subscription.name, params);
|
|
17
|
-
await pubsub.publish(channelName, { [subscription.name]: data });
|
|
18
|
-
};
|
|
19
|
-
subscription.subscribe = async (params, viewer) => {
|
|
20
|
-
const pubsub = (0, pubsub_1.getPubsub)();
|
|
21
|
-
try {
|
|
22
|
-
await (0, resolvers_1.checkPermissions)({ params, viewer, options: null }, options);
|
|
23
|
-
const channelName = (0, getChannelName_1.default)(subscription.name, params);
|
|
24
|
-
return pubsub.asyncIterator(channelName);
|
|
25
|
-
}
|
|
26
|
-
catch (error) {
|
|
27
|
-
return pubsub.asyncIterator('unauthorized');
|
|
28
|
-
}
|
|
29
|
-
};
|
|
30
|
-
subscription.params = (0, resolvers_1.cleanParams)(options.params);
|
|
31
|
-
subscription.returns = (0, resolvers_1.cleanReturns)(options.returns);
|
|
32
|
-
return subscription;
|
|
33
|
-
};
|
|
34
|
-
exports.default = createSubscription;
|
package/lib/types/index.d.ts
DELETED
package/lib/types/index.js
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
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 __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
require("./subscription");
|
|
18
|
-
__exportStar(require("./startGraphQL"), exports);
|
|
19
|
-
__exportStar(require("./subscription"), exports);
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import { GlobalResolversMap, ModelResolversMap } from '@orion-js/models';
|
|
2
|
-
import { express } from '@orion-js/http';
|
|
3
|
-
import { OrionSubscriptionsMap } from './subscription';
|
|
4
|
-
import { PubSubEngine } from 'graphql-subscriptions';
|
|
5
|
-
import { ApolloServerOptions } from '@apollo/server';
|
|
6
|
-
export type ExecuteGraphQLCache = (req: express.Request, res: express.Response, viewer: object, executeQuery: () => Promise<string>) => Promise<string>;
|
|
7
|
-
export interface ModelsResolversMap {
|
|
8
|
-
[key: string]: ModelResolversMap;
|
|
9
|
-
}
|
|
10
|
-
type SchemaOmits = 'schema' | 'schemaHash' | 'context' | 'useGraphiql';
|
|
11
|
-
export interface StartGraphQLOptions extends Omit<ApolloServerOptions<any>, SchemaOmits> {
|
|
12
|
-
/**
|
|
13
|
-
* A map with all the global resolvers
|
|
14
|
-
*/
|
|
15
|
-
resolvers: GlobalResolversMap;
|
|
16
|
-
/**
|
|
17
|
-
* A map with all the model resolvers. You must only add the models that you want to extend with resolvers.
|
|
18
|
-
*/
|
|
19
|
-
modelResolvers?: ModelsResolversMap;
|
|
20
|
-
/**
|
|
21
|
-
* A Map with all global subscriptions
|
|
22
|
-
*/
|
|
23
|
-
subscriptions?: OrionSubscriptionsMap;
|
|
24
|
-
/**
|
|
25
|
-
* A function that executes the http level cache of graphql queries
|
|
26
|
-
*/
|
|
27
|
-
/**
|
|
28
|
-
* Should use GraphiQL. Default to true
|
|
29
|
-
*/
|
|
30
|
-
useGraphiql?: boolean;
|
|
31
|
-
/**
|
|
32
|
-
* Pass another express app
|
|
33
|
-
*/
|
|
34
|
-
app?: express.Application;
|
|
35
|
-
/**
|
|
36
|
-
* The pubsub provider to use. Default to the single server pubsub.
|
|
37
|
-
* If you are using multiple servers you must pass a pubsub provider like RedisPubSub
|
|
38
|
-
*/
|
|
39
|
-
pubsub?: PubSubEngine;
|
|
40
|
-
}
|
|
41
|
-
export {};
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { ResolverOptions } from '@orion-js/resolvers';
|
|
2
|
-
export interface OrionSubscription<TParams = any, ReturnType = any> {
|
|
3
|
-
name: string;
|
|
4
|
-
params: object;
|
|
5
|
-
subscribe: (callParams: object, viewer: object) => {};
|
|
6
|
-
returns: ReturnType;
|
|
7
|
-
publish: (params: TParams, data: ReturnType) => Promise<void>;
|
|
8
|
-
}
|
|
9
|
-
export type CreateOrionSubscriptionFunction = <T = any, ReturnType = any>(options: OrionSubscriptionOptions) => OrionSubscription<T, ReturnType>;
|
|
10
|
-
export interface OrionSubscriptionsMap {
|
|
11
|
-
[key: string]: OrionSubscription;
|
|
12
|
-
}
|
|
13
|
-
export interface OrionSubscriptionOptions extends Omit<ResolverOptions, 'resolve'> {
|
|
14
|
-
name?: string;
|
|
15
|
-
}
|
package/lib/websockerViewer.d.ts
DELETED
package/lib/websockerViewer.js
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.setGetWebsockerViewer = exports.getWebsockerViewer = void 0;
|
|
4
|
-
global.getWebsocketViewerRef = () => null;
|
|
5
|
-
const getWebsockerViewer = async (connectionParams) => {
|
|
6
|
-
try {
|
|
7
|
-
const viewer = await global.getWebsocketViewerRef(connectionParams);
|
|
8
|
-
if (!viewer)
|
|
9
|
-
return {};
|
|
10
|
-
return viewer;
|
|
11
|
-
}
|
|
12
|
-
catch {
|
|
13
|
-
return {};
|
|
14
|
-
}
|
|
15
|
-
};
|
|
16
|
-
exports.getWebsockerViewer = getWebsockerViewer;
|
|
17
|
-
const setGetWebsockerViewer = (getViewerFunc) => {
|
|
18
|
-
global.getWebsocketViewerRef = getViewerFunc;
|
|
19
|
-
};
|
|
20
|
-
exports.setGetWebsockerViewer = setGetWebsockerViewer;
|
package/tsconfig.json
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"compilerOptions": {
|
|
3
|
-
"strict": false,
|
|
4
|
-
"outDir": "./lib",
|
|
5
|
-
"rootDir": "./src",
|
|
6
|
-
"module": "commonjs",
|
|
7
|
-
"target": "es2020",
|
|
8
|
-
"moduleResolution": "node",
|
|
9
|
-
"lib": ["es2020"],
|
|
10
|
-
"declaration": true,
|
|
11
|
-
|
|
12
|
-
"esModuleInterop": true,
|
|
13
|
-
"skipLibCheck": true,
|
|
14
|
-
"forceConsistentCasingInFileNames": true,
|
|
15
|
-
|
|
16
|
-
// required for typed models
|
|
17
|
-
"experimentalDecorators": true,
|
|
18
|
-
"emitDecoratorMetadata": true
|
|
19
|
-
}
|
|
20
|
-
}
|