@orion-js/graphql 4.0.0-next.2 → 4.0.0-next.3
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/LICENSE +21 -0
- package/dist/index.cjs +98 -177
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +106 -181
- package/dist/index.js.map +1 -1
- package/package.json +9 -9
package/dist/index.js
CHANGED
|
@@ -1,14 +1,11 @@
|
|
|
1
|
-
var __defProp = Object.defineProperty;
|
|
2
|
-
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
|
-
|
|
4
1
|
// src/pubsub.ts
|
|
5
2
|
var pubsub = null;
|
|
6
|
-
var setPubsub =
|
|
3
|
+
var setPubsub = function(newPubsub) {
|
|
7
4
|
pubsub = newPubsub;
|
|
8
|
-
}
|
|
9
|
-
var getPubsub =
|
|
5
|
+
};
|
|
6
|
+
var getPubsub = function() {
|
|
10
7
|
return pubsub;
|
|
11
|
-
}
|
|
8
|
+
};
|
|
12
9
|
|
|
13
10
|
// src/subscription/getChannelName.ts
|
|
14
11
|
import { hashObject } from "@orion-js/helpers";
|
|
@@ -17,29 +14,26 @@ function getChannelName_default(name, params) {
|
|
|
17
14
|
const channelName = `${name}_${hash}`;
|
|
18
15
|
return channelName;
|
|
19
16
|
}
|
|
20
|
-
__name(getChannelName_default, "default");
|
|
21
17
|
|
|
22
18
|
// src/subscription/index.ts
|
|
23
|
-
import {
|
|
24
|
-
|
|
19
|
+
import {
|
|
20
|
+
checkPermissions as checkResolverPermissions,
|
|
21
|
+
cleanParams,
|
|
22
|
+
cleanReturns
|
|
23
|
+
} from "@orion-js/resolvers";
|
|
24
|
+
var createSubscription = function(options) {
|
|
25
25
|
const subscription = {
|
|
26
26
|
name: options.name
|
|
27
27
|
};
|
|
28
28
|
subscription.publish = async (params, data) => {
|
|
29
29
|
const pubsub2 = getPubsub();
|
|
30
30
|
const channelName = getChannelName_default(subscription.name, params);
|
|
31
|
-
await pubsub2.publish(channelName, {
|
|
32
|
-
[subscription.name]: data
|
|
33
|
-
});
|
|
31
|
+
await pubsub2.publish(channelName, { [subscription.name]: data });
|
|
34
32
|
};
|
|
35
33
|
subscription.subscribe = async (params, viewer) => {
|
|
36
34
|
const pubsub2 = getPubsub();
|
|
37
35
|
try {
|
|
38
|
-
await checkResolverPermissions({
|
|
39
|
-
params,
|
|
40
|
-
viewer,
|
|
41
|
-
options: null
|
|
42
|
-
}, options);
|
|
36
|
+
await checkResolverPermissions({ params, viewer, options: null }, options);
|
|
43
37
|
const channelName = getChannelName_default(subscription.name, params);
|
|
44
38
|
return pubsub2.asyncIterator(channelName);
|
|
45
39
|
} catch (error) {
|
|
@@ -49,7 +43,7 @@ var createSubscription = /* @__PURE__ */ __name(function(options) {
|
|
|
49
43
|
subscription.params = cleanParams(options.params);
|
|
50
44
|
subscription.returns = cleanReturns(options.returns);
|
|
51
45
|
return subscription;
|
|
52
|
-
}
|
|
46
|
+
};
|
|
53
47
|
var subscription_default = createSubscription;
|
|
54
48
|
|
|
55
49
|
// src/startGraphiQL.ts
|
|
@@ -57,8 +51,7 @@ import { registerRoute, route } from "@orion-js/http";
|
|
|
57
51
|
function safeSerialize(data) {
|
|
58
52
|
return data ? JSON.stringify(data).replace(/\//g, "\\/") : null;
|
|
59
53
|
}
|
|
60
|
-
|
|
61
|
-
var getHTML = /* @__PURE__ */ __name(function(apolloOptions, options, data) {
|
|
54
|
+
var getHTML = function(apolloOptions, options, data) {
|
|
62
55
|
const GRAPHIQL_VERSION = "0.11.11";
|
|
63
56
|
const endpointURL = "/graphql";
|
|
64
57
|
const subscriptionsEndpoint = "/subscriptions";
|
|
@@ -239,19 +232,20 @@ var getHTML = /* @__PURE__ */ __name(function(apolloOptions, options, data) {
|
|
|
239
232
|
</script>
|
|
240
233
|
</body>
|
|
241
234
|
</html>`;
|
|
242
|
-
}
|
|
235
|
+
};
|
|
243
236
|
function startGraphiQL_default(apolloOptions, options) {
|
|
244
|
-
registerRoute(
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
237
|
+
registerRoute(
|
|
238
|
+
route({
|
|
239
|
+
path: "/graphiql",
|
|
240
|
+
method: "get",
|
|
241
|
+
async resolve(req) {
|
|
242
|
+
return {
|
|
243
|
+
body: getHTML(apolloOptions, options, req.query)
|
|
244
|
+
};
|
|
245
|
+
}
|
|
246
|
+
})
|
|
247
|
+
);
|
|
253
248
|
}
|
|
254
|
-
__name(startGraphiQL_default, "default");
|
|
255
249
|
|
|
256
250
|
// src/buildSchema/index.ts
|
|
257
251
|
import { GraphQLSchema } from "graphql";
|
|
@@ -269,7 +263,7 @@ import { getFieldType as getFieldType2 } from "@orion-js/schema";
|
|
|
269
263
|
import { GraphQLScalarType } from "graphql";
|
|
270
264
|
var MAX_INT = Number.MAX_SAFE_INTEGER;
|
|
271
265
|
var MIN_INT = Number.MIN_SAFE_INTEGER;
|
|
272
|
-
var coerceBigInt =
|
|
266
|
+
var coerceBigInt = function coerceBigInt2(value) {
|
|
273
267
|
if (value === "") {
|
|
274
268
|
throw new TypeError("BigInt cannot represent non 53-bit signed integer value: (empty string)");
|
|
275
269
|
}
|
|
@@ -282,7 +276,7 @@ var coerceBigInt = /* @__PURE__ */ __name(function coerceBigInt2(value) {
|
|
|
282
276
|
throw new TypeError("BigInt cannot represent non-integer value: " + String(value));
|
|
283
277
|
}
|
|
284
278
|
return int;
|
|
285
|
-
}
|
|
279
|
+
};
|
|
286
280
|
var BigIntScalar_default = new GraphQLScalarType({
|
|
287
281
|
name: "BigInt",
|
|
288
282
|
description: "The `BigInt` scalar type represents non-fractional signed whole numeric values. BigInt can represent values between -(2^53) + 1 and 2^53 - 1. ",
|
|
@@ -314,7 +308,6 @@ import { GraphQLScalarType as GraphQLScalarType3, Kind } from "graphql";
|
|
|
314
308
|
function identity(value) {
|
|
315
309
|
return value;
|
|
316
310
|
}
|
|
317
|
-
__name(identity, "identity");
|
|
318
311
|
function parseLiteral(ast, variables) {
|
|
319
312
|
switch (ast.kind) {
|
|
320
313
|
case Kind.STRING:
|
|
@@ -342,7 +335,6 @@ function parseLiteral(ast, variables) {
|
|
|
342
335
|
return void 0;
|
|
343
336
|
}
|
|
344
337
|
}
|
|
345
|
-
__name(parseLiteral, "parseLiteral");
|
|
346
338
|
var JSONScalar_default = new GraphQLScalarType3({
|
|
347
339
|
name: "JSON",
|
|
348
340
|
description: "The `JSON` scalar type represents JSON values as specified by [ECMA-404](http://www.ecma-international.org/publications/files/ECMA-ST/ECMA-404.pdf).",
|
|
@@ -378,7 +370,6 @@ function getScalar_default(fieldType) {
|
|
|
378
370
|
}
|
|
379
371
|
throw new Error(`Field type "${fieldType.name}" has no convertion to GraphQLType`);
|
|
380
372
|
}
|
|
381
|
-
__name(getScalar_default, "default");
|
|
382
373
|
|
|
383
374
|
// src/buildSchema/getArgs/getField.ts
|
|
384
375
|
import isPlainObject from "lodash/isPlainObject";
|
|
@@ -399,11 +390,10 @@ function getStaticFields(model) {
|
|
|
399
390
|
};
|
|
400
391
|
}).filter((field) => !field.private);
|
|
401
392
|
}
|
|
402
|
-
__name(getStaticFields, "getStaticFields");
|
|
403
393
|
|
|
404
394
|
// src/buildSchema/getArgs/getField.ts
|
|
405
395
|
var storedModelInput = {};
|
|
406
|
-
var getModelInput =
|
|
396
|
+
var getModelInput = function(model, fields) {
|
|
407
397
|
if (storedModelInput[model.name]) {
|
|
408
398
|
return storedModelInput[model.name];
|
|
409
399
|
}
|
|
@@ -412,7 +402,7 @@ var getModelInput = /* @__PURE__ */ __name(function(model, fields) {
|
|
|
412
402
|
fields
|
|
413
403
|
});
|
|
414
404
|
return storedModelInput[model.name];
|
|
415
|
-
}
|
|
405
|
+
};
|
|
416
406
|
function getParams(type) {
|
|
417
407
|
if (!type) {
|
|
418
408
|
throw new Error(`No type specified`);
|
|
@@ -436,7 +426,6 @@ function getParams(type) {
|
|
|
436
426
|
return graphQLType;
|
|
437
427
|
}
|
|
438
428
|
}
|
|
439
|
-
__name(getParams, "getParams");
|
|
440
429
|
|
|
441
430
|
// src/buildSchema/getArgs/index.ts
|
|
442
431
|
function getArgs_default(params) {
|
|
@@ -446,16 +435,13 @@ function getArgs_default(params) {
|
|
|
446
435
|
for (const key of Object.keys(params)) {
|
|
447
436
|
try {
|
|
448
437
|
const type = getParams(params[key].type);
|
|
449
|
-
fields[key] = {
|
|
450
|
-
type
|
|
451
|
-
};
|
|
438
|
+
fields[key] = { type };
|
|
452
439
|
} catch (error) {
|
|
453
440
|
throw new Error(`Error creating GraphQL resolver params argument ${key}: ${error.message}`);
|
|
454
441
|
}
|
|
455
442
|
}
|
|
456
443
|
return fields;
|
|
457
444
|
}
|
|
458
|
-
__name(getArgs_default, "default");
|
|
459
445
|
|
|
460
446
|
// src/errorHandler.ts
|
|
461
447
|
import crypto from "crypto";
|
|
@@ -489,7 +475,6 @@ function errorHandler(error, data) {
|
|
|
489
475
|
});
|
|
490
476
|
}
|
|
491
477
|
}
|
|
492
|
-
__name(errorHandler, "errorHandler");
|
|
493
478
|
|
|
494
479
|
// src/buildSchema/getType/getTypeAsResolver.ts
|
|
495
480
|
function getTypeAsResolver_default({ resolver: resolver4, getGraphQLType: getGraphQLType2, options, model }) {
|
|
@@ -503,18 +488,12 @@ function getTypeAsResolver_default({ resolver: resolver4, getGraphQLType: getGra
|
|
|
503
488
|
const result = await resolver4.resolve(item, params, context, info);
|
|
504
489
|
return result;
|
|
505
490
|
} catch (error) {
|
|
506
|
-
errorHandler(error, {
|
|
507
|
-
context,
|
|
508
|
-
resolver: resolver4,
|
|
509
|
-
options,
|
|
510
|
-
model
|
|
511
|
-
});
|
|
491
|
+
errorHandler(error, { context, resolver: resolver4, options, model });
|
|
512
492
|
throw error;
|
|
513
493
|
}
|
|
514
494
|
}
|
|
515
495
|
};
|
|
516
496
|
}
|
|
517
|
-
__name(getTypeAsResolver_default, "default");
|
|
518
497
|
|
|
519
498
|
// src/resolversSchemas/getDynamicFields.ts
|
|
520
499
|
function getDynamicFields(model) {
|
|
@@ -529,7 +508,6 @@ function getDynamicFields(model) {
|
|
|
529
508
|
};
|
|
530
509
|
}).filter((resolver4) => !resolver4.private);
|
|
531
510
|
}
|
|
532
|
-
__name(getDynamicFields, "getDynamicFields");
|
|
533
511
|
|
|
534
512
|
// src/resolversSchemas/getModelLoadedResolvers.ts
|
|
535
513
|
function getModelLoadedResolvers(model, options) {
|
|
@@ -545,7 +523,6 @@ function getModelLoadedResolvers(model, options) {
|
|
|
545
523
|
};
|
|
546
524
|
}).filter((resolver4) => !resolver4.private);
|
|
547
525
|
}
|
|
548
|
-
__name(getModelLoadedResolvers, "getModelLoadedResolvers");
|
|
549
526
|
|
|
550
527
|
// src/buildSchema/getType/index.ts
|
|
551
528
|
function getGraphQLType(type, options) {
|
|
@@ -563,7 +540,7 @@ function getGraphQLType(type, options) {
|
|
|
563
540
|
if (model.graphQLType) return model.graphQLType;
|
|
564
541
|
model.graphQLType = new GraphQLObjectType({
|
|
565
542
|
name: model.name,
|
|
566
|
-
fields:
|
|
543
|
+
fields: () => {
|
|
567
544
|
const fields = {};
|
|
568
545
|
for (const field of getStaticFields(model)) {
|
|
569
546
|
try {
|
|
@@ -585,30 +562,24 @@ function getGraphQLType(type, options) {
|
|
|
585
562
|
}
|
|
586
563
|
for (const resolver4 of getDynamicFields(model)) {
|
|
587
564
|
try {
|
|
588
|
-
fields[resolver4.key] = getTypeAsResolver_default({
|
|
589
|
-
resolver: resolver4,
|
|
590
|
-
getGraphQLType,
|
|
591
|
-
options,
|
|
592
|
-
model
|
|
593
|
-
});
|
|
565
|
+
fields[resolver4.key] = getTypeAsResolver_default({ resolver: resolver4, getGraphQLType, options, model });
|
|
594
566
|
} catch (error) {
|
|
595
|
-
throw new Error(
|
|
567
|
+
throw new Error(
|
|
568
|
+
`Error getting resolver type for resolver "${resolver4.key}": ${error.message}`
|
|
569
|
+
);
|
|
596
570
|
}
|
|
597
571
|
}
|
|
598
572
|
for (const resolver4 of getModelLoadedResolvers(model, options)) {
|
|
599
573
|
try {
|
|
600
|
-
fields[resolver4.key] = getTypeAsResolver_default({
|
|
601
|
-
resolver: resolver4,
|
|
602
|
-
getGraphQLType,
|
|
603
|
-
options,
|
|
604
|
-
model
|
|
605
|
-
});
|
|
574
|
+
fields[resolver4.key] = getTypeAsResolver_default({ resolver: resolver4, getGraphQLType, options, model });
|
|
606
575
|
} catch (error) {
|
|
607
|
-
throw new Error(
|
|
576
|
+
throw new Error(
|
|
577
|
+
`Error getting resolver type for resolver "${resolver4.key}": ${error.message}`
|
|
578
|
+
);
|
|
608
579
|
}
|
|
609
580
|
}
|
|
610
581
|
return fields;
|
|
611
|
-
}
|
|
582
|
+
}
|
|
612
583
|
});
|
|
613
584
|
return model.graphQLType;
|
|
614
585
|
} else {
|
|
@@ -617,7 +588,6 @@ function getGraphQLType(type, options) {
|
|
|
617
588
|
return graphQLType;
|
|
618
589
|
}
|
|
619
590
|
}
|
|
620
|
-
__name(getGraphQLType, "getGraphQLType");
|
|
621
591
|
|
|
622
592
|
// src/buildSchema/getResolvers/resolversStore.ts
|
|
623
593
|
var resolversStore = {};
|
|
@@ -644,12 +614,7 @@ async function getResolvers_default(options, mutation) {
|
|
|
644
614
|
const result = await resolver4.resolve(params, context, info);
|
|
645
615
|
return result;
|
|
646
616
|
} catch (error) {
|
|
647
|
-
errorHandler(error, {
|
|
648
|
-
context,
|
|
649
|
-
resolver: resolver4,
|
|
650
|
-
options,
|
|
651
|
-
name
|
|
652
|
-
});
|
|
617
|
+
errorHandler(error, { context, resolver: resolver4, options, name });
|
|
653
618
|
throw error;
|
|
654
619
|
}
|
|
655
620
|
}
|
|
@@ -657,7 +622,6 @@ async function getResolvers_default(options, mutation) {
|
|
|
657
622
|
}
|
|
658
623
|
return fields;
|
|
659
624
|
}
|
|
660
|
-
__name(getResolvers_default, "default");
|
|
661
625
|
|
|
662
626
|
// src/buildSchema/getQuery.ts
|
|
663
627
|
import isEmpty from "lodash/isEmpty";
|
|
@@ -669,7 +633,6 @@ async function getQuery_default(options) {
|
|
|
669
633
|
fields
|
|
670
634
|
});
|
|
671
635
|
}
|
|
672
|
-
__name(getQuery_default, "default");
|
|
673
636
|
|
|
674
637
|
// src/buildSchema/getMutation.ts
|
|
675
638
|
import { GraphQLObjectType as GraphQLObjectType3 } from "graphql";
|
|
@@ -682,7 +645,6 @@ async function getMutation_default(options) {
|
|
|
682
645
|
fields
|
|
683
646
|
});
|
|
684
647
|
}
|
|
685
|
-
__name(getMutation_default, "default");
|
|
686
648
|
|
|
687
649
|
// src/buildSchema/getSubscription.ts
|
|
688
650
|
import { GraphQLObjectType as GraphQLObjectType4 } from "graphql";
|
|
@@ -706,7 +668,6 @@ async function getSubscriptions_default(options) {
|
|
|
706
668
|
}
|
|
707
669
|
return fields;
|
|
708
670
|
}
|
|
709
|
-
__name(getSubscriptions_default, "default");
|
|
710
671
|
|
|
711
672
|
// src/buildSchema/getSubscription.ts
|
|
712
673
|
async function getSubscription_default(options) {
|
|
@@ -717,27 +678,19 @@ async function getSubscription_default(options) {
|
|
|
717
678
|
fields
|
|
718
679
|
});
|
|
719
680
|
}
|
|
720
|
-
__name(getSubscription_default, "default");
|
|
721
681
|
|
|
722
682
|
// src/buildSchema/index.ts
|
|
723
683
|
async function buildSchema_default(options) {
|
|
724
684
|
const query = await getQuery_default(options);
|
|
725
685
|
const mutation = await getMutation_default(options);
|
|
726
686
|
const subscription = await getSubscription_default(options);
|
|
727
|
-
const schema = new GraphQLSchema({
|
|
728
|
-
query,
|
|
729
|
-
mutation,
|
|
730
|
-
subscription
|
|
731
|
-
});
|
|
687
|
+
const schema = new GraphQLSchema({ query, mutation, subscription });
|
|
732
688
|
return schema;
|
|
733
689
|
}
|
|
734
|
-
__name(buildSchema_default, "default");
|
|
735
690
|
|
|
736
691
|
// src/getApolloOptions/formatError.ts
|
|
737
692
|
function formatError_default(apolloError) {
|
|
738
|
-
let response = {
|
|
739
|
-
...apolloError
|
|
740
|
-
};
|
|
693
|
+
let response = { ...apolloError };
|
|
741
694
|
const error = apolloError.originalError;
|
|
742
695
|
if (error && error.isValidationError) {
|
|
743
696
|
response.validationErrors = error.validationErrors;
|
|
@@ -747,7 +700,6 @@ function formatError_default(apolloError) {
|
|
|
747
700
|
}
|
|
748
701
|
return response;
|
|
749
702
|
}
|
|
750
|
-
__name(formatError_default, "default");
|
|
751
703
|
|
|
752
704
|
// src/getApolloOptions/index.ts
|
|
753
705
|
import { omit } from "lodash";
|
|
@@ -768,7 +720,6 @@ async function getApolloOptions_default(options) {
|
|
|
768
720
|
formatError: formatError_default
|
|
769
721
|
};
|
|
770
722
|
}
|
|
771
|
-
__name(getApolloOptions_default, "default");
|
|
772
723
|
|
|
773
724
|
// src/startWebsocket.ts
|
|
774
725
|
import { PubSub } from "graphql-subscriptions";
|
|
@@ -777,7 +728,7 @@ import { useServer } from "graphql-ws/lib/use/ws";
|
|
|
777
728
|
|
|
778
729
|
// src/websockerViewer.ts
|
|
779
730
|
global.getWebsocketViewerRef = () => null;
|
|
780
|
-
var getWebsockerViewer =
|
|
731
|
+
var getWebsockerViewer = async (connectionParams) => {
|
|
781
732
|
try {
|
|
782
733
|
const viewer = await global.getWebsocketViewerRef(connectionParams);
|
|
783
734
|
if (!viewer) return {};
|
|
@@ -785,10 +736,10 @@ var getWebsockerViewer = /* @__PURE__ */ __name(async (connectionParams) => {
|
|
|
785
736
|
} catch {
|
|
786
737
|
return {};
|
|
787
738
|
}
|
|
788
|
-
}
|
|
789
|
-
var setGetWebsockerViewer =
|
|
739
|
+
};
|
|
740
|
+
var setGetWebsockerViewer = (getViewerFunc) => {
|
|
790
741
|
global.getWebsocketViewerRef = getViewerFunc;
|
|
791
|
-
}
|
|
742
|
+
};
|
|
792
743
|
|
|
793
744
|
// src/startWebsocket.ts
|
|
794
745
|
import { getServer } from "@orion-js/http";
|
|
@@ -804,12 +755,15 @@ function startWebsocket_default(apolloOptions, options, wsServer) {
|
|
|
804
755
|
path: "/subscriptions"
|
|
805
756
|
});
|
|
806
757
|
}
|
|
807
|
-
const serverCleanup = useServer(
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
758
|
+
const serverCleanup = useServer(
|
|
759
|
+
{
|
|
760
|
+
schema: apolloOptions.schema,
|
|
761
|
+
context: async (ctx, msg, args) => {
|
|
762
|
+
return getWebsockerViewer(ctx.connectionParams);
|
|
763
|
+
}
|
|
764
|
+
},
|
|
765
|
+
wsServer
|
|
766
|
+
);
|
|
813
767
|
return [
|
|
814
768
|
// Proper shutdown for the WebSocket server.
|
|
815
769
|
{
|
|
@@ -823,7 +777,6 @@ function startWebsocket_default(apolloOptions, options, wsServer) {
|
|
|
823
777
|
}
|
|
824
778
|
];
|
|
825
779
|
}
|
|
826
|
-
__name(startWebsocket_default, "default");
|
|
827
780
|
|
|
828
781
|
// src/startGraphQL.ts
|
|
829
782
|
import { getApp, getServer as getServer2, registerRoute as registerRoute2, route as route2 } from "@orion-js/http";
|
|
@@ -838,36 +791,29 @@ async function startGraphQL_default(options) {
|
|
|
838
791
|
startGraphiQL_default(apolloOptions, options);
|
|
839
792
|
}
|
|
840
793
|
const subPlugins = startWebsocket_default(apolloOptions, options);
|
|
841
|
-
const drainPlugins = httpServer ? [
|
|
842
|
-
ApolloServerPluginDrainHttpServer({
|
|
843
|
-
httpServer
|
|
844
|
-
})
|
|
845
|
-
] : [];
|
|
794
|
+
const drainPlugins = httpServer ? [ApolloServerPluginDrainHttpServer({ httpServer })] : [];
|
|
846
795
|
const server = new ApolloServer({
|
|
847
796
|
...apolloOptions,
|
|
848
|
-
plugins: [
|
|
849
|
-
...apolloOptions.plugins || [],
|
|
850
|
-
...drainPlugins,
|
|
851
|
-
...subPlugins
|
|
852
|
-
]
|
|
797
|
+
plugins: [...apolloOptions.plugins || [], ...drainPlugins, ...subPlugins]
|
|
853
798
|
});
|
|
854
799
|
await server.start();
|
|
855
800
|
const middleware = expressMiddleware(server, {
|
|
856
801
|
// @ts-expect-error
|
|
857
|
-
context:
|
|
802
|
+
context: ({ req, res }) => req._viewer
|
|
858
803
|
});
|
|
859
|
-
registerRoute2(
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
req
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
804
|
+
registerRoute2(
|
|
805
|
+
route2({
|
|
806
|
+
app,
|
|
807
|
+
method: "all",
|
|
808
|
+
path: "/graphql",
|
|
809
|
+
bodyParser: "json",
|
|
810
|
+
async resolve(req, res, viewer) {
|
|
811
|
+
req._viewer = viewer;
|
|
812
|
+
return middleware(req, res, req.next);
|
|
813
|
+
}
|
|
814
|
+
})
|
|
815
|
+
);
|
|
869
816
|
}
|
|
870
|
-
__name(startGraphQL_default, "default");
|
|
871
817
|
|
|
872
818
|
// src/resolversSchemas/params.ts
|
|
873
819
|
import { resolver as resolver2 } from "@orion-js/resolvers";
|
|
@@ -882,20 +828,12 @@ async function getParams2(field) {
|
|
|
882
828
|
let { type } = field;
|
|
883
829
|
if (typeof type === "function" && type.getModel && type.__schemaId) {
|
|
884
830
|
const model = type.getModel();
|
|
885
|
-
return await getParams2({
|
|
886
|
-
...field,
|
|
887
|
-
type: model
|
|
888
|
-
});
|
|
831
|
+
return await getParams2({ ...field, type: model });
|
|
889
832
|
} else if (isArray3(type)) {
|
|
890
|
-
const serialized = await getParams2({
|
|
891
|
-
...field,
|
|
892
|
-
type: type[0]
|
|
893
|
-
});
|
|
833
|
+
const serialized = await getParams2({ ...field, type: type[0] });
|
|
894
834
|
return {
|
|
895
835
|
...serialized,
|
|
896
|
-
type: [
|
|
897
|
-
serialized.type
|
|
898
|
-
],
|
|
836
|
+
type: [serialized.type],
|
|
899
837
|
__graphQLType: `[${serialized.__graphQLType}]`
|
|
900
838
|
};
|
|
901
839
|
} else if (!type._isFieldType && (isPlainObject3(type) || type.__isModel)) {
|
|
@@ -920,7 +858,6 @@ async function getParams2(field) {
|
|
|
920
858
|
};
|
|
921
859
|
}
|
|
922
860
|
}
|
|
923
|
-
__name(getParams2, "getParams");
|
|
924
861
|
|
|
925
862
|
// src/resolversSchemas/serializeSchema.ts
|
|
926
863
|
async function serializeSchema(params) {
|
|
@@ -936,7 +873,6 @@ async function serializeSchema(params) {
|
|
|
936
873
|
}
|
|
937
874
|
return fields;
|
|
938
875
|
}
|
|
939
|
-
__name(serializeSchema, "serializeSchema");
|
|
940
876
|
|
|
941
877
|
// src/resolversSchemas/getBasicResultQuery.ts
|
|
942
878
|
import isArray4 from "lodash/isArray";
|
|
@@ -954,15 +890,14 @@ async function getBasicQuery(field) {
|
|
|
954
890
|
return field.key;
|
|
955
891
|
}
|
|
956
892
|
}
|
|
957
|
-
__name(getBasicQuery, "getBasicQuery");
|
|
958
893
|
|
|
959
894
|
// src/resolversSchemas/ResolverParamsInfo.ts
|
|
960
895
|
import { createModel } from "@orion-js/models";
|
|
961
896
|
import { resolver } from "@orion-js/resolvers";
|
|
962
897
|
import { isArray as isArray5 } from "lodash";
|
|
963
|
-
var resolverReturnsIsModel =
|
|
898
|
+
var resolverReturnsIsModel = (returns) => {
|
|
964
899
|
return returns && returns.__isModel;
|
|
965
|
-
}
|
|
900
|
+
};
|
|
966
901
|
var ResolverParamsInfo_default = createModel({
|
|
967
902
|
name: "ResolverParams",
|
|
968
903
|
schema: {
|
|
@@ -973,26 +908,26 @@ var ResolverParamsInfo_default = createModel({
|
|
|
973
908
|
resolvers: {
|
|
974
909
|
params: resolver({
|
|
975
910
|
returns: "blackbox",
|
|
976
|
-
resolve:
|
|
911
|
+
resolve: async function({ resolver: resolver4 }) {
|
|
977
912
|
return await serializeSchema(resolver4.params);
|
|
978
|
-
}
|
|
913
|
+
}
|
|
979
914
|
}),
|
|
980
915
|
result: resolver({
|
|
981
916
|
returns: String,
|
|
982
|
-
resolve:
|
|
917
|
+
resolve: async function({ resolver: resolver4 }) {
|
|
983
918
|
const returns = isArray5(resolver4.returns) ? resolver4.returns[0] : resolver4.returns;
|
|
984
919
|
if (resolverReturnsIsModel(returns)) return returns.name;
|
|
985
920
|
return;
|
|
986
|
-
}
|
|
921
|
+
}
|
|
987
922
|
}),
|
|
988
923
|
basicResultQuery: resolver({
|
|
989
924
|
returns: String,
|
|
990
|
-
resolve:
|
|
925
|
+
resolve: async function({ resolver: resolver4 }) {
|
|
991
926
|
const returns = isArray5(resolver4.returns) ? resolver4.returns[0] : resolver4.returns;
|
|
992
927
|
return await getBasicQuery({
|
|
993
928
|
type: resolverReturnsIsModel(returns) ? returns.getSchema() : ""
|
|
994
929
|
});
|
|
995
|
-
}
|
|
930
|
+
}
|
|
996
931
|
})
|
|
997
932
|
}
|
|
998
933
|
});
|
|
@@ -1009,19 +944,19 @@ var params_default = resolver2({
|
|
|
1009
944
|
},
|
|
1010
945
|
returns: ResolverParamsInfo_default,
|
|
1011
946
|
mutation: false,
|
|
1012
|
-
resolve:
|
|
947
|
+
resolve: async function({ mutation, name }, viewer) {
|
|
1013
948
|
const resolver4 = resolversStore[name];
|
|
1014
949
|
if (!resolver4) {
|
|
1015
|
-
throw new UserError(
|
|
950
|
+
throw new UserError(
|
|
951
|
+
"notFound",
|
|
952
|
+
`${mutation ? "Mutation" : "Query"} named "${name}" not found`
|
|
953
|
+
);
|
|
1016
954
|
}
|
|
1017
955
|
if (!!resolver4.mutation !== !!mutation) {
|
|
1018
956
|
throw new UserError("incorrectType", `"${name}" is ${mutation ? "not" : ""} a mutation`);
|
|
1019
957
|
}
|
|
1020
|
-
return {
|
|
1021
|
-
|
|
1022
|
-
name
|
|
1023
|
-
};
|
|
1024
|
-
}, "resolve")
|
|
958
|
+
return { resolver: resolver4, name };
|
|
959
|
+
}
|
|
1025
960
|
});
|
|
1026
961
|
|
|
1027
962
|
// src/resolversSchemas/index.ts
|
|
@@ -1033,15 +968,13 @@ var resolversSchemas_default = {
|
|
|
1033
968
|
import * as GraphQL2 from "graphql";
|
|
1034
969
|
|
|
1035
970
|
// src/types/subscription.ts
|
|
1036
|
-
var
|
|
971
|
+
var OrionSubscription = class {
|
|
1037
972
|
name;
|
|
1038
973
|
params;
|
|
1039
974
|
subscribe;
|
|
1040
975
|
returns;
|
|
1041
976
|
publish;
|
|
1042
977
|
};
|
|
1043
|
-
__name(_OrionSubscription, "OrionSubscription");
|
|
1044
|
-
var OrionSubscription = _OrionSubscription;
|
|
1045
978
|
|
|
1046
979
|
// src/service/global.ts
|
|
1047
980
|
import { getInstance, Service } from "@orion-js/services";
|
|
@@ -1063,12 +996,10 @@ function createRegisterResolverMetadata(metadataKey, isArray6 = false) {
|
|
|
1063
996
|
};
|
|
1064
997
|
};
|
|
1065
998
|
}
|
|
1066
|
-
__name(createRegisterResolverMetadata, "createRegisterResolverMetadata");
|
|
1067
999
|
function getTargetMetadata(target, propertyKey, metadataKey) {
|
|
1068
1000
|
const items = target[metadataKey] || {};
|
|
1069
1001
|
return items[propertyKey] || [];
|
|
1070
1002
|
}
|
|
1071
|
-
__name(getTargetMetadata, "getTargetMetadata");
|
|
1072
1003
|
var UseMiddleware = createRegisterResolverMetadata("middlewares", true);
|
|
1073
1004
|
var ResolverParams = createRegisterResolverMetadata("params");
|
|
1074
1005
|
var ResolverReturns = createRegisterResolverMetadata("returns");
|
|
@@ -1080,7 +1011,6 @@ function Resolvers() {
|
|
|
1080
1011
|
target.prototype.service = target;
|
|
1081
1012
|
};
|
|
1082
1013
|
}
|
|
1083
|
-
__name(Resolvers, "Resolvers");
|
|
1084
1014
|
function Query(options) {
|
|
1085
1015
|
return (target, propertyKey, descriptor) => {
|
|
1086
1016
|
if (!descriptor.value) throw new Error(`You must pass resolver function to ${propertyKey}`);
|
|
@@ -1091,14 +1021,13 @@ function Query(options) {
|
|
|
1091
1021
|
returns: getTargetMetadata(target, propertyKey, "returns"),
|
|
1092
1022
|
middlewares: getTargetMetadata(target, propertyKey, "middlewares"),
|
|
1093
1023
|
...options,
|
|
1094
|
-
resolve:
|
|
1024
|
+
resolve: async (params, viewer, info) => {
|
|
1095
1025
|
const instance = getInstance(target.service);
|
|
1096
1026
|
return await instance[propertyKey](params, viewer, info);
|
|
1097
|
-
}
|
|
1027
|
+
}
|
|
1098
1028
|
});
|
|
1099
1029
|
};
|
|
1100
1030
|
}
|
|
1101
|
-
__name(Query, "Query");
|
|
1102
1031
|
function Mutation(options) {
|
|
1103
1032
|
return (target, propertyKey, descriptor) => {
|
|
1104
1033
|
if (!descriptor.value) throw new Error(`You must pass resolver function to ${propertyKey}`);
|
|
@@ -1110,25 +1039,25 @@ function Mutation(options) {
|
|
|
1110
1039
|
middlewares: getTargetMetadata(target, propertyKey, "middlewares"),
|
|
1111
1040
|
...options,
|
|
1112
1041
|
mutation: true,
|
|
1113
|
-
resolve:
|
|
1042
|
+
resolve: async (params, viewer, info) => {
|
|
1114
1043
|
const instance = getInstance(target.service);
|
|
1115
1044
|
return await instance[propertyKey](params, viewer, info);
|
|
1116
|
-
}
|
|
1045
|
+
}
|
|
1117
1046
|
});
|
|
1118
1047
|
};
|
|
1119
1048
|
}
|
|
1120
|
-
__name(Mutation, "Mutation");
|
|
1121
1049
|
function getServiceResolvers(target) {
|
|
1122
1050
|
if (!target.prototype) {
|
|
1123
1051
|
throw new UserError2("You must pass a class to getResolvers");
|
|
1124
1052
|
}
|
|
1125
1053
|
return target.prototype.resolvers || {};
|
|
1126
1054
|
}
|
|
1127
|
-
__name(getServiceResolvers, "getServiceResolvers");
|
|
1128
1055
|
|
|
1129
1056
|
// src/service/model.ts
|
|
1130
1057
|
import { getInstance as getInstance2, Service as Service2 } from "@orion-js/services";
|
|
1131
|
-
import {
|
|
1058
|
+
import {
|
|
1059
|
+
modelResolver
|
|
1060
|
+
} from "@orion-js/resolvers";
|
|
1132
1061
|
import { UserError as UserError3 } from "@orion-js/helpers";
|
|
1133
1062
|
function ModelResolver(options) {
|
|
1134
1063
|
return (target, propertyKey, descriptor) => {
|
|
@@ -1139,14 +1068,13 @@ function ModelResolver(options) {
|
|
|
1139
1068
|
returns: getTargetMetadata(target, propertyKey, "returns"),
|
|
1140
1069
|
middlewares: getTargetMetadata(target, propertyKey, "middlewares"),
|
|
1141
1070
|
...options,
|
|
1142
|
-
resolve:
|
|
1071
|
+
resolve: async (item, params, viewer, info) => {
|
|
1143
1072
|
const instance = getInstance2(target.service);
|
|
1144
1073
|
return await instance[propertyKey](item, params, viewer, info);
|
|
1145
|
-
}
|
|
1074
|
+
}
|
|
1146
1075
|
});
|
|
1147
1076
|
};
|
|
1148
1077
|
}
|
|
1149
|
-
__name(ModelResolver, "ModelResolver");
|
|
1150
1078
|
function ModelResolvers(typedSchema, options = {}) {
|
|
1151
1079
|
return (target) => {
|
|
1152
1080
|
Service2()(target);
|
|
@@ -1159,7 +1087,6 @@ function ModelResolvers(typedSchema, options = {}) {
|
|
|
1159
1087
|
target.getModel = () => getModelForClass(target);
|
|
1160
1088
|
};
|
|
1161
1089
|
}
|
|
1162
|
-
__name(ModelResolvers, "ModelResolvers");
|
|
1163
1090
|
function getServiceModelResolvers(target) {
|
|
1164
1091
|
if (!target.prototype) {
|
|
1165
1092
|
throw new UserError3("You must pass a class to getResolvers");
|
|
@@ -1168,7 +1095,6 @@ function getServiceModelResolvers(target) {
|
|
|
1168
1095
|
[target.prototype.modelName]: target.prototype.resolvers || {}
|
|
1169
1096
|
};
|
|
1170
1097
|
}
|
|
1171
|
-
__name(getServiceModelResolvers, "getServiceModelResolvers");
|
|
1172
1098
|
|
|
1173
1099
|
// src/service/subscription.ts
|
|
1174
1100
|
import { Container, Service as Service3 } from "@orion-js/services";
|
|
@@ -1180,7 +1106,6 @@ function Subscriptions() {
|
|
|
1180
1106
|
target.prototype.serviceType = "subscriptions";
|
|
1181
1107
|
};
|
|
1182
1108
|
}
|
|
1183
|
-
__name(Subscriptions, "Subscriptions");
|
|
1184
1109
|
function Subscription(options) {
|
|
1185
1110
|
return (object, propertyName, index) => {
|
|
1186
1111
|
const sub = subscription_default({
|
|
@@ -1193,23 +1118,23 @@ function Subscription(options) {
|
|
|
1193
1118
|
object,
|
|
1194
1119
|
propertyName,
|
|
1195
1120
|
index,
|
|
1196
|
-
value:
|
|
1121
|
+
value: (_containerInstance) => {
|
|
1197
1122
|
if (!object.serviceType || object.serviceType !== "subscriptions") {
|
|
1198
|
-
throw new Error(
|
|
1123
|
+
throw new Error(
|
|
1124
|
+
"You must pass a class decorated with @Subscriptions if you want to use @Subscription"
|
|
1125
|
+
);
|
|
1199
1126
|
}
|
|
1200
1127
|
return sub;
|
|
1201
|
-
}
|
|
1128
|
+
}
|
|
1202
1129
|
});
|
|
1203
1130
|
};
|
|
1204
1131
|
}
|
|
1205
|
-
__name(Subscription, "Subscription");
|
|
1206
1132
|
function getServiceSubscriptions(target) {
|
|
1207
1133
|
if (!target.prototype) {
|
|
1208
1134
|
throw new UserError4("You must pass a class to getSubscriptions");
|
|
1209
1135
|
}
|
|
1210
1136
|
return target.prototype.subscriptions || {};
|
|
1211
1137
|
}
|
|
1212
|
-
__name(getServiceSubscriptions, "getServiceSubscriptions");
|
|
1213
1138
|
export {
|
|
1214
1139
|
GraphQL2 as GraphQL,
|
|
1215
1140
|
ModelResolver,
|