@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.cjs
CHANGED
|
@@ -4,7 +4,6 @@ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
|
4
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
5
|
var __getProtoOf = Object.getPrototypeOf;
|
|
6
6
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
-
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
8
7
|
var __export = (target, all) => {
|
|
9
8
|
for (var name in all)
|
|
10
9
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
@@ -60,12 +59,12 @@ module.exports = __toCommonJS(index_exports);
|
|
|
60
59
|
|
|
61
60
|
// src/pubsub.ts
|
|
62
61
|
var pubsub = null;
|
|
63
|
-
var setPubsub =
|
|
62
|
+
var setPubsub = function(newPubsub) {
|
|
64
63
|
pubsub = newPubsub;
|
|
65
|
-
}
|
|
66
|
-
var getPubsub =
|
|
64
|
+
};
|
|
65
|
+
var getPubsub = function() {
|
|
67
66
|
return pubsub;
|
|
68
|
-
}
|
|
67
|
+
};
|
|
69
68
|
|
|
70
69
|
// src/subscription/getChannelName.ts
|
|
71
70
|
var import_helpers = require("@orion-js/helpers");
|
|
@@ -74,29 +73,22 @@ function getChannelName_default(name, params) {
|
|
|
74
73
|
const channelName = `${name}_${hash}`;
|
|
75
74
|
return channelName;
|
|
76
75
|
}
|
|
77
|
-
__name(getChannelName_default, "default");
|
|
78
76
|
|
|
79
77
|
// src/subscription/index.ts
|
|
80
78
|
var import_resolvers = require("@orion-js/resolvers");
|
|
81
|
-
var createSubscription =
|
|
79
|
+
var createSubscription = function(options) {
|
|
82
80
|
const subscription = {
|
|
83
81
|
name: options.name
|
|
84
82
|
};
|
|
85
83
|
subscription.publish = async (params, data) => {
|
|
86
84
|
const pubsub2 = getPubsub();
|
|
87
85
|
const channelName = getChannelName_default(subscription.name, params);
|
|
88
|
-
await pubsub2.publish(channelName, {
|
|
89
|
-
[subscription.name]: data
|
|
90
|
-
});
|
|
86
|
+
await pubsub2.publish(channelName, { [subscription.name]: data });
|
|
91
87
|
};
|
|
92
88
|
subscription.subscribe = async (params, viewer) => {
|
|
93
89
|
const pubsub2 = getPubsub();
|
|
94
90
|
try {
|
|
95
|
-
await (0, import_resolvers.checkPermissions)({
|
|
96
|
-
params,
|
|
97
|
-
viewer,
|
|
98
|
-
options: null
|
|
99
|
-
}, options);
|
|
91
|
+
await (0, import_resolvers.checkPermissions)({ params, viewer, options: null }, options);
|
|
100
92
|
const channelName = getChannelName_default(subscription.name, params);
|
|
101
93
|
return pubsub2.asyncIterator(channelName);
|
|
102
94
|
} catch (error) {
|
|
@@ -106,7 +98,7 @@ var createSubscription = /* @__PURE__ */ __name(function(options) {
|
|
|
106
98
|
subscription.params = (0, import_resolvers.cleanParams)(options.params);
|
|
107
99
|
subscription.returns = (0, import_resolvers.cleanReturns)(options.returns);
|
|
108
100
|
return subscription;
|
|
109
|
-
}
|
|
101
|
+
};
|
|
110
102
|
var subscription_default = createSubscription;
|
|
111
103
|
|
|
112
104
|
// src/startGraphiQL.ts
|
|
@@ -114,8 +106,7 @@ var import_http = require("@orion-js/http");
|
|
|
114
106
|
function safeSerialize(data) {
|
|
115
107
|
return data ? JSON.stringify(data).replace(/\//g, "\\/") : null;
|
|
116
108
|
}
|
|
117
|
-
|
|
118
|
-
var getHTML = /* @__PURE__ */ __name(function(apolloOptions, options, data) {
|
|
109
|
+
var getHTML = function(apolloOptions, options, data) {
|
|
119
110
|
const GRAPHIQL_VERSION = "0.11.11";
|
|
120
111
|
const endpointURL = "/graphql";
|
|
121
112
|
const subscriptionsEndpoint = "/subscriptions";
|
|
@@ -296,19 +287,20 @@ var getHTML = /* @__PURE__ */ __name(function(apolloOptions, options, data) {
|
|
|
296
287
|
</script>
|
|
297
288
|
</body>
|
|
298
289
|
</html>`;
|
|
299
|
-
}
|
|
290
|
+
};
|
|
300
291
|
function startGraphiQL_default(apolloOptions, options) {
|
|
301
|
-
(0, import_http.registerRoute)(
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
292
|
+
(0, import_http.registerRoute)(
|
|
293
|
+
(0, import_http.route)({
|
|
294
|
+
path: "/graphiql",
|
|
295
|
+
method: "get",
|
|
296
|
+
async resolve(req) {
|
|
297
|
+
return {
|
|
298
|
+
body: getHTML(apolloOptions, options, req.query)
|
|
299
|
+
};
|
|
300
|
+
}
|
|
301
|
+
})
|
|
302
|
+
);
|
|
310
303
|
}
|
|
311
|
-
__name(startGraphiQL_default, "default");
|
|
312
304
|
|
|
313
305
|
// src/buildSchema/index.ts
|
|
314
306
|
var import_graphql10 = require("graphql");
|
|
@@ -326,7 +318,7 @@ var import_schema2 = require("@orion-js/schema");
|
|
|
326
318
|
var import_graphql = require("graphql");
|
|
327
319
|
var MAX_INT = Number.MAX_SAFE_INTEGER;
|
|
328
320
|
var MIN_INT = Number.MIN_SAFE_INTEGER;
|
|
329
|
-
var coerceBigInt =
|
|
321
|
+
var coerceBigInt = function coerceBigInt2(value) {
|
|
330
322
|
if (value === "") {
|
|
331
323
|
throw new TypeError("BigInt cannot represent non 53-bit signed integer value: (empty string)");
|
|
332
324
|
}
|
|
@@ -339,7 +331,7 @@ var coerceBigInt = /* @__PURE__ */ __name(function coerceBigInt2(value) {
|
|
|
339
331
|
throw new TypeError("BigInt cannot represent non-integer value: " + String(value));
|
|
340
332
|
}
|
|
341
333
|
return int;
|
|
342
|
-
}
|
|
334
|
+
};
|
|
343
335
|
var BigIntScalar_default = new import_graphql.GraphQLScalarType({
|
|
344
336
|
name: "BigInt",
|
|
345
337
|
description: "The `BigInt` scalar type represents non-fractional signed whole numeric values. BigInt can represent values between -(2^53) + 1 and 2^53 - 1. ",
|
|
@@ -371,7 +363,6 @@ var import_graphql3 = require("graphql");
|
|
|
371
363
|
function identity(value) {
|
|
372
364
|
return value;
|
|
373
365
|
}
|
|
374
|
-
__name(identity, "identity");
|
|
375
366
|
function parseLiteral(ast, variables) {
|
|
376
367
|
switch (ast.kind) {
|
|
377
368
|
case import_graphql3.Kind.STRING:
|
|
@@ -399,7 +390,6 @@ function parseLiteral(ast, variables) {
|
|
|
399
390
|
return void 0;
|
|
400
391
|
}
|
|
401
392
|
}
|
|
402
|
-
__name(parseLiteral, "parseLiteral");
|
|
403
393
|
var JSONScalar_default = new import_graphql3.GraphQLScalarType({
|
|
404
394
|
name: "JSON",
|
|
405
395
|
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).",
|
|
@@ -435,7 +425,6 @@ function getScalar_default(fieldType) {
|
|
|
435
425
|
}
|
|
436
426
|
throw new Error(`Field type "${fieldType.name}" has no convertion to GraphQLType`);
|
|
437
427
|
}
|
|
438
|
-
__name(getScalar_default, "default");
|
|
439
428
|
|
|
440
429
|
// src/buildSchema/getArgs/getField.ts
|
|
441
430
|
var import_isPlainObject = __toESM(require("lodash/isPlainObject"), 1);
|
|
@@ -456,11 +445,10 @@ function getStaticFields(model) {
|
|
|
456
445
|
};
|
|
457
446
|
}).filter((field) => !field.private);
|
|
458
447
|
}
|
|
459
|
-
__name(getStaticFields, "getStaticFields");
|
|
460
448
|
|
|
461
449
|
// src/buildSchema/getArgs/getField.ts
|
|
462
450
|
var storedModelInput = {};
|
|
463
|
-
var getModelInput =
|
|
451
|
+
var getModelInput = function(model, fields) {
|
|
464
452
|
if (storedModelInput[model.name]) {
|
|
465
453
|
return storedModelInput[model.name];
|
|
466
454
|
}
|
|
@@ -469,7 +457,7 @@ var getModelInput = /* @__PURE__ */ __name(function(model, fields) {
|
|
|
469
457
|
fields
|
|
470
458
|
});
|
|
471
459
|
return storedModelInput[model.name];
|
|
472
|
-
}
|
|
460
|
+
};
|
|
473
461
|
function getParams(type) {
|
|
474
462
|
if (!type) {
|
|
475
463
|
throw new Error(`No type specified`);
|
|
@@ -493,7 +481,6 @@ function getParams(type) {
|
|
|
493
481
|
return graphQLType;
|
|
494
482
|
}
|
|
495
483
|
}
|
|
496
|
-
__name(getParams, "getParams");
|
|
497
484
|
|
|
498
485
|
// src/buildSchema/getArgs/index.ts
|
|
499
486
|
function getArgs_default(params) {
|
|
@@ -503,16 +490,13 @@ function getArgs_default(params) {
|
|
|
503
490
|
for (const key of Object.keys(params)) {
|
|
504
491
|
try {
|
|
505
492
|
const type = getParams(params[key].type);
|
|
506
|
-
fields[key] = {
|
|
507
|
-
type
|
|
508
|
-
};
|
|
493
|
+
fields[key] = { type };
|
|
509
494
|
} catch (error) {
|
|
510
495
|
throw new Error(`Error creating GraphQL resolver params argument ${key}: ${error.message}`);
|
|
511
496
|
}
|
|
512
497
|
}
|
|
513
498
|
return fields;
|
|
514
499
|
}
|
|
515
|
-
__name(getArgs_default, "default");
|
|
516
500
|
|
|
517
501
|
// src/errorHandler.ts
|
|
518
502
|
var import_crypto = __toESM(require("crypto"), 1);
|
|
@@ -546,7 +530,6 @@ function errorHandler(error, data) {
|
|
|
546
530
|
});
|
|
547
531
|
}
|
|
548
532
|
}
|
|
549
|
-
__name(errorHandler, "errorHandler");
|
|
550
533
|
|
|
551
534
|
// src/buildSchema/getType/getTypeAsResolver.ts
|
|
552
535
|
function getTypeAsResolver_default({ resolver: resolver4, getGraphQLType: getGraphQLType2, options, model }) {
|
|
@@ -560,18 +543,12 @@ function getTypeAsResolver_default({ resolver: resolver4, getGraphQLType: getGra
|
|
|
560
543
|
const result = await resolver4.resolve(item, params, context, info);
|
|
561
544
|
return result;
|
|
562
545
|
} catch (error) {
|
|
563
|
-
errorHandler(error, {
|
|
564
|
-
context,
|
|
565
|
-
resolver: resolver4,
|
|
566
|
-
options,
|
|
567
|
-
model
|
|
568
|
-
});
|
|
546
|
+
errorHandler(error, { context, resolver: resolver4, options, model });
|
|
569
547
|
throw error;
|
|
570
548
|
}
|
|
571
549
|
}
|
|
572
550
|
};
|
|
573
551
|
}
|
|
574
|
-
__name(getTypeAsResolver_default, "default");
|
|
575
552
|
|
|
576
553
|
// src/resolversSchemas/getDynamicFields.ts
|
|
577
554
|
function getDynamicFields(model) {
|
|
@@ -586,7 +563,6 @@ function getDynamicFields(model) {
|
|
|
586
563
|
};
|
|
587
564
|
}).filter((resolver4) => !resolver4.private);
|
|
588
565
|
}
|
|
589
|
-
__name(getDynamicFields, "getDynamicFields");
|
|
590
566
|
|
|
591
567
|
// src/resolversSchemas/getModelLoadedResolvers.ts
|
|
592
568
|
function getModelLoadedResolvers(model, options) {
|
|
@@ -602,7 +578,6 @@ function getModelLoadedResolvers(model, options) {
|
|
|
602
578
|
};
|
|
603
579
|
}).filter((resolver4) => !resolver4.private);
|
|
604
580
|
}
|
|
605
|
-
__name(getModelLoadedResolvers, "getModelLoadedResolvers");
|
|
606
581
|
|
|
607
582
|
// src/buildSchema/getType/index.ts
|
|
608
583
|
function getGraphQLType(type, options) {
|
|
@@ -620,7 +595,7 @@ function getGraphQLType(type, options) {
|
|
|
620
595
|
if (model.graphQLType) return model.graphQLType;
|
|
621
596
|
model.graphQLType = new import_graphql6.GraphQLObjectType({
|
|
622
597
|
name: model.name,
|
|
623
|
-
fields:
|
|
598
|
+
fields: () => {
|
|
624
599
|
const fields = {};
|
|
625
600
|
for (const field of getStaticFields(model)) {
|
|
626
601
|
try {
|
|
@@ -642,30 +617,24 @@ function getGraphQLType(type, options) {
|
|
|
642
617
|
}
|
|
643
618
|
for (const resolver4 of getDynamicFields(model)) {
|
|
644
619
|
try {
|
|
645
|
-
fields[resolver4.key] = getTypeAsResolver_default({
|
|
646
|
-
resolver: resolver4,
|
|
647
|
-
getGraphQLType,
|
|
648
|
-
options,
|
|
649
|
-
model
|
|
650
|
-
});
|
|
620
|
+
fields[resolver4.key] = getTypeAsResolver_default({ resolver: resolver4, getGraphQLType, options, model });
|
|
651
621
|
} catch (error) {
|
|
652
|
-
throw new Error(
|
|
622
|
+
throw new Error(
|
|
623
|
+
`Error getting resolver type for resolver "${resolver4.key}": ${error.message}`
|
|
624
|
+
);
|
|
653
625
|
}
|
|
654
626
|
}
|
|
655
627
|
for (const resolver4 of getModelLoadedResolvers(model, options)) {
|
|
656
628
|
try {
|
|
657
|
-
fields[resolver4.key] = getTypeAsResolver_default({
|
|
658
|
-
resolver: resolver4,
|
|
659
|
-
getGraphQLType,
|
|
660
|
-
options,
|
|
661
|
-
model
|
|
662
|
-
});
|
|
629
|
+
fields[resolver4.key] = getTypeAsResolver_default({ resolver: resolver4, getGraphQLType, options, model });
|
|
663
630
|
} catch (error) {
|
|
664
|
-
throw new Error(
|
|
631
|
+
throw new Error(
|
|
632
|
+
`Error getting resolver type for resolver "${resolver4.key}": ${error.message}`
|
|
633
|
+
);
|
|
665
634
|
}
|
|
666
635
|
}
|
|
667
636
|
return fields;
|
|
668
|
-
}
|
|
637
|
+
}
|
|
669
638
|
});
|
|
670
639
|
return model.graphQLType;
|
|
671
640
|
} else {
|
|
@@ -674,7 +643,6 @@ function getGraphQLType(type, options) {
|
|
|
674
643
|
return graphQLType;
|
|
675
644
|
}
|
|
676
645
|
}
|
|
677
|
-
__name(getGraphQLType, "getGraphQLType");
|
|
678
646
|
|
|
679
647
|
// src/buildSchema/getResolvers/resolversStore.ts
|
|
680
648
|
var resolversStore = {};
|
|
@@ -701,12 +669,7 @@ async function getResolvers_default(options, mutation) {
|
|
|
701
669
|
const result = await resolver4.resolve(params, context, info);
|
|
702
670
|
return result;
|
|
703
671
|
} catch (error) {
|
|
704
|
-
errorHandler(error, {
|
|
705
|
-
context,
|
|
706
|
-
resolver: resolver4,
|
|
707
|
-
options,
|
|
708
|
-
name
|
|
709
|
-
});
|
|
672
|
+
errorHandler(error, { context, resolver: resolver4, options, name });
|
|
710
673
|
throw error;
|
|
711
674
|
}
|
|
712
675
|
}
|
|
@@ -714,7 +677,6 @@ async function getResolvers_default(options, mutation) {
|
|
|
714
677
|
}
|
|
715
678
|
return fields;
|
|
716
679
|
}
|
|
717
|
-
__name(getResolvers_default, "default");
|
|
718
680
|
|
|
719
681
|
// src/buildSchema/getQuery.ts
|
|
720
682
|
var import_isEmpty = __toESM(require("lodash/isEmpty"), 1);
|
|
@@ -726,7 +688,6 @@ async function getQuery_default(options) {
|
|
|
726
688
|
fields
|
|
727
689
|
});
|
|
728
690
|
}
|
|
729
|
-
__name(getQuery_default, "default");
|
|
730
691
|
|
|
731
692
|
// src/buildSchema/getMutation.ts
|
|
732
693
|
var import_graphql8 = require("graphql");
|
|
@@ -739,7 +700,6 @@ async function getMutation_default(options) {
|
|
|
739
700
|
fields
|
|
740
701
|
});
|
|
741
702
|
}
|
|
742
|
-
__name(getMutation_default, "default");
|
|
743
703
|
|
|
744
704
|
// src/buildSchema/getSubscription.ts
|
|
745
705
|
var import_graphql9 = require("graphql");
|
|
@@ -763,7 +723,6 @@ async function getSubscriptions_default(options) {
|
|
|
763
723
|
}
|
|
764
724
|
return fields;
|
|
765
725
|
}
|
|
766
|
-
__name(getSubscriptions_default, "default");
|
|
767
726
|
|
|
768
727
|
// src/buildSchema/getSubscription.ts
|
|
769
728
|
async function getSubscription_default(options) {
|
|
@@ -774,27 +733,19 @@ async function getSubscription_default(options) {
|
|
|
774
733
|
fields
|
|
775
734
|
});
|
|
776
735
|
}
|
|
777
|
-
__name(getSubscription_default, "default");
|
|
778
736
|
|
|
779
737
|
// src/buildSchema/index.ts
|
|
780
738
|
async function buildSchema_default(options) {
|
|
781
739
|
const query = await getQuery_default(options);
|
|
782
740
|
const mutation = await getMutation_default(options);
|
|
783
741
|
const subscription = await getSubscription_default(options);
|
|
784
|
-
const schema = new import_graphql10.GraphQLSchema({
|
|
785
|
-
query,
|
|
786
|
-
mutation,
|
|
787
|
-
subscription
|
|
788
|
-
});
|
|
742
|
+
const schema = new import_graphql10.GraphQLSchema({ query, mutation, subscription });
|
|
789
743
|
return schema;
|
|
790
744
|
}
|
|
791
|
-
__name(buildSchema_default, "default");
|
|
792
745
|
|
|
793
746
|
// src/getApolloOptions/formatError.ts
|
|
794
747
|
function formatError_default(apolloError) {
|
|
795
|
-
let response = {
|
|
796
|
-
...apolloError
|
|
797
|
-
};
|
|
748
|
+
let response = { ...apolloError };
|
|
798
749
|
const error = apolloError.originalError;
|
|
799
750
|
if (error && error.isValidationError) {
|
|
800
751
|
response.validationErrors = error.validationErrors;
|
|
@@ -804,7 +755,6 @@ function formatError_default(apolloError) {
|
|
|
804
755
|
}
|
|
805
756
|
return response;
|
|
806
757
|
}
|
|
807
|
-
__name(formatError_default, "default");
|
|
808
758
|
|
|
809
759
|
// src/getApolloOptions/index.ts
|
|
810
760
|
var import_lodash = require("lodash");
|
|
@@ -825,7 +775,6 @@ async function getApolloOptions_default(options) {
|
|
|
825
775
|
formatError: formatError_default
|
|
826
776
|
};
|
|
827
777
|
}
|
|
828
|
-
__name(getApolloOptions_default, "default");
|
|
829
778
|
|
|
830
779
|
// src/startWebsocket.ts
|
|
831
780
|
var import_graphql_subscriptions = require("graphql-subscriptions");
|
|
@@ -834,7 +783,7 @@ var import_ws2 = require("graphql-ws/lib/use/ws");
|
|
|
834
783
|
|
|
835
784
|
// src/websockerViewer.ts
|
|
836
785
|
global.getWebsocketViewerRef = () => null;
|
|
837
|
-
var getWebsockerViewer =
|
|
786
|
+
var getWebsockerViewer = async (connectionParams) => {
|
|
838
787
|
try {
|
|
839
788
|
const viewer = await global.getWebsocketViewerRef(connectionParams);
|
|
840
789
|
if (!viewer) return {};
|
|
@@ -842,10 +791,10 @@ var getWebsockerViewer = /* @__PURE__ */ __name(async (connectionParams) => {
|
|
|
842
791
|
} catch {
|
|
843
792
|
return {};
|
|
844
793
|
}
|
|
845
|
-
}
|
|
846
|
-
var setGetWebsockerViewer =
|
|
794
|
+
};
|
|
795
|
+
var setGetWebsockerViewer = (getViewerFunc) => {
|
|
847
796
|
global.getWebsocketViewerRef = getViewerFunc;
|
|
848
|
-
}
|
|
797
|
+
};
|
|
849
798
|
|
|
850
799
|
// src/startWebsocket.ts
|
|
851
800
|
var import_http2 = require("@orion-js/http");
|
|
@@ -861,12 +810,15 @@ function startWebsocket_default(apolloOptions, options, wsServer) {
|
|
|
861
810
|
path: "/subscriptions"
|
|
862
811
|
});
|
|
863
812
|
}
|
|
864
|
-
const serverCleanup = (0, import_ws2.useServer)(
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
813
|
+
const serverCleanup = (0, import_ws2.useServer)(
|
|
814
|
+
{
|
|
815
|
+
schema: apolloOptions.schema,
|
|
816
|
+
context: async (ctx, msg, args) => {
|
|
817
|
+
return getWebsockerViewer(ctx.connectionParams);
|
|
818
|
+
}
|
|
819
|
+
},
|
|
820
|
+
wsServer
|
|
821
|
+
);
|
|
870
822
|
return [
|
|
871
823
|
// Proper shutdown for the WebSocket server.
|
|
872
824
|
{
|
|
@@ -880,7 +832,6 @@ function startWebsocket_default(apolloOptions, options, wsServer) {
|
|
|
880
832
|
}
|
|
881
833
|
];
|
|
882
834
|
}
|
|
883
|
-
__name(startWebsocket_default, "default");
|
|
884
835
|
|
|
885
836
|
// src/startGraphQL.ts
|
|
886
837
|
var import_http3 = require("@orion-js/http");
|
|
@@ -895,36 +846,29 @@ async function startGraphQL_default(options) {
|
|
|
895
846
|
startGraphiQL_default(apolloOptions, options);
|
|
896
847
|
}
|
|
897
848
|
const subPlugins = startWebsocket_default(apolloOptions, options);
|
|
898
|
-
const drainPlugins = httpServer ? [
|
|
899
|
-
(0, import_drainHttpServer.ApolloServerPluginDrainHttpServer)({
|
|
900
|
-
httpServer
|
|
901
|
-
})
|
|
902
|
-
] : [];
|
|
849
|
+
const drainPlugins = httpServer ? [(0, import_drainHttpServer.ApolloServerPluginDrainHttpServer)({ httpServer })] : [];
|
|
903
850
|
const server = new import_server.ApolloServer({
|
|
904
851
|
...apolloOptions,
|
|
905
|
-
plugins: [
|
|
906
|
-
...apolloOptions.plugins || [],
|
|
907
|
-
...drainPlugins,
|
|
908
|
-
...subPlugins
|
|
909
|
-
]
|
|
852
|
+
plugins: [...apolloOptions.plugins || [], ...drainPlugins, ...subPlugins]
|
|
910
853
|
});
|
|
911
854
|
await server.start();
|
|
912
855
|
const middleware = (0, import_express4.expressMiddleware)(server, {
|
|
913
856
|
// @ts-expect-error
|
|
914
|
-
context:
|
|
857
|
+
context: ({ req, res }) => req._viewer
|
|
915
858
|
});
|
|
916
|
-
(0, import_http3.registerRoute)(
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
req
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
859
|
+
(0, import_http3.registerRoute)(
|
|
860
|
+
(0, import_http3.route)({
|
|
861
|
+
app,
|
|
862
|
+
method: "all",
|
|
863
|
+
path: "/graphql",
|
|
864
|
+
bodyParser: "json",
|
|
865
|
+
async resolve(req, res, viewer) {
|
|
866
|
+
req._viewer = viewer;
|
|
867
|
+
return middleware(req, res, req.next);
|
|
868
|
+
}
|
|
869
|
+
})
|
|
870
|
+
);
|
|
926
871
|
}
|
|
927
|
-
__name(startGraphQL_default, "default");
|
|
928
872
|
|
|
929
873
|
// src/resolversSchemas/params.ts
|
|
930
874
|
var import_resolvers3 = require("@orion-js/resolvers");
|
|
@@ -939,20 +883,12 @@ async function getParams2(field) {
|
|
|
939
883
|
let { type } = field;
|
|
940
884
|
if (typeof type === "function" && type.getModel && type.__schemaId) {
|
|
941
885
|
const model = type.getModel();
|
|
942
|
-
return await getParams2({
|
|
943
|
-
...field,
|
|
944
|
-
type: model
|
|
945
|
-
});
|
|
886
|
+
return await getParams2({ ...field, type: model });
|
|
946
887
|
} else if ((0, import_isArray3.default)(type)) {
|
|
947
|
-
const serialized = await getParams2({
|
|
948
|
-
...field,
|
|
949
|
-
type: type[0]
|
|
950
|
-
});
|
|
888
|
+
const serialized = await getParams2({ ...field, type: type[0] });
|
|
951
889
|
return {
|
|
952
890
|
...serialized,
|
|
953
|
-
type: [
|
|
954
|
-
serialized.type
|
|
955
|
-
],
|
|
891
|
+
type: [serialized.type],
|
|
956
892
|
__graphQLType: `[${serialized.__graphQLType}]`
|
|
957
893
|
};
|
|
958
894
|
} else if (!type._isFieldType && ((0, import_isPlainObject3.default)(type) || type.__isModel)) {
|
|
@@ -977,7 +913,6 @@ async function getParams2(field) {
|
|
|
977
913
|
};
|
|
978
914
|
}
|
|
979
915
|
}
|
|
980
|
-
__name(getParams2, "getParams");
|
|
981
916
|
|
|
982
917
|
// src/resolversSchemas/serializeSchema.ts
|
|
983
918
|
async function serializeSchema(params) {
|
|
@@ -993,7 +928,6 @@ async function serializeSchema(params) {
|
|
|
993
928
|
}
|
|
994
929
|
return fields;
|
|
995
930
|
}
|
|
996
|
-
__name(serializeSchema, "serializeSchema");
|
|
997
931
|
|
|
998
932
|
// src/resolversSchemas/getBasicResultQuery.ts
|
|
999
933
|
var import_isArray4 = __toESM(require("lodash/isArray"), 1);
|
|
@@ -1011,15 +945,14 @@ async function getBasicQuery(field) {
|
|
|
1011
945
|
return field.key;
|
|
1012
946
|
}
|
|
1013
947
|
}
|
|
1014
|
-
__name(getBasicQuery, "getBasicQuery");
|
|
1015
948
|
|
|
1016
949
|
// src/resolversSchemas/ResolverParamsInfo.ts
|
|
1017
950
|
var import_models = require("@orion-js/models");
|
|
1018
951
|
var import_resolvers2 = require("@orion-js/resolvers");
|
|
1019
952
|
var import_lodash2 = require("lodash");
|
|
1020
|
-
var resolverReturnsIsModel =
|
|
953
|
+
var resolverReturnsIsModel = (returns) => {
|
|
1021
954
|
return returns && returns.__isModel;
|
|
1022
|
-
}
|
|
955
|
+
};
|
|
1023
956
|
var ResolverParamsInfo_default = (0, import_models.createModel)({
|
|
1024
957
|
name: "ResolverParams",
|
|
1025
958
|
schema: {
|
|
@@ -1030,26 +963,26 @@ var ResolverParamsInfo_default = (0, import_models.createModel)({
|
|
|
1030
963
|
resolvers: {
|
|
1031
964
|
params: (0, import_resolvers2.resolver)({
|
|
1032
965
|
returns: "blackbox",
|
|
1033
|
-
resolve:
|
|
966
|
+
resolve: async function({ resolver: resolver4 }) {
|
|
1034
967
|
return await serializeSchema(resolver4.params);
|
|
1035
|
-
}
|
|
968
|
+
}
|
|
1036
969
|
}),
|
|
1037
970
|
result: (0, import_resolvers2.resolver)({
|
|
1038
971
|
returns: String,
|
|
1039
|
-
resolve:
|
|
972
|
+
resolve: async function({ resolver: resolver4 }) {
|
|
1040
973
|
const returns = (0, import_lodash2.isArray)(resolver4.returns) ? resolver4.returns[0] : resolver4.returns;
|
|
1041
974
|
if (resolverReturnsIsModel(returns)) return returns.name;
|
|
1042
975
|
return;
|
|
1043
|
-
}
|
|
976
|
+
}
|
|
1044
977
|
}),
|
|
1045
978
|
basicResultQuery: (0, import_resolvers2.resolver)({
|
|
1046
979
|
returns: String,
|
|
1047
|
-
resolve:
|
|
980
|
+
resolve: async function({ resolver: resolver4 }) {
|
|
1048
981
|
const returns = (0, import_lodash2.isArray)(resolver4.returns) ? resolver4.returns[0] : resolver4.returns;
|
|
1049
982
|
return await getBasicQuery({
|
|
1050
983
|
type: resolverReturnsIsModel(returns) ? returns.getSchema() : ""
|
|
1051
984
|
});
|
|
1052
|
-
}
|
|
985
|
+
}
|
|
1053
986
|
})
|
|
1054
987
|
}
|
|
1055
988
|
});
|
|
@@ -1066,19 +999,19 @@ var params_default = (0, import_resolvers3.resolver)({
|
|
|
1066
999
|
},
|
|
1067
1000
|
returns: ResolverParamsInfo_default,
|
|
1068
1001
|
mutation: false,
|
|
1069
|
-
resolve:
|
|
1002
|
+
resolve: async function({ mutation, name }, viewer) {
|
|
1070
1003
|
const resolver4 = resolversStore[name];
|
|
1071
1004
|
if (!resolver4) {
|
|
1072
|
-
throw new import_helpers2.UserError(
|
|
1005
|
+
throw new import_helpers2.UserError(
|
|
1006
|
+
"notFound",
|
|
1007
|
+
`${mutation ? "Mutation" : "Query"} named "${name}" not found`
|
|
1008
|
+
);
|
|
1073
1009
|
}
|
|
1074
1010
|
if (!!resolver4.mutation !== !!mutation) {
|
|
1075
1011
|
throw new import_helpers2.UserError("incorrectType", `"${name}" is ${mutation ? "not" : ""} a mutation`);
|
|
1076
1012
|
}
|
|
1077
|
-
return {
|
|
1078
|
-
|
|
1079
|
-
name
|
|
1080
|
-
};
|
|
1081
|
-
}, "resolve")
|
|
1013
|
+
return { resolver: resolver4, name };
|
|
1014
|
+
}
|
|
1082
1015
|
});
|
|
1083
1016
|
|
|
1084
1017
|
// src/resolversSchemas/index.ts
|
|
@@ -1090,15 +1023,13 @@ var resolversSchemas_default = {
|
|
|
1090
1023
|
var GraphQL2 = __toESM(require("graphql"), 1);
|
|
1091
1024
|
|
|
1092
1025
|
// src/types/subscription.ts
|
|
1093
|
-
var
|
|
1026
|
+
var OrionSubscription = class {
|
|
1094
1027
|
name;
|
|
1095
1028
|
params;
|
|
1096
1029
|
subscribe;
|
|
1097
1030
|
returns;
|
|
1098
1031
|
publish;
|
|
1099
1032
|
};
|
|
1100
|
-
__name(_OrionSubscription, "OrionSubscription");
|
|
1101
|
-
var OrionSubscription = _OrionSubscription;
|
|
1102
1033
|
|
|
1103
1034
|
// src/service/global.ts
|
|
1104
1035
|
var import_services = require("@orion-js/services");
|
|
@@ -1120,12 +1051,10 @@ function createRegisterResolverMetadata(metadataKey, isArray6 = false) {
|
|
|
1120
1051
|
};
|
|
1121
1052
|
};
|
|
1122
1053
|
}
|
|
1123
|
-
__name(createRegisterResolverMetadata, "createRegisterResolverMetadata");
|
|
1124
1054
|
function getTargetMetadata(target, propertyKey, metadataKey) {
|
|
1125
1055
|
const items = target[metadataKey] || {};
|
|
1126
1056
|
return items[propertyKey] || [];
|
|
1127
1057
|
}
|
|
1128
|
-
__name(getTargetMetadata, "getTargetMetadata");
|
|
1129
1058
|
var UseMiddleware = createRegisterResolverMetadata("middlewares", true);
|
|
1130
1059
|
var ResolverParams = createRegisterResolverMetadata("params");
|
|
1131
1060
|
var ResolverReturns = createRegisterResolverMetadata("returns");
|
|
@@ -1137,7 +1066,6 @@ function Resolvers() {
|
|
|
1137
1066
|
target.prototype.service = target;
|
|
1138
1067
|
};
|
|
1139
1068
|
}
|
|
1140
|
-
__name(Resolvers, "Resolvers");
|
|
1141
1069
|
function Query(options) {
|
|
1142
1070
|
return (target, propertyKey, descriptor) => {
|
|
1143
1071
|
if (!descriptor.value) throw new Error(`You must pass resolver function to ${propertyKey}`);
|
|
@@ -1148,14 +1076,13 @@ function Query(options) {
|
|
|
1148
1076
|
returns: getTargetMetadata(target, propertyKey, "returns"),
|
|
1149
1077
|
middlewares: getTargetMetadata(target, propertyKey, "middlewares"),
|
|
1150
1078
|
...options,
|
|
1151
|
-
resolve:
|
|
1079
|
+
resolve: async (params, viewer, info) => {
|
|
1152
1080
|
const instance = (0, import_services.getInstance)(target.service);
|
|
1153
1081
|
return await instance[propertyKey](params, viewer, info);
|
|
1154
|
-
}
|
|
1082
|
+
}
|
|
1155
1083
|
});
|
|
1156
1084
|
};
|
|
1157
1085
|
}
|
|
1158
|
-
__name(Query, "Query");
|
|
1159
1086
|
function Mutation(options) {
|
|
1160
1087
|
return (target, propertyKey, descriptor) => {
|
|
1161
1088
|
if (!descriptor.value) throw new Error(`You must pass resolver function to ${propertyKey}`);
|
|
@@ -1167,21 +1094,19 @@ function Mutation(options) {
|
|
|
1167
1094
|
middlewares: getTargetMetadata(target, propertyKey, "middlewares"),
|
|
1168
1095
|
...options,
|
|
1169
1096
|
mutation: true,
|
|
1170
|
-
resolve:
|
|
1097
|
+
resolve: async (params, viewer, info) => {
|
|
1171
1098
|
const instance = (0, import_services.getInstance)(target.service);
|
|
1172
1099
|
return await instance[propertyKey](params, viewer, info);
|
|
1173
|
-
}
|
|
1100
|
+
}
|
|
1174
1101
|
});
|
|
1175
1102
|
};
|
|
1176
1103
|
}
|
|
1177
|
-
__name(Mutation, "Mutation");
|
|
1178
1104
|
function getServiceResolvers(target) {
|
|
1179
1105
|
if (!target.prototype) {
|
|
1180
1106
|
throw new import_helpers3.UserError("You must pass a class to getResolvers");
|
|
1181
1107
|
}
|
|
1182
1108
|
return target.prototype.resolvers || {};
|
|
1183
1109
|
}
|
|
1184
|
-
__name(getServiceResolvers, "getServiceResolvers");
|
|
1185
1110
|
|
|
1186
1111
|
// src/service/model.ts
|
|
1187
1112
|
var import_services2 = require("@orion-js/services");
|
|
@@ -1196,14 +1121,13 @@ function ModelResolver(options) {
|
|
|
1196
1121
|
returns: getTargetMetadata(target, propertyKey, "returns"),
|
|
1197
1122
|
middlewares: getTargetMetadata(target, propertyKey, "middlewares"),
|
|
1198
1123
|
...options,
|
|
1199
|
-
resolve:
|
|
1124
|
+
resolve: async (item, params, viewer, info) => {
|
|
1200
1125
|
const instance = (0, import_services2.getInstance)(target.service);
|
|
1201
1126
|
return await instance[propertyKey](item, params, viewer, info);
|
|
1202
|
-
}
|
|
1127
|
+
}
|
|
1203
1128
|
});
|
|
1204
1129
|
};
|
|
1205
1130
|
}
|
|
1206
|
-
__name(ModelResolver, "ModelResolver");
|
|
1207
1131
|
function ModelResolvers(typedSchema, options = {}) {
|
|
1208
1132
|
return (target) => {
|
|
1209
1133
|
(0, import_services2.Service)()(target);
|
|
@@ -1216,7 +1140,6 @@ function ModelResolvers(typedSchema, options = {}) {
|
|
|
1216
1140
|
target.getModel = () => getModelForClass(target);
|
|
1217
1141
|
};
|
|
1218
1142
|
}
|
|
1219
|
-
__name(ModelResolvers, "ModelResolvers");
|
|
1220
1143
|
function getServiceModelResolvers(target) {
|
|
1221
1144
|
if (!target.prototype) {
|
|
1222
1145
|
throw new import_helpers4.UserError("You must pass a class to getResolvers");
|
|
@@ -1225,7 +1148,6 @@ function getServiceModelResolvers(target) {
|
|
|
1225
1148
|
[target.prototype.modelName]: target.prototype.resolvers || {}
|
|
1226
1149
|
};
|
|
1227
1150
|
}
|
|
1228
|
-
__name(getServiceModelResolvers, "getServiceModelResolvers");
|
|
1229
1151
|
|
|
1230
1152
|
// src/service/subscription.ts
|
|
1231
1153
|
var import_services3 = require("@orion-js/services");
|
|
@@ -1237,7 +1159,6 @@ function Subscriptions() {
|
|
|
1237
1159
|
target.prototype.serviceType = "subscriptions";
|
|
1238
1160
|
};
|
|
1239
1161
|
}
|
|
1240
|
-
__name(Subscriptions, "Subscriptions");
|
|
1241
1162
|
function Subscription(options) {
|
|
1242
1163
|
return (object, propertyName, index) => {
|
|
1243
1164
|
const sub = subscription_default({
|
|
@@ -1250,23 +1171,23 @@ function Subscription(options) {
|
|
|
1250
1171
|
object,
|
|
1251
1172
|
propertyName,
|
|
1252
1173
|
index,
|
|
1253
|
-
value:
|
|
1174
|
+
value: (_containerInstance) => {
|
|
1254
1175
|
if (!object.serviceType || object.serviceType !== "subscriptions") {
|
|
1255
|
-
throw new Error(
|
|
1176
|
+
throw new Error(
|
|
1177
|
+
"You must pass a class decorated with @Subscriptions if you want to use @Subscription"
|
|
1178
|
+
);
|
|
1256
1179
|
}
|
|
1257
1180
|
return sub;
|
|
1258
|
-
}
|
|
1181
|
+
}
|
|
1259
1182
|
});
|
|
1260
1183
|
};
|
|
1261
1184
|
}
|
|
1262
|
-
__name(Subscription, "Subscription");
|
|
1263
1185
|
function getServiceSubscriptions(target) {
|
|
1264
1186
|
if (!target.prototype) {
|
|
1265
1187
|
throw new import_helpers5.UserError("You must pass a class to getSubscriptions");
|
|
1266
1188
|
}
|
|
1267
1189
|
return target.prototype.subscriptions || {};
|
|
1268
1190
|
}
|
|
1269
|
-
__name(getServiceSubscriptions, "getServiceSubscriptions");
|
|
1270
1191
|
// Annotate the CommonJS export names for ESM import in node:
|
|
1271
1192
|
0 && (module.exports = {
|
|
1272
1193
|
GraphQL,
|