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

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.js CHANGED
@@ -51,7 +51,7 @@ import { registerRoute, route } from "@orion-js/http";
51
51
  function safeSerialize(data) {
52
52
  return data ? JSON.stringify(data).replace(/\//g, "\\/") : null;
53
53
  }
54
- var getHTML = function(apolloOptions, options, data) {
54
+ var getHTML = (_apolloOptions, options, data) => {
55
55
  const GRAPHIQL_VERSION = "0.11.11";
56
56
  const endpointURL = "/graphql";
57
57
  const subscriptionsEndpoint = "/subscriptions";
@@ -254,7 +254,6 @@ import { GraphQLSchema } from "graphql";
254
254
  import { GraphQLObjectType as GraphQLObjectType2 } from "graphql";
255
255
 
256
256
  // src/buildSchema/getType/index.ts
257
- import isArray2 from "lodash/isArray";
258
257
  import { GraphQLList as GraphQLList2, GraphQLObjectType } from "graphql";
259
258
  import {
260
259
  getFieldType as getFieldType2,
@@ -262,6 +261,189 @@ import {
262
261
  isSchemaLike
263
262
  } from "@orion-js/schema";
264
263
 
264
+ // ../../node_modules/.pnpm/rambdax@11.3.1/node_modules/rambdax/src/type.js
265
+ function type(input) {
266
+ if (input === null) {
267
+ return "Null";
268
+ } else if (input === void 0) {
269
+ return "Undefined";
270
+ } else if (Number.isNaN(input)) {
271
+ return "NaN";
272
+ }
273
+ const typeResult = Object.prototype.toString.call(input).slice(8, -1);
274
+ return typeResult === "AsyncFunction" ? "Promise" : typeResult;
275
+ }
276
+
277
+ // ../../node_modules/.pnpm/rambdax@11.3.1/node_modules/rambdax/src/_internals/isArray.js
278
+ var { isArray } = Array;
279
+
280
+ // ../../node_modules/.pnpm/rambdax@11.3.1/node_modules/rambdax/src/_internals/isInteger.js
281
+ function _isInteger(n) {
282
+ return n << 0 === n;
283
+ }
284
+ var isInteger = Number.isInteger || _isInteger;
285
+
286
+ // ../../node_modules/.pnpm/rambdax@11.3.1/node_modules/rambdax/src/_internals/createPath.js
287
+ function createPath(path, delimiter = ".") {
288
+ return typeof path === "string" ? path.split(delimiter).map((x) => isInteger(x) ? Number(x) : x) : path;
289
+ }
290
+
291
+ // ../../node_modules/.pnpm/rambdax@11.3.1/node_modules/rambdax/src/equals.js
292
+ function _indexOf(valueToFind, list) {
293
+ if (!isArray(list))
294
+ throw new Error(`Cannot read property 'indexOf' of ${list}`);
295
+ const typeOfValue = type(valueToFind);
296
+ if (!["Array", "NaN", "Object", "RegExp"].includes(typeOfValue))
297
+ return list.indexOf(valueToFind);
298
+ let index = -1;
299
+ let foundIndex = -1;
300
+ const { length } = list;
301
+ while (++index < length && foundIndex === -1)
302
+ if (equals(list[index], valueToFind))
303
+ foundIndex = index;
304
+ return foundIndex;
305
+ }
306
+ function _arrayFromIterator(iter) {
307
+ const list = [];
308
+ let next;
309
+ while (!(next = iter.next()).done)
310
+ list.push(next.value);
311
+ return list;
312
+ }
313
+ function _compareSets(a, b) {
314
+ if (a.size !== b.size)
315
+ return false;
316
+ const aList = _arrayFromIterator(a.values());
317
+ const bList = _arrayFromIterator(b.values());
318
+ const filtered = aList.filter((aInstance) => _indexOf(aInstance, bList) === -1);
319
+ return filtered.length === 0;
320
+ }
321
+ function compareErrors(a, b) {
322
+ if (a.message !== b.message) return false;
323
+ if (a.toString !== b.toString) return false;
324
+ return a.toString() === b.toString();
325
+ }
326
+ function parseDate(maybeDate) {
327
+ if (!maybeDate.toDateString) return [false];
328
+ return [true, maybeDate.getTime()];
329
+ }
330
+ function parseRegex(maybeRegex) {
331
+ if (maybeRegex.constructor !== RegExp) return [false];
332
+ return [true, maybeRegex.toString()];
333
+ }
334
+ function equals(a, b) {
335
+ if (arguments.length === 1) return (_b) => equals(a, _b);
336
+ if (Object.is(a, b)) return true;
337
+ const aType = type(a);
338
+ if (aType !== type(b)) return false;
339
+ if (aType === "Function")
340
+ return a.name === void 0 ? false : a.name === b.name;
341
+ if (["NaN", "Null", "Undefined"].includes(aType)) return true;
342
+ if (["BigInt", "Number"].includes(aType)) {
343
+ if (Object.is(-0, a) !== Object.is(-0, b)) return false;
344
+ return a.toString() === b.toString();
345
+ }
346
+ if (["Boolean", "String"].includes(aType))
347
+ return a.toString() === b.toString();
348
+ if (aType === "Array") {
349
+ const aClone = Array.from(a);
350
+ const bClone = Array.from(b);
351
+ if (aClone.toString() !== bClone.toString())
352
+ return false;
353
+ let loopArrayFlag = true;
354
+ aClone.forEach((aCloneInstance, aCloneIndex) => {
355
+ if (loopArrayFlag) {
356
+ if (aCloneInstance !== bClone[aCloneIndex] && !equals(aCloneInstance, bClone[aCloneIndex]))
357
+ loopArrayFlag = false;
358
+ }
359
+ });
360
+ return loopArrayFlag;
361
+ }
362
+ const aRegex = parseRegex(a);
363
+ const bRegex = parseRegex(b);
364
+ if (aRegex[0])
365
+ return bRegex[0] ? aRegex[1] === bRegex[1] : false;
366
+ else if (bRegex[0]) return false;
367
+ const aDate = parseDate(a);
368
+ const bDate = parseDate(b);
369
+ if (aDate[0])
370
+ return bDate[0] ? aDate[1] === bDate[1] : false;
371
+ else if (bDate[0]) return false;
372
+ if (a instanceof Error) {
373
+ if (!(b instanceof Error)) return false;
374
+ return compareErrors(a, b);
375
+ }
376
+ if (aType === "Set")
377
+ return _compareSets(a, b);
378
+ if (aType === "Object") {
379
+ const aKeys = Object.keys(a);
380
+ if (aKeys.length !== Object.keys(b).length)
381
+ return false;
382
+ let loopObjectFlag = true;
383
+ aKeys.forEach((aKeyInstance) => {
384
+ if (loopObjectFlag) {
385
+ const aValue = a[aKeyInstance];
386
+ const bValue = b[aKeyInstance];
387
+ if (aValue !== bValue && !equals(aValue, bValue))
388
+ loopObjectFlag = false;
389
+ }
390
+ });
391
+ return loopObjectFlag;
392
+ }
393
+ return false;
394
+ }
395
+
396
+ // ../../node_modules/.pnpm/rambdax@11.3.1/node_modules/rambdax/src/isType.js
397
+ function isType(xType, x) {
398
+ if (arguments.length === 1) {
399
+ return (xHolder) => isType(xType, xHolder);
400
+ }
401
+ return type(x) === xType;
402
+ }
403
+
404
+ // ../../node_modules/.pnpm/rambdax@11.3.1/node_modules/rambdax/src/_internals/compare.js
405
+ function compare(a, b) {
406
+ return String(a) === String(b);
407
+ }
408
+
409
+ // ../../node_modules/.pnpm/rambdax@11.3.1/node_modules/rambdax/src/_internals/includes.js
410
+ function includes(a, list) {
411
+ let index = -1;
412
+ const { length } = list;
413
+ while (++index < length)
414
+ if (compare(list[index], a))
415
+ return true;
416
+ return false;
417
+ }
418
+
419
+ // ../../node_modules/.pnpm/rambdax@11.3.1/node_modules/rambdax/src/omit.js
420
+ function omit(propsToOmit, obj) {
421
+ if (arguments.length === 1) return (_obj) => omit(propsToOmit, _obj);
422
+ if (obj === null || obj === void 0)
423
+ return void 0;
424
+ const propsToOmitValue = createPath(propsToOmit, ",");
425
+ const willReturn = {};
426
+ for (const key in obj)
427
+ if (!includes(key, propsToOmitValue))
428
+ willReturn[key] = obj[key];
429
+ return willReturn;
430
+ }
431
+
432
+ // ../../node_modules/.pnpm/rambdax@11.3.1/node_modules/rambdax/src/isEmpty.js
433
+ function isEmpty(input) {
434
+ const inputType = type(input);
435
+ if (["Undefined", "NaN", "Number", "Null"].includes(inputType))
436
+ return false;
437
+ if (!input) return true;
438
+ if (inputType === "Object") {
439
+ return Object.keys(input).length === 0;
440
+ }
441
+ if (inputType === "Array") {
442
+ return input.length === 0;
443
+ }
444
+ return false;
445
+ }
446
+
265
447
  // src/buildSchema/getType/BigIntScalar.ts
266
448
  import { GraphQLScalarType } from "graphql";
267
449
  var MAX_INT = Number.MAX_SAFE_INTEGER;
@@ -298,7 +480,7 @@ var BigIntScalar_default = new GraphQLScalarType({
298
480
 
299
481
  // src/buildSchema/getType/DateScalar.ts
300
482
  import { GraphQLScalarType as GraphQLScalarType2 } from "graphql";
301
- import { GraphQLDateTime } from "graphql-iso-date";
483
+ import { GraphQLDateTime } from "graphql-scalars";
302
484
  var DateScalar_default = new GraphQLScalarType2({
303
485
  name: "Date",
304
486
  serialize: GraphQLDateTime.serialize,
@@ -375,8 +557,6 @@ function getScalar_default(fieldType) {
375
557
  }
376
558
 
377
559
  // src/buildSchema/getArgs/getField.ts
378
- import isPlainObject from "lodash/isPlainObject";
379
- import isArray from "lodash/isArray";
380
560
  import { GraphQLList, GraphQLInputObjectType } from "graphql";
381
561
  import { getFieldType } from "@orion-js/schema";
382
562
 
@@ -415,27 +595,27 @@ var resolveModelFields = (model) => {
415
595
  }
416
596
  return fields;
417
597
  };
418
- var resolveArrayType = (type) => new GraphQLList(resolveType(type[0]));
419
- var resolvePlainObjectOrModelType = (type) => {
420
- const model = type.__isModel ? type : type.__model;
598
+ var resolveArrayType = (type2) => new GraphQLList(resolveType(type2[0]));
599
+ var resolvePlainObjectOrModelType = (type2) => {
600
+ const model = type2.__isModel ? type2 : type2.__model;
421
601
  if (!model || !model.__isModel) {
422
602
  throw new Error("A type is not a Model");
423
603
  }
424
604
  const fields = resolveModelFields(model);
425
605
  return getCachedModelInput(model, fields);
426
606
  };
427
- var resolveType = (type) => {
607
+ var resolveType = (type2) => {
428
608
  var _a;
429
- if (!type) throw new Error("No type specified");
430
- if ((_a = type == null ? void 0 : type[Symbol.metadata]) == null ? void 0 : _a._getModel) {
431
- const model = type[Symbol.metadata]._getModel();
609
+ if (!type2) throw new Error("No type specified");
610
+ if ((_a = type2 == null ? void 0 : type2[Symbol.metadata]) == null ? void 0 : _a._getModel) {
611
+ const model = type2[Symbol.metadata]._getModel();
432
612
  return resolveType(model);
433
613
  }
434
- if (isArray(type)) return resolveArrayType(type);
435
- if (!type.__isFieldType && (isPlainObject(type) || type.__isModel)) {
436
- return resolvePlainObjectOrModelType(type);
614
+ if (Array.isArray(type2)) return resolveArrayType(type2);
615
+ if (!type2.__isFieldType && (isType("Object", type2) || type2.__isModel)) {
616
+ return resolvePlainObjectOrModelType(type2);
437
617
  }
438
- const schemaType = getFieldType(type);
618
+ const schemaType = getFieldType(type2);
439
619
  return getScalar_default(schemaType);
440
620
  };
441
621
  var getField_default = resolveType;
@@ -447,8 +627,8 @@ async function getArgs_default(params) {
447
627
  const fields = {};
448
628
  for (const key of Object.keys(params)) {
449
629
  try {
450
- const type = getField_default(params[key].type);
451
- fields[key] = { type };
630
+ const type2 = getField_default(params[key].type);
631
+ fields[key] = { type: type2 };
452
632
  } catch (error) {
453
633
  throw new Error(`Error creating GraphQL resolver params argument ${key}: ${error.message}`);
454
634
  }
@@ -490,10 +670,10 @@ function errorHandler(error, data) {
490
670
 
491
671
  // src/buildSchema/getType/getTypeAsResolver.ts
492
672
  function getTypeAsResolver_default({ resolver: resolver2, getGraphQLType: getGraphQLType2, options, schema }) {
493
- const type = getGraphQLType2(resolver2.returns, options);
673
+ const type2 = getGraphQLType2(resolver2.returns, options);
494
674
  const args = getArgs_default(resolver2.params);
495
675
  return {
496
- type,
676
+ type: type2,
497
677
  args,
498
678
  async resolve(item, params, context, info) {
499
679
  try {
@@ -547,7 +727,6 @@ function getModelLoadedResolvers(schema, options) {
547
727
  }
548
728
 
549
729
  // src/buildSchema/getType/index.ts
550
- import { isEqual } from "lodash";
551
730
  var createGraphQLObjectType = (modelName, schema, options) => new GraphQLObjectType({
552
731
  name: modelName,
553
732
  fields: () => buildFields(schema, options)
@@ -591,13 +770,13 @@ var buildFields = (schema, options) => {
591
770
  return fields;
592
771
  };
593
772
  var registeredGraphQLTypes = /* @__PURE__ */ new Map();
594
- function getGraphQLType(type, options) {
595
- if (!type) throw new Error("Type is undefined");
596
- if (isArray2(type)) {
597
- return new GraphQLList2(getGraphQLType(type[0], options));
773
+ function getGraphQLType(type2, options) {
774
+ if (!type2) throw new Error("Type is undefined");
775
+ if (Array.isArray(type2)) {
776
+ return new GraphQLList2(getGraphQLType(type2[0], options));
598
777
  }
599
- if (isSchemaLike(type)) {
600
- const schema = getSchemaWithMetadataFromAnyOrionForm(type);
778
+ if (isSchemaLike(type2)) {
779
+ const schema = getSchemaWithMetadataFromAnyOrionForm(type2);
601
780
  const modelName = schema.__modelName;
602
781
  if (schema.__graphQLType) {
603
782
  return schema.__graphQLType;
@@ -609,7 +788,7 @@ function getGraphQLType(type, options) {
609
788
  }
610
789
  if (registeredGraphQLTypes.has(modelName)) {
611
790
  const { graphQLType: graphQLType2, schema: registeredSchema } = registeredGraphQLTypes.get(modelName);
612
- if (isEqual(registeredSchema, schema)) {
791
+ if (equals(registeredSchema, schema)) {
613
792
  return graphQLType2;
614
793
  }
615
794
  throw new Error(`Schema named "${modelName}" already registered`);
@@ -618,7 +797,7 @@ function getGraphQLType(type, options) {
618
797
  registeredGraphQLTypes.set(modelName, { schema, graphQLType });
619
798
  return graphQLType;
620
799
  }
621
- return getScalar_default(getFieldType2(type));
800
+ return getScalar_default(getFieldType2(type2));
622
801
  }
623
802
 
624
803
  // src/buildSchema/getResolvers/resolversStore.ts
@@ -636,10 +815,10 @@ async function getResolvers_default(options, mutation) {
636
815
  const fields = {};
637
816
  for (const { resolver: resolver2, name } of filteredResolvers) {
638
817
  resolversStore[name] = resolver2;
639
- const type = await getGraphQLType(resolver2.returns, options);
818
+ const type2 = await getGraphQLType(resolver2.returns, options);
640
819
  const args = await getArgs_default(resolver2.params);
641
820
  fields[name] = {
642
- type,
821
+ type: type2,
643
822
  args,
644
823
  async resolve(_root, params, context, info) {
645
824
  try {
@@ -656,7 +835,6 @@ async function getResolvers_default(options, mutation) {
656
835
  }
657
836
 
658
837
  // src/buildSchema/getQuery.ts
659
- import isEmpty from "lodash/isEmpty";
660
838
  async function getQuery_default(options) {
661
839
  const fields = await getResolvers_default(options, false);
662
840
  if (isEmpty(fields)) return null;
@@ -668,10 +846,9 @@ async function getQuery_default(options) {
668
846
 
669
847
  // src/buildSchema/getMutation.ts
670
848
  import { GraphQLObjectType as GraphQLObjectType3 } from "graphql";
671
- import isEmpty2 from "lodash/isEmpty";
672
849
  async function getMutation_default(options) {
673
850
  const fields = await getResolvers_default(options, true);
674
- if (isEmpty2(fields)) return null;
851
+ if (isEmpty(fields)) return null;
675
852
  return new GraphQLObjectType3({
676
853
  name: "Mutation",
677
854
  fields
@@ -688,10 +865,10 @@ async function getSubscriptions_default(options) {
688
865
  for (const key of Object.keys(subscriptions)) {
689
866
  const subscription = subscriptions[key];
690
867
  subscription.name = subscription.name || key;
691
- const type = await getGraphQLType(subscription.returns, options);
868
+ const type2 = await getGraphQLType(subscription.returns, options);
692
869
  const args = await getArgs_default(subscription.params);
693
870
  fields[subscription.name] = {
694
- type,
871
+ type: type2,
695
872
  args,
696
873
  async subscribe(root, params, viewer) {
697
874
  return await subscription.subscribe(params, viewer);
@@ -734,18 +911,20 @@ function formatError_default(apolloError) {
734
911
  }
735
912
 
736
913
  // src/getApolloOptions/index.ts
737
- import { omit } from "lodash";
738
914
  async function getApolloOptions_default(options) {
739
915
  const schema = await buildSchema_default(options);
740
- const passedOptions = omit(options, [
741
- "resolvers",
742
- "modelResolvers",
743
- "subscriptions",
744
- "executeGraphQLCache",
745
- "useGraphiql",
746
- "app",
747
- "pubsub"
748
- ]);
916
+ const passedOptions = omit(
917
+ [
918
+ "resolvers",
919
+ "modelResolvers",
920
+ "subscriptions",
921
+ "executeGraphQLCache",
922
+ "useGraphiql",
923
+ "app",
924
+ "pubsub"
925
+ ],
926
+ options
927
+ );
749
928
  return {
750
929
  ...passedOptions,
751
930
  schema,
@@ -878,20 +1057,20 @@ import {
878
1057
  getSchemaWithMetadataFromAnyOrionForm as getSchemaWithMetadataFromAnyOrionForm2,
879
1058
  isSchemaLike as isSchemaLike2
880
1059
  } from "@orion-js/schema";
881
- import omit2 from "lodash/omit";
882
1060
  async function getParams(field) {
883
- const { type } = field;
884
- if (Array.isArray(type)) {
885
- const serialized = await getParams({ ...field, type: type[0] });
1061
+ const { type: type2 } = field;
1062
+ console.log(type2, "getting parms");
1063
+ if (Array.isArray(type2)) {
1064
+ const serialized = await getParams({ ...field, type: type2[0] });
886
1065
  return {
887
1066
  ...serialized,
888
1067
  type: [serialized.type],
889
1068
  __graphQLType: `[${serialized.__graphQLType}]`
890
1069
  };
891
1070
  }
892
- const isSchema = isSchemaLike2(type);
1071
+ const isSchema = isSchemaLike2(type2);
893
1072
  if (isSchema) {
894
- const schemaOfType = getSchemaWithMetadataFromAnyOrionForm2(type);
1073
+ const schemaOfType = getSchemaWithMetadataFromAnyOrionForm2(type2);
895
1074
  const modelName = schemaOfType.__modelName;
896
1075
  if (!modelName) {
897
1076
  throw new Error("The schema needs a model name to be serialized for GraphQL");
@@ -901,31 +1080,34 @@ async function getParams(field) {
901
1080
  fields[field2.key] = await getParams(field2);
902
1081
  }
903
1082
  return {
904
- ...omit2(field, "key"),
1083
+ ...omit(["key"], field),
905
1084
  type: fields,
906
1085
  __graphQLType: `${modelName}Input`
907
1086
  };
908
1087
  }
909
- const schemaType = getFieldType3(type);
1088
+ const schemaType = getFieldType3(type2);
910
1089
  const graphQLType = await getScalar_default(schemaType);
1090
+ const withoutKey = isType("Object", field) ? omit(["key"], field) : {};
911
1091
  return {
912
- ...omit2(field, "key"),
1092
+ ...withoutKey,
913
1093
  type: schemaType.name,
914
1094
  __graphQLType: graphQLType.name
915
1095
  };
916
1096
  }
917
1097
 
918
1098
  // src/resolversSchemas/serializeSchema.ts
919
- Symbol.metadata ?? (Symbol.metadata = Symbol("Symbol.metadata"));
920
1099
  async function serializeSchema(params) {
921
1100
  if (!params) return;
922
1101
  const schema = getSchemaFromAnyOrionForm(params);
923
1102
  if (Object.keys(schema).length === 0) return;
924
1103
  const fields = {};
1104
+ console.log(schema, "schema");
925
1105
  for (const key of Object.keys(schema).filter((key2) => !key2.startsWith("__"))) {
926
1106
  const field = schema[key];
927
1107
  fields[key] = await getParams(field);
1108
+ console.log(fields[key], field);
928
1109
  }
1110
+ console.log(fields, "fields");
929
1111
  return fields;
930
1112
  }
931
1113
 
@@ -933,11 +1115,10 @@ async function serializeSchema(params) {
933
1115
  import { getSchemaFromAnyOrionForm as getSchemaFromAnyOrionForm3, isSchemaLike as isSchemaLike4 } from "@orion-js/schema";
934
1116
 
935
1117
  // src/resolversSchemas/getBasicResultQuery.ts
936
- import isArray3 from "lodash/isArray";
937
1118
  import { getSchemaFromAnyOrionForm as getSchemaFromAnyOrionForm2, isSchemaLike as isSchemaLike3 } from "@orion-js/schema";
938
1119
  async function getBasicQuery(field) {
939
1120
  if (!field.type) return "";
940
- if (isArray3(field.type)) {
1121
+ if (Array.isArray(field.type)) {
941
1122
  return getBasicQuery({
942
1123
  ...field,
943
1124
  type: field.type[0]
@@ -956,14 +1137,14 @@ async function getBasicQuery(field) {
956
1137
  }
957
1138
 
958
1139
  // src/resolversSchemas/params.ts
959
- function getResultTypeName(type) {
960
- const returns = Array.isArray(type) ? type[0] : type;
1140
+ function getResultTypeName(type2) {
1141
+ const returns = Array.isArray(type2) ? type2[0] : type2;
961
1142
  const schema = getSchemaFromAnyOrionForm3(returns);
962
1143
  if (schema == null ? void 0 : schema.__modelName) return schema.__modelName;
963
1144
  return;
964
1145
  }
965
- async function getInternalBasicResultQuery(type) {
966
- const returns = Array.isArray(type) ? type[0] : type;
1146
+ async function getInternalBasicResultQuery(type2) {
1147
+ const returns = Array.isArray(type2) ? type2[0] : type2;
967
1148
  if (isSchemaLike4(returns)) {
968
1149
  const schema = getSchemaFromAnyOrionForm3(returns);
969
1150
  return await getBasicQuery({
@@ -1026,10 +1207,10 @@ import { resolver } from "@orion-js/resolvers";
1026
1207
 
1027
1208
  // src/service/middlewares.ts
1028
1209
  var resolversMetadata = /* @__PURE__ */ new WeakMap();
1029
- function addTargetMetadata(target, propertyKey, metadataKey, metadata, isArray4 = false) {
1210
+ function addTargetMetadata(target, propertyKey, metadataKey, metadata, isArray2 = false) {
1030
1211
  const targetMetadata = resolversMetadata.get(target) || {};
1031
1212
  targetMetadata[propertyKey] = targetMetadata[propertyKey] || {};
1032
- if (isArray4) {
1213
+ if (isArray2) {
1033
1214
  targetMetadata[propertyKey][metadataKey] = targetMetadata[propertyKey][metadataKey] || [];
1034
1215
  targetMetadata[propertyKey][metadataKey].unshift(metadata);
1035
1216
  } else {