@orion-js/graphql 4.2.2 → 4.2.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/dist/index.cjs CHANGED
@@ -84,6 +84,20 @@ function getChannelName_default(name, params) {
84
84
  }
85
85
 
86
86
  // src/subscription/index.ts
87
+ var unauthorizedIterator = {
88
+ async next() {
89
+ return { value: void 0, done: true };
90
+ },
91
+ async return() {
92
+ return { value: void 0, done: true };
93
+ },
94
+ async throw(error) {
95
+ throw error;
96
+ },
97
+ [Symbol.asyncIterator]() {
98
+ return this;
99
+ }
100
+ };
87
101
  var createSubscription = (options) => {
88
102
  const subscription = {};
89
103
  const getSubscriptionName = () => {
@@ -103,13 +117,13 @@ var createSubscription = (options) => {
103
117
  if (options.canSubscribe) {
104
118
  const canSubscribe = await options.canSubscribe(params, viewer);
105
119
  if (!canSubscribe) {
106
- return pubsub2.asyncIterator("unauthorized");
120
+ return unauthorizedIterator;
107
121
  }
108
122
  }
109
123
  const channelName = getChannelName_default(getSubscriptionName(), params);
110
124
  return pubsub2.asyncIterator(channelName);
111
125
  } catch (_error) {
112
- return pubsub2.asyncIterator("unauthorized");
126
+ return unauthorizedIterator;
113
127
  }
114
128
  };
115
129
  subscription.params = (0, import_schema.getSchemaFromAnyOrionForm)(options.params) ?? {};
@@ -325,9 +339,159 @@ var import_graphql10 = require("graphql");
325
339
  // src/buildSchema/getQuery.ts
326
340
  var import_graphql7 = require("graphql");
327
341
 
328
- // src/buildSchema/getType/index.ts
329
- var import_graphql6 = require("graphql");
330
- var import_schema3 = require("@orion-js/schema");
342
+ // src/buildSchema/getResolvers/index.ts
343
+ var import_logger2 = require("@orion-js/logger");
344
+
345
+ // src/errorHandler.ts
346
+ var import_node_crypto = __toESM(require("crypto"), 1);
347
+ var import_graphql = require("graphql");
348
+ function errorHandler(error, data) {
349
+ const message = `Error in resolver "${data.name}" ${data.schema ? `of model "${data.schema.__modelName}"` : ""}`;
350
+ const hash = import_node_crypto.default.createHash("sha1").update(error.message, "utf8").digest("hex").substring(0, 10);
351
+ error.hash = hash;
352
+ if (error == null ? void 0 : error.isOrionError) {
353
+ console.warn(message, error);
354
+ throw new import_graphql.GraphQLError(error.message, {
355
+ originalError: error,
356
+ extensions: {
357
+ isOrionError: !!error.isOrionError,
358
+ isValidationError: !!error.isValidationError,
359
+ code: error.code,
360
+ hash,
361
+ info: error.getInfo()
362
+ }
363
+ });
364
+ }
365
+ console.error(message, error);
366
+ throw new import_graphql.GraphQLError(`${error.message} [${hash}]`, {
367
+ // originalError: error,
368
+ extensions: {
369
+ isOrionError: false,
370
+ isValidationError: false,
371
+ code: "INTERNAL_SERVER_ERROR",
372
+ hash
373
+ }
374
+ });
375
+ }
376
+
377
+ // src/buildSchema/getArgs/getField.ts
378
+ var import_graphql5 = require("graphql");
379
+ var import_schema2 = require("@orion-js/schema");
380
+
381
+ // src/buildSchema/getType/BigIntScalar.ts
382
+ var import_graphql2 = require("graphql");
383
+ var MAX_INT = Number.MAX_SAFE_INTEGER;
384
+ var MIN_INT = Number.MIN_SAFE_INTEGER;
385
+ var coerceBigInt = function coerceBigInt2(value) {
386
+ if (value === "") {
387
+ throw new TypeError("BigInt cannot represent non 53-bit signed integer value: (empty string)");
388
+ }
389
+ const num = Number(value);
390
+ if (num > MAX_INT || num < MIN_INT) {
391
+ throw new TypeError("BigInt cannot represent non 53-bit signed integer value: " + String(value));
392
+ }
393
+ const int = Math.floor(num);
394
+ if (int !== num) {
395
+ throw new TypeError("BigInt cannot represent non-integer value: " + String(value));
396
+ }
397
+ return int;
398
+ };
399
+ var BigIntScalar_default = new import_graphql2.GraphQLScalarType({
400
+ name: "BigInt",
401
+ description: "The `BigInt` scalar type represents non-fractional signed whole numeric values. BigInt can represent values between -(2^53) + 1 and 2^53 - 1. ",
402
+ serialize: coerceBigInt,
403
+ parseValue: coerceBigInt,
404
+ parseLiteral(ast) {
405
+ if (ast.kind === "IntValue") {
406
+ const num = parseInt(ast.value, 10);
407
+ if (num <= MAX_INT && num >= MIN_INT) {
408
+ return num;
409
+ }
410
+ }
411
+ return null;
412
+ }
413
+ });
414
+
415
+ // src/buildSchema/getType/DateScalar.ts
416
+ var import_graphql3 = require("graphql");
417
+ var import_graphql_scalars = require("graphql-scalars");
418
+ var DateScalar_default = new import_graphql3.GraphQLScalarType({
419
+ name: "Date",
420
+ serialize: import_graphql_scalars.GraphQLDateTime.serialize,
421
+ parseValue: import_graphql_scalars.GraphQLDateTime.parseValue,
422
+ parseLiteral: import_graphql_scalars.GraphQLDateTime.parseLiteral
423
+ });
424
+
425
+ // src/buildSchema/getType/JSONScalar.ts
426
+ var import_graphql4 = require("graphql");
427
+ function identity(value) {
428
+ return value;
429
+ }
430
+ function parseLiteral(ast, variables) {
431
+ switch (ast.kind) {
432
+ case import_graphql4.Kind.STRING:
433
+ case import_graphql4.Kind.BOOLEAN:
434
+ return ast.value;
435
+ case import_graphql4.Kind.INT:
436
+ case import_graphql4.Kind.FLOAT:
437
+ return parseFloat(ast.value);
438
+ case import_graphql4.Kind.OBJECT: {
439
+ const value = /* @__PURE__ */ Object.create(null);
440
+ ast.fields.forEach((field) => {
441
+ value[field.name.value] = parseLiteral(field.value, variables);
442
+ });
443
+ return value;
444
+ }
445
+ case import_graphql4.Kind.LIST:
446
+ return ast.values.map((n) => parseLiteral(n, variables));
447
+ case import_graphql4.Kind.NULL:
448
+ return null;
449
+ case import_graphql4.Kind.VARIABLE: {
450
+ const name = ast.name.value;
451
+ return variables ? variables[name] : void 0;
452
+ }
453
+ default:
454
+ return void 0;
455
+ }
456
+ }
457
+ var JSONScalar_default = new import_graphql4.GraphQLScalarType({
458
+ name: "JSON",
459
+ 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).",
460
+ serialize: identity,
461
+ parseValue: identity,
462
+ parseLiteral
463
+ });
464
+
465
+ // src/buildSchema/getType/getScalar.ts
466
+ var GraphQL = __toESM(require("graphql"), 1);
467
+ var { GraphQLFloat, GraphQLString, GraphQLID, GraphQLBoolean } = GraphQL;
468
+ var fieldMap = {
469
+ string: GraphQLString,
470
+ email: GraphQLString,
471
+ date: DateScalar_default,
472
+ integer: BigIntScalar_default,
473
+ number: GraphQLFloat,
474
+ ID: GraphQLID,
475
+ boolean: GraphQLBoolean,
476
+ blackbox: JSONScalar_default,
477
+ any: JSONScalar_default
478
+ };
479
+ function getScalar_default(fieldType) {
480
+ if (fieldMap[fieldType.name]) {
481
+ return fieldMap[fieldType.name];
482
+ }
483
+ if (fieldType.name.startsWith("typedId:")) {
484
+ return fieldMap.string;
485
+ }
486
+ if (fieldType.toGraphQLType) {
487
+ const result = fieldType.toGraphQLType(GraphQL);
488
+ if (result.then) {
489
+ throw new Error("toGraphQLType cant return a promise");
490
+ }
491
+ return result;
492
+ }
493
+ throw new Error(`Field type "${fieldType.name}" has no convertion to GraphQLType`);
494
+ }
331
495
 
332
496
  // ../../node_modules/.pnpm/rambdax@11.3.1/node_modules/rambdax/src/type.js
333
497
  function type(input) {
@@ -512,125 +676,6 @@ function isEmpty(input) {
512
676
  return false;
513
677
  }
514
678
 
515
- // src/buildSchema/getType/BigIntScalar.ts
516
- var import_graphql = require("graphql");
517
- var MAX_INT = Number.MAX_SAFE_INTEGER;
518
- var MIN_INT = Number.MIN_SAFE_INTEGER;
519
- var coerceBigInt = function coerceBigInt2(value) {
520
- if (value === "") {
521
- throw new TypeError("BigInt cannot represent non 53-bit signed integer value: (empty string)");
522
- }
523
- const num = Number(value);
524
- if (num > MAX_INT || num < MIN_INT) {
525
- throw new TypeError("BigInt cannot represent non 53-bit signed integer value: " + String(value));
526
- }
527
- const int = Math.floor(num);
528
- if (int !== num) {
529
- throw new TypeError("BigInt cannot represent non-integer value: " + String(value));
530
- }
531
- return int;
532
- };
533
- var BigIntScalar_default = new import_graphql.GraphQLScalarType({
534
- name: "BigInt",
535
- description: "The `BigInt` scalar type represents non-fractional signed whole numeric values. BigInt can represent values between -(2^53) + 1 and 2^53 - 1. ",
536
- serialize: coerceBigInt,
537
- parseValue: coerceBigInt,
538
- parseLiteral(ast) {
539
- if (ast.kind === "IntValue") {
540
- const num = parseInt(ast.value, 10);
541
- if (num <= MAX_INT && num >= MIN_INT) {
542
- return num;
543
- }
544
- }
545
- return null;
546
- }
547
- });
548
-
549
- // src/buildSchema/getType/DateScalar.ts
550
- var import_graphql2 = require("graphql");
551
- var import_graphql_scalars = require("graphql-scalars");
552
- var DateScalar_default = new import_graphql2.GraphQLScalarType({
553
- name: "Date",
554
- serialize: import_graphql_scalars.GraphQLDateTime.serialize,
555
- parseValue: import_graphql_scalars.GraphQLDateTime.parseValue,
556
- parseLiteral: import_graphql_scalars.GraphQLDateTime.parseLiteral
557
- });
558
-
559
- // src/buildSchema/getType/JSONScalar.ts
560
- var import_graphql3 = require("graphql");
561
- function identity(value) {
562
- return value;
563
- }
564
- function parseLiteral(ast, variables) {
565
- switch (ast.kind) {
566
- case import_graphql3.Kind.STRING:
567
- case import_graphql3.Kind.BOOLEAN:
568
- return ast.value;
569
- case import_graphql3.Kind.INT:
570
- case import_graphql3.Kind.FLOAT:
571
- return parseFloat(ast.value);
572
- case import_graphql3.Kind.OBJECT: {
573
- const value = /* @__PURE__ */ Object.create(null);
574
- ast.fields.forEach((field) => {
575
- value[field.name.value] = parseLiteral(field.value, variables);
576
- });
577
- return value;
578
- }
579
- case import_graphql3.Kind.LIST:
580
- return ast.values.map((n) => parseLiteral(n, variables));
581
- case import_graphql3.Kind.NULL:
582
- return null;
583
- case import_graphql3.Kind.VARIABLE: {
584
- const name = ast.name.value;
585
- return variables ? variables[name] : void 0;
586
- }
587
- default:
588
- return void 0;
589
- }
590
- }
591
- var JSONScalar_default = new import_graphql3.GraphQLScalarType({
592
- name: "JSON",
593
- 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).",
594
- serialize: identity,
595
- parseValue: identity,
596
- parseLiteral
597
- });
598
-
599
- // src/buildSchema/getType/getScalar.ts
600
- var GraphQL = __toESM(require("graphql"), 1);
601
- var { GraphQLFloat, GraphQLString, GraphQLID, GraphQLBoolean } = GraphQL;
602
- var fieldMap = {
603
- string: GraphQLString,
604
- email: GraphQLString,
605
- date: DateScalar_default,
606
- integer: BigIntScalar_default,
607
- number: GraphQLFloat,
608
- ID: GraphQLID,
609
- boolean: GraphQLBoolean,
610
- blackbox: JSONScalar_default,
611
- any: JSONScalar_default
612
- };
613
- function getScalar_default(fieldType) {
614
- if (fieldMap[fieldType.name]) {
615
- return fieldMap[fieldType.name];
616
- }
617
- if (fieldType.name.startsWith("typedId:")) {
618
- return fieldMap.string;
619
- }
620
- if (fieldType.toGraphQLType) {
621
- const result = fieldType.toGraphQLType(GraphQL);
622
- if (result.then) {
623
- throw new Error("toGraphQLType cant return a promise");
624
- }
625
- return result;
626
- }
627
- throw new Error(`Field type "${fieldType.name}" has no convertion to GraphQLType`);
628
- }
629
-
630
- // src/buildSchema/getArgs/getField.ts
631
- var import_graphql4 = require("graphql");
632
- var import_schema2 = require("@orion-js/schema");
633
-
634
679
  // src/resolversSchemas/getStaticFields.ts
635
680
  function getStaticFields(schema) {
636
681
  if (!schema) return [];
@@ -657,7 +702,7 @@ var resolveType = (type2, options) => {
657
702
  return resolveType(model, options);
658
703
  }
659
704
  if (Array.isArray(type2)) {
660
- return new import_graphql4.GraphQLList(resolveType(type2[0], options));
705
+ return new import_graphql5.GraphQLList(resolveType(type2[0], options));
661
706
  }
662
707
  if ((0, import_schema2.isSchemaLike)(type2)) {
663
708
  const schema = (0, import_schema2.getSchemaWithMetadataFromAnyOrionForm)(type2);
@@ -685,7 +730,7 @@ var resolveType = (type2, options) => {
685
730
  return getScalar_default(schemaType);
686
731
  };
687
732
  var getField_default = resolveType;
688
- var createGraphQLInputType = (modelName, schema, options) => new import_graphql4.GraphQLInputObjectType({
733
+ var createGraphQLInputType = (modelName, schema, options) => new import_graphql5.GraphQLInputObjectType({
689
734
  name: modelName,
690
735
  fields: () => buildFields(schema, options)
691
736
  });
@@ -720,37 +765,9 @@ function getArgs_default(params, options) {
720
765
  return fields;
721
766
  }
722
767
 
723
- // src/errorHandler.ts
724
- var import_node_crypto = __toESM(require("crypto"), 1);
725
- var import_graphql5 = require("graphql");
726
- function errorHandler(error, data) {
727
- const message = `Error in resolver "${data.name}" ${data.schema ? `of model "${data.schema.__modelName}"` : ""}`;
728
- const hash = import_node_crypto.default.createHash("sha1").update(error.message, "utf8").digest("hex").substring(0, 10);
729
- error.hash = hash;
730
- if (error == null ? void 0 : error.isOrionError) {
731
- console.warn(message, error);
732
- throw new import_graphql5.GraphQLError(error.message, {
733
- originalError: error,
734
- extensions: {
735
- isOrionError: !!error.isOrionError,
736
- isValidationError: !!error.isValidationError,
737
- code: error.code,
738
- hash,
739
- info: error.getInfo()
740
- }
741
- });
742
- }
743
- console.error(message, error);
744
- throw new import_graphql5.GraphQLError(`${error.message} [${hash}]`, {
745
- // originalError: error,
746
- extensions: {
747
- isOrionError: false,
748
- isValidationError: false,
749
- code: "INTERNAL_SERVER_ERROR",
750
- hash
751
- }
752
- });
753
- }
768
+ // src/buildSchema/getType/index.ts
769
+ var import_graphql6 = require("graphql");
770
+ var import_schema3 = require("@orion-js/schema");
754
771
 
755
772
  // src/buildSchema/getType/getTypeAsResolver.ts
756
773
  var import_logger = require("@orion-js/logger");
@@ -900,17 +917,17 @@ function getGraphQLType(type2, options) {
900
917
  var resolversStore = {};
901
918
 
902
919
  // src/buildSchema/getResolvers/index.ts
903
- var import_logger2 = require("@orion-js/logger");
904
920
  async function getResolvers_default(options, mutation) {
905
921
  const { resolvers } = options;
906
- const filteredResolvers = Object.keys(resolvers).map((key) => {
907
- return {
908
- name: key,
909
- resolver: resolvers[key]
910
- };
911
- }).filter(({ resolver }) => !!resolver.mutation === !!mutation).filter(({ resolver }) => !resolver.private);
912
922
  const fields = {};
913
- for (const { resolver, name } of filteredResolvers) {
923
+ for (const name of Object.keys(resolvers)) {
924
+ const resolver = resolvers[name];
925
+ if (!!resolver.mutation !== !!mutation) {
926
+ continue;
927
+ }
928
+ if (resolver.private) {
929
+ continue;
930
+ }
914
931
  resolversStore[name] = resolver;
915
932
  const type2 = await getGraphQLType(resolver.returns, options);
916
933
  const args = await getArgs_default(resolver.params, options);