@orion-js/graphql 4.0.0-next.5 → 4.0.0-next.6

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
@@ -106,7 +106,7 @@ var import_http = require("@orion-js/http");
106
106
  function safeSerialize(data) {
107
107
  return data ? JSON.stringify(data).replace(/\//g, "\\/") : null;
108
108
  }
109
- var getHTML = function(apolloOptions, options, data) {
109
+ var getHTML = (_apolloOptions, options, data) => {
110
110
  const GRAPHIQL_VERSION = "0.11.11";
111
111
  const endpointURL = "/graphql";
112
112
  const subscriptionsEndpoint = "/subscriptions";
@@ -309,10 +309,192 @@ var import_graphql10 = require("graphql");
309
309
  var import_graphql7 = require("graphql");
310
310
 
311
311
  // src/buildSchema/getType/index.ts
312
- var import_isArray2 = __toESM(require("lodash/isArray"), 1);
313
312
  var import_graphql6 = require("graphql");
314
313
  var import_schema2 = require("@orion-js/schema");
315
314
 
315
+ // ../../node_modules/.pnpm/rambdax@11.3.1/node_modules/rambdax/src/type.js
316
+ function type(input) {
317
+ if (input === null) {
318
+ return "Null";
319
+ } else if (input === void 0) {
320
+ return "Undefined";
321
+ } else if (Number.isNaN(input)) {
322
+ return "NaN";
323
+ }
324
+ const typeResult = Object.prototype.toString.call(input).slice(8, -1);
325
+ return typeResult === "AsyncFunction" ? "Promise" : typeResult;
326
+ }
327
+
328
+ // ../../node_modules/.pnpm/rambdax@11.3.1/node_modules/rambdax/src/_internals/isArray.js
329
+ var { isArray } = Array;
330
+
331
+ // ../../node_modules/.pnpm/rambdax@11.3.1/node_modules/rambdax/src/_internals/isInteger.js
332
+ function _isInteger(n) {
333
+ return n << 0 === n;
334
+ }
335
+ var isInteger = Number.isInteger || _isInteger;
336
+
337
+ // ../../node_modules/.pnpm/rambdax@11.3.1/node_modules/rambdax/src/_internals/createPath.js
338
+ function createPath(path, delimiter = ".") {
339
+ return typeof path === "string" ? path.split(delimiter).map((x) => isInteger(x) ? Number(x) : x) : path;
340
+ }
341
+
342
+ // ../../node_modules/.pnpm/rambdax@11.3.1/node_modules/rambdax/src/equals.js
343
+ function _indexOf(valueToFind, list) {
344
+ if (!isArray(list))
345
+ throw new Error(`Cannot read property 'indexOf' of ${list}`);
346
+ const typeOfValue = type(valueToFind);
347
+ if (!["Array", "NaN", "Object", "RegExp"].includes(typeOfValue))
348
+ return list.indexOf(valueToFind);
349
+ let index = -1;
350
+ let foundIndex = -1;
351
+ const { length } = list;
352
+ while (++index < length && foundIndex === -1)
353
+ if (equals(list[index], valueToFind))
354
+ foundIndex = index;
355
+ return foundIndex;
356
+ }
357
+ function _arrayFromIterator(iter) {
358
+ const list = [];
359
+ let next;
360
+ while (!(next = iter.next()).done)
361
+ list.push(next.value);
362
+ return list;
363
+ }
364
+ function _compareSets(a, b) {
365
+ if (a.size !== b.size)
366
+ return false;
367
+ const aList = _arrayFromIterator(a.values());
368
+ const bList = _arrayFromIterator(b.values());
369
+ const filtered = aList.filter((aInstance) => _indexOf(aInstance, bList) === -1);
370
+ return filtered.length === 0;
371
+ }
372
+ function compareErrors(a, b) {
373
+ if (a.message !== b.message) return false;
374
+ if (a.toString !== b.toString) return false;
375
+ return a.toString() === b.toString();
376
+ }
377
+ function parseDate(maybeDate) {
378
+ if (!maybeDate.toDateString) return [false];
379
+ return [true, maybeDate.getTime()];
380
+ }
381
+ function parseRegex(maybeRegex) {
382
+ if (maybeRegex.constructor !== RegExp) return [false];
383
+ return [true, maybeRegex.toString()];
384
+ }
385
+ function equals(a, b) {
386
+ if (arguments.length === 1) return (_b) => equals(a, _b);
387
+ if (Object.is(a, b)) return true;
388
+ const aType = type(a);
389
+ if (aType !== type(b)) return false;
390
+ if (aType === "Function")
391
+ return a.name === void 0 ? false : a.name === b.name;
392
+ if (["NaN", "Null", "Undefined"].includes(aType)) return true;
393
+ if (["BigInt", "Number"].includes(aType)) {
394
+ if (Object.is(-0, a) !== Object.is(-0, b)) return false;
395
+ return a.toString() === b.toString();
396
+ }
397
+ if (["Boolean", "String"].includes(aType))
398
+ return a.toString() === b.toString();
399
+ if (aType === "Array") {
400
+ const aClone = Array.from(a);
401
+ const bClone = Array.from(b);
402
+ if (aClone.toString() !== bClone.toString())
403
+ return false;
404
+ let loopArrayFlag = true;
405
+ aClone.forEach((aCloneInstance, aCloneIndex) => {
406
+ if (loopArrayFlag) {
407
+ if (aCloneInstance !== bClone[aCloneIndex] && !equals(aCloneInstance, bClone[aCloneIndex]))
408
+ loopArrayFlag = false;
409
+ }
410
+ });
411
+ return loopArrayFlag;
412
+ }
413
+ const aRegex = parseRegex(a);
414
+ const bRegex = parseRegex(b);
415
+ if (aRegex[0])
416
+ return bRegex[0] ? aRegex[1] === bRegex[1] : false;
417
+ else if (bRegex[0]) return false;
418
+ const aDate = parseDate(a);
419
+ const bDate = parseDate(b);
420
+ if (aDate[0])
421
+ return bDate[0] ? aDate[1] === bDate[1] : false;
422
+ else if (bDate[0]) return false;
423
+ if (a instanceof Error) {
424
+ if (!(b instanceof Error)) return false;
425
+ return compareErrors(a, b);
426
+ }
427
+ if (aType === "Set")
428
+ return _compareSets(a, b);
429
+ if (aType === "Object") {
430
+ const aKeys = Object.keys(a);
431
+ if (aKeys.length !== Object.keys(b).length)
432
+ return false;
433
+ let loopObjectFlag = true;
434
+ aKeys.forEach((aKeyInstance) => {
435
+ if (loopObjectFlag) {
436
+ const aValue = a[aKeyInstance];
437
+ const bValue = b[aKeyInstance];
438
+ if (aValue !== bValue && !equals(aValue, bValue))
439
+ loopObjectFlag = false;
440
+ }
441
+ });
442
+ return loopObjectFlag;
443
+ }
444
+ return false;
445
+ }
446
+
447
+ // ../../node_modules/.pnpm/rambdax@11.3.1/node_modules/rambdax/src/isType.js
448
+ function isType(xType, x) {
449
+ if (arguments.length === 1) {
450
+ return (xHolder) => isType(xType, xHolder);
451
+ }
452
+ return type(x) === xType;
453
+ }
454
+
455
+ // ../../node_modules/.pnpm/rambdax@11.3.1/node_modules/rambdax/src/_internals/compare.js
456
+ function compare(a, b) {
457
+ return String(a) === String(b);
458
+ }
459
+
460
+ // ../../node_modules/.pnpm/rambdax@11.3.1/node_modules/rambdax/src/_internals/includes.js
461
+ function includes(a, list) {
462
+ let index = -1;
463
+ const { length } = list;
464
+ while (++index < length)
465
+ if (compare(list[index], a))
466
+ return true;
467
+ return false;
468
+ }
469
+
470
+ // ../../node_modules/.pnpm/rambdax@11.3.1/node_modules/rambdax/src/omit.js
471
+ function omit(propsToOmit, obj) {
472
+ if (arguments.length === 1) return (_obj) => omit(propsToOmit, _obj);
473
+ if (obj === null || obj === void 0)
474
+ return void 0;
475
+ const propsToOmitValue = createPath(propsToOmit, ",");
476
+ const willReturn = {};
477
+ for (const key in obj)
478
+ if (!includes(key, propsToOmitValue))
479
+ willReturn[key] = obj[key];
480
+ return willReturn;
481
+ }
482
+
483
+ // ../../node_modules/.pnpm/rambdax@11.3.1/node_modules/rambdax/src/isEmpty.js
484
+ function isEmpty(input) {
485
+ const inputType = type(input);
486
+ if (["Undefined", "NaN", "Number", "Null"].includes(inputType))
487
+ return false;
488
+ if (!input) return true;
489
+ if (inputType === "Object") {
490
+ return Object.keys(input).length === 0;
491
+ }
492
+ if (inputType === "Array") {
493
+ return input.length === 0;
494
+ }
495
+ return false;
496
+ }
497
+
316
498
  // src/buildSchema/getType/BigIntScalar.ts
317
499
  var import_graphql = require("graphql");
318
500
  var MAX_INT = Number.MAX_SAFE_INTEGER;
@@ -426,8 +608,6 @@ function getScalar_default(fieldType) {
426
608
  }
427
609
 
428
610
  // src/buildSchema/getArgs/getField.ts
429
- var import_isPlainObject = __toESM(require("lodash/isPlainObject"), 1);
430
- var import_isArray = __toESM(require("lodash/isArray"), 1);
431
611
  var import_graphql4 = require("graphql");
432
612
  var import_schema = require("@orion-js/schema");
433
613
 
@@ -466,27 +646,27 @@ var resolveModelFields = (model) => {
466
646
  }
467
647
  return fields;
468
648
  };
469
- var resolveArrayType = (type) => new import_graphql4.GraphQLList(resolveType(type[0]));
470
- var resolvePlainObjectOrModelType = (type) => {
471
- const model = type.__isModel ? type : type.__model;
649
+ var resolveArrayType = (type2) => new import_graphql4.GraphQLList(resolveType(type2[0]));
650
+ var resolvePlainObjectOrModelType = (type2) => {
651
+ const model = type2.__isModel ? type2 : type2.__model;
472
652
  if (!model || !model.__isModel) {
473
653
  throw new Error("A type is not a Model");
474
654
  }
475
655
  const fields = resolveModelFields(model);
476
656
  return getCachedModelInput(model, fields);
477
657
  };
478
- var resolveType = (type) => {
658
+ var resolveType = (type2) => {
479
659
  var _a;
480
- if (!type) throw new Error("No type specified");
481
- if ((_a = type == null ? void 0 : type[Symbol.metadata]) == null ? void 0 : _a._getModel) {
482
- const model = type[Symbol.metadata]._getModel();
660
+ if (!type2) throw new Error("No type specified");
661
+ if ((_a = type2 == null ? void 0 : type2[Symbol.metadata]) == null ? void 0 : _a._getModel) {
662
+ const model = type2[Symbol.metadata]._getModel();
483
663
  return resolveType(model);
484
664
  }
485
- if ((0, import_isArray.default)(type)) return resolveArrayType(type);
486
- if (!type.__isFieldType && ((0, import_isPlainObject.default)(type) || type.__isModel)) {
487
- return resolvePlainObjectOrModelType(type);
665
+ if (Array.isArray(type2)) return resolveArrayType(type2);
666
+ if (!type2.__isFieldType && (isType("Object", type2) || type2.__isModel)) {
667
+ return resolvePlainObjectOrModelType(type2);
488
668
  }
489
- const schemaType = (0, import_schema.getFieldType)(type);
669
+ const schemaType = (0, import_schema.getFieldType)(type2);
490
670
  return getScalar_default(schemaType);
491
671
  };
492
672
  var getField_default = resolveType;
@@ -498,8 +678,8 @@ async function getArgs_default(params) {
498
678
  const fields = {};
499
679
  for (const key of Object.keys(params)) {
500
680
  try {
501
- const type = getField_default(params[key].type);
502
- fields[key] = { type };
681
+ const type2 = getField_default(params[key].type);
682
+ fields[key] = { type: type2 };
503
683
  } catch (error) {
504
684
  throw new Error(`Error creating GraphQL resolver params argument ${key}: ${error.message}`);
505
685
  }
@@ -541,10 +721,10 @@ function errorHandler(error, data) {
541
721
 
542
722
  // src/buildSchema/getType/getTypeAsResolver.ts
543
723
  function getTypeAsResolver_default({ resolver: resolver2, getGraphQLType: getGraphQLType2, options, schema }) {
544
- const type = getGraphQLType2(resolver2.returns, options);
724
+ const type2 = getGraphQLType2(resolver2.returns, options);
545
725
  const args = getArgs_default(resolver2.params);
546
726
  return {
547
- type,
727
+ type: type2,
548
728
  args,
549
729
  async resolve(item, params, context, info) {
550
730
  try {
@@ -598,7 +778,6 @@ function getModelLoadedResolvers(schema, options) {
598
778
  }
599
779
 
600
780
  // src/buildSchema/getType/index.ts
601
- var import_lodash = require("lodash");
602
781
  var createGraphQLObjectType = (modelName, schema, options) => new import_graphql6.GraphQLObjectType({
603
782
  name: modelName,
604
783
  fields: () => buildFields(schema, options)
@@ -642,13 +821,13 @@ var buildFields = (schema, options) => {
642
821
  return fields;
643
822
  };
644
823
  var registeredGraphQLTypes = /* @__PURE__ */ new Map();
645
- function getGraphQLType(type, options) {
646
- if (!type) throw new Error("Type is undefined");
647
- if ((0, import_isArray2.default)(type)) {
648
- return new import_graphql6.GraphQLList(getGraphQLType(type[0], options));
824
+ function getGraphQLType(type2, options) {
825
+ if (!type2) throw new Error("Type is undefined");
826
+ if (Array.isArray(type2)) {
827
+ return new import_graphql6.GraphQLList(getGraphQLType(type2[0], options));
649
828
  }
650
- if ((0, import_schema2.isSchemaLike)(type)) {
651
- const schema = (0, import_schema2.getSchemaWithMetadataFromAnyOrionForm)(type);
829
+ if ((0, import_schema2.isSchemaLike)(type2)) {
830
+ const schema = (0, import_schema2.getSchemaWithMetadataFromAnyOrionForm)(type2);
652
831
  const modelName = schema.__modelName;
653
832
  if (schema.__graphQLType) {
654
833
  return schema.__graphQLType;
@@ -660,7 +839,7 @@ function getGraphQLType(type, options) {
660
839
  }
661
840
  if (registeredGraphQLTypes.has(modelName)) {
662
841
  const { graphQLType: graphQLType2, schema: registeredSchema } = registeredGraphQLTypes.get(modelName);
663
- if ((0, import_lodash.isEqual)(registeredSchema, schema)) {
842
+ if (equals(registeredSchema, schema)) {
664
843
  return graphQLType2;
665
844
  }
666
845
  throw new Error(`Schema named "${modelName}" already registered`);
@@ -669,7 +848,7 @@ function getGraphQLType(type, options) {
669
848
  registeredGraphQLTypes.set(modelName, { schema, graphQLType });
670
849
  return graphQLType;
671
850
  }
672
- return getScalar_default((0, import_schema2.getFieldType)(type));
851
+ return getScalar_default((0, import_schema2.getFieldType)(type2));
673
852
  }
674
853
 
675
854
  // src/buildSchema/getResolvers/resolversStore.ts
@@ -687,10 +866,10 @@ async function getResolvers_default(options, mutation) {
687
866
  const fields = {};
688
867
  for (const { resolver: resolver2, name } of filteredResolvers) {
689
868
  resolversStore[name] = resolver2;
690
- const type = await getGraphQLType(resolver2.returns, options);
869
+ const type2 = await getGraphQLType(resolver2.returns, options);
691
870
  const args = await getArgs_default(resolver2.params);
692
871
  fields[name] = {
693
- type,
872
+ type: type2,
694
873
  args,
695
874
  async resolve(_root, params, context, info) {
696
875
  try {
@@ -707,10 +886,9 @@ async function getResolvers_default(options, mutation) {
707
886
  }
708
887
 
709
888
  // src/buildSchema/getQuery.ts
710
- var import_isEmpty = __toESM(require("lodash/isEmpty"), 1);
711
889
  async function getQuery_default(options) {
712
890
  const fields = await getResolvers_default(options, false);
713
- if ((0, import_isEmpty.default)(fields)) return null;
891
+ if (isEmpty(fields)) return null;
714
892
  return new import_graphql7.GraphQLObjectType({
715
893
  name: "Query",
716
894
  fields
@@ -719,10 +897,9 @@ async function getQuery_default(options) {
719
897
 
720
898
  // src/buildSchema/getMutation.ts
721
899
  var import_graphql8 = require("graphql");
722
- var import_isEmpty2 = __toESM(require("lodash/isEmpty"), 1);
723
900
  async function getMutation_default(options) {
724
901
  const fields = await getResolvers_default(options, true);
725
- if ((0, import_isEmpty2.default)(fields)) return null;
902
+ if (isEmpty(fields)) return null;
726
903
  return new import_graphql8.GraphQLObjectType({
727
904
  name: "Mutation",
728
905
  fields
@@ -739,10 +916,10 @@ async function getSubscriptions_default(options) {
739
916
  for (const key of Object.keys(subscriptions)) {
740
917
  const subscription = subscriptions[key];
741
918
  subscription.name = subscription.name || key;
742
- const type = await getGraphQLType(subscription.returns, options);
919
+ const type2 = await getGraphQLType(subscription.returns, options);
743
920
  const args = await getArgs_default(subscription.params);
744
921
  fields[subscription.name] = {
745
- type,
922
+ type: type2,
746
923
  args,
747
924
  async subscribe(root, params, viewer) {
748
925
  return await subscription.subscribe(params, viewer);
@@ -785,18 +962,20 @@ function formatError_default(apolloError) {
785
962
  }
786
963
 
787
964
  // src/getApolloOptions/index.ts
788
- var import_lodash2 = require("lodash");
789
965
  async function getApolloOptions_default(options) {
790
966
  const schema = await buildSchema_default(options);
791
- const passedOptions = (0, import_lodash2.omit)(options, [
792
- "resolvers",
793
- "modelResolvers",
794
- "subscriptions",
795
- "executeGraphQLCache",
796
- "useGraphiql",
797
- "app",
798
- "pubsub"
799
- ]);
967
+ const passedOptions = omit(
968
+ [
969
+ "resolvers",
970
+ "modelResolvers",
971
+ "subscriptions",
972
+ "executeGraphQLCache",
973
+ "useGraphiql",
974
+ "app",
975
+ "pubsub"
976
+ ],
977
+ options
978
+ );
800
979
  return {
801
980
  ...passedOptions,
802
981
  schema,
@@ -925,20 +1104,20 @@ var import_schema5 = require("@orion-js/schema");
925
1104
 
926
1105
  // src/resolversSchemas/getField.ts
927
1106
  var import_schema4 = require("@orion-js/schema");
928
- var import_omit = __toESM(require("lodash/omit"), 1);
929
1107
  async function getParams(field) {
930
- const { type } = field;
931
- if (Array.isArray(type)) {
932
- const serialized = await getParams({ ...field, type: type[0] });
1108
+ const { type: type2 } = field;
1109
+ console.log(type2, "getting parms");
1110
+ if (Array.isArray(type2)) {
1111
+ const serialized = await getParams({ ...field, type: type2[0] });
933
1112
  return {
934
1113
  ...serialized,
935
1114
  type: [serialized.type],
936
1115
  __graphQLType: `[${serialized.__graphQLType}]`
937
1116
  };
938
1117
  }
939
- const isSchema = (0, import_schema4.isSchemaLike)(type);
1118
+ const isSchema = (0, import_schema4.isSchemaLike)(type2);
940
1119
  if (isSchema) {
941
- const schemaOfType = (0, import_schema4.getSchemaWithMetadataFromAnyOrionForm)(type);
1120
+ const schemaOfType = (0, import_schema4.getSchemaWithMetadataFromAnyOrionForm)(type2);
942
1121
  const modelName = schemaOfType.__modelName;
943
1122
  if (!modelName) {
944
1123
  throw new Error("The schema needs a model name to be serialized for GraphQL");
@@ -948,31 +1127,34 @@ async function getParams(field) {
948
1127
  fields[field2.key] = await getParams(field2);
949
1128
  }
950
1129
  return {
951
- ...(0, import_omit.default)(field, "key"),
1130
+ ...omit(["key"], field),
952
1131
  type: fields,
953
1132
  __graphQLType: `${modelName}Input`
954
1133
  };
955
1134
  }
956
- const schemaType = (0, import_schema4.getFieldType)(type);
1135
+ const schemaType = (0, import_schema4.getFieldType)(type2);
957
1136
  const graphQLType = await getScalar_default(schemaType);
1137
+ const withoutKey = isType("Object", field) ? omit(["key"], field) : {};
958
1138
  return {
959
- ...(0, import_omit.default)(field, "key"),
1139
+ ...withoutKey,
960
1140
  type: schemaType.name,
961
1141
  __graphQLType: graphQLType.name
962
1142
  };
963
1143
  }
964
1144
 
965
1145
  // src/resolversSchemas/serializeSchema.ts
966
- Symbol.metadata ?? (Symbol.metadata = Symbol("Symbol.metadata"));
967
1146
  async function serializeSchema(params) {
968
1147
  if (!params) return;
969
1148
  const schema = (0, import_schema5.getSchemaFromAnyOrionForm)(params);
970
1149
  if (Object.keys(schema).length === 0) return;
971
1150
  const fields = {};
1151
+ console.log(schema, "schema");
972
1152
  for (const key of Object.keys(schema).filter((key2) => !key2.startsWith("__"))) {
973
1153
  const field = schema[key];
974
1154
  fields[key] = await getParams(field);
1155
+ console.log(fields[key], field);
975
1156
  }
1157
+ console.log(fields, "fields");
976
1158
  return fields;
977
1159
  }
978
1160
 
@@ -980,11 +1162,10 @@ async function serializeSchema(params) {
980
1162
  var import_schema7 = require("@orion-js/schema");
981
1163
 
982
1164
  // src/resolversSchemas/getBasicResultQuery.ts
983
- var import_isArray3 = __toESM(require("lodash/isArray"), 1);
984
1165
  var import_schema6 = require("@orion-js/schema");
985
1166
  async function getBasicQuery(field) {
986
1167
  if (!field.type) return "";
987
- if ((0, import_isArray3.default)(field.type)) {
1168
+ if (Array.isArray(field.type)) {
988
1169
  return getBasicQuery({
989
1170
  ...field,
990
1171
  type: field.type[0]
@@ -1003,14 +1184,14 @@ async function getBasicQuery(field) {
1003
1184
  }
1004
1185
 
1005
1186
  // src/resolversSchemas/params.ts
1006
- function getResultTypeName(type) {
1007
- const returns = Array.isArray(type) ? type[0] : type;
1187
+ function getResultTypeName(type2) {
1188
+ const returns = Array.isArray(type2) ? type2[0] : type2;
1008
1189
  const schema = (0, import_schema7.getSchemaFromAnyOrionForm)(returns);
1009
1190
  if (schema == null ? void 0 : schema.__modelName) return schema.__modelName;
1010
1191
  return;
1011
1192
  }
1012
- async function getInternalBasicResultQuery(type) {
1013
- const returns = Array.isArray(type) ? type[0] : type;
1193
+ async function getInternalBasicResultQuery(type2) {
1194
+ const returns = Array.isArray(type2) ? type2[0] : type2;
1014
1195
  if ((0, import_schema7.isSchemaLike)(returns)) {
1015
1196
  const schema = (0, import_schema7.getSchemaFromAnyOrionForm)(returns);
1016
1197
  return await getBasicQuery({
@@ -1073,10 +1254,10 @@ var import_resolvers3 = require("@orion-js/resolvers");
1073
1254
 
1074
1255
  // src/service/middlewares.ts
1075
1256
  var resolversMetadata = /* @__PURE__ */ new WeakMap();
1076
- function addTargetMetadata(target, propertyKey, metadataKey, metadata, isArray4 = false) {
1257
+ function addTargetMetadata(target, propertyKey, metadataKey, metadata, isArray2 = false) {
1077
1258
  const targetMetadata = resolversMetadata.get(target) || {};
1078
1259
  targetMetadata[propertyKey] = targetMetadata[propertyKey] || {};
1079
- if (isArray4) {
1260
+ if (isArray2) {
1080
1261
  targetMetadata[propertyKey][metadataKey] = targetMetadata[propertyKey][metadataKey] || [];
1081
1262
  targetMetadata[propertyKey][metadataKey].unshift(metadata);
1082
1263
  } else {