@luvio/graphql-parser 0.81.0 → 0.82.1

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.
@@ -1,11 +1,18 @@
1
- import type { GraphQLSchema } from 'graphql';
1
+ import type { GraphQLScalarType, GraphQLSchema } from 'graphql';
2
2
  interface LuvioGraphQLSchemaParams {
3
3
  schema: GraphQLSchema;
4
4
  schemaName: string;
5
5
  }
6
- export declare class LuvioGraphQLSchema {
6
+ export interface LuvioGraphQLSchema {
7
7
  schema: Readonly<GraphQLSchema>;
8
8
  schemaName: Readonly<string>;
9
+ customScalars: GraphQLScalarType[];
10
+ }
11
+ export declare class LuvioSchema implements LuvioGraphQLSchema {
12
+ schema: Readonly<GraphQLSchema>;
13
+ schemaName: Readonly<string>;
14
+ customScalars: GraphQLScalarType[];
9
15
  constructor(luvioSchemaParams: Readonly<LuvioGraphQLSchemaParams>);
16
+ private extractCustomScalars;
10
17
  }
11
18
  export {};
@@ -3843,115 +3843,6 @@ function isTypeExtensionNode(node) {
3843
3843
  return node.kind === Kind.SCALAR_TYPE_EXTENSION || node.kind === Kind.OBJECT_TYPE_EXTENSION || node.kind === Kind.INTERFACE_TYPE_EXTENSION || node.kind === Kind.UNION_TYPE_EXTENSION || node.kind === Kind.ENUM_TYPE_EXTENSION || node.kind === Kind.INPUT_OBJECT_TYPE_EXTENSION;
3844
3844
  }
3845
3845
 
3846
- /* eslint-disable no-redeclare */
3847
- // $FlowFixMe[name-already-bound]
3848
- var find = Array.prototype.find ? function (list, predicate) {
3849
- return Array.prototype.find.call(list, predicate);
3850
- } : function (list, predicate) {
3851
- for (var _i2 = 0; _i2 < list.length; _i2++) {
3852
- var value = list[_i2];
3853
-
3854
- if (predicate(value)) {
3855
- return value;
3856
- }
3857
- }
3858
- };
3859
- var find$1 = find;
3860
-
3861
- /* eslint-disable no-redeclare */
3862
- // $FlowFixMe[name-already-bound]
3863
- var arrayFrom = Array.from || function (obj, mapFn, thisArg) {
3864
- if (obj == null) {
3865
- throw new TypeError('Array.from requires an array-like object - not null or undefined');
3866
- } // Is Iterable?
3867
-
3868
-
3869
- var iteratorMethod = obj[SYMBOL_ITERATOR];
3870
-
3871
- if (typeof iteratorMethod === 'function') {
3872
- var iterator = iteratorMethod.call(obj);
3873
- var result = [];
3874
- var step;
3875
-
3876
- for (var i = 0; !(step = iterator.next()).done; ++i) {
3877
- result.push(mapFn.call(thisArg, step.value, i)); // Infinite Iterators could cause forEach to run forever.
3878
- // After a very large number of iterations, produce an error.
3879
- // istanbul ignore if (Too big to actually test)
3880
-
3881
- if (i > 9999999) {
3882
- throw new TypeError('Near-infinite iteration.');
3883
- }
3884
- }
3885
-
3886
- return result;
3887
- } // Is Array like?
3888
-
3889
-
3890
- var length = obj.length;
3891
-
3892
- if (typeof length === 'number' && length >= 0 && length % 1 === 0) {
3893
- var _result = [];
3894
-
3895
- for (var _i = 0; _i < length; ++_i) {
3896
- if (Object.prototype.hasOwnProperty.call(obj, _i)) {
3897
- _result.push(mapFn.call(thisArg, obj[_i], _i));
3898
- }
3899
- }
3900
-
3901
- return _result;
3902
- }
3903
-
3904
- return [];
3905
- };
3906
-
3907
- var arrayFrom$1 = arrayFrom;
3908
-
3909
- /* eslint-disable no-redeclare */
3910
- // $FlowFixMe[name-already-bound] workaround for: https://github.com/facebook/flow/issues/4441
3911
- var objectValues = Object.values || function (obj) {
3912
- return Object.keys(obj).map(function (key) {
3913
- return obj[key];
3914
- });
3915
- };
3916
-
3917
- var objectValues$1 = objectValues;
3918
-
3919
- /* eslint-disable no-redeclare */
3920
- // $FlowFixMe[name-already-bound] workaround for: https://github.com/facebook/flow/issues/4441
3921
- var objectEntries = Object.entries || function (obj) {
3922
- return Object.keys(obj).map(function (key) {
3923
- return [key, obj[key]];
3924
- });
3925
- };
3926
-
3927
- var objectEntries$1 = objectEntries;
3928
-
3929
- function toObjMap(obj) {
3930
- /* eslint-enable no-redeclare */
3931
- if (Object.getPrototypeOf(obj) === null) {
3932
- return obj;
3933
- }
3934
-
3935
- var map = Object.create(null);
3936
-
3937
- for (var _i2 = 0, _objectEntries2 = objectEntries$1(obj); _i2 < _objectEntries2.length; _i2++) {
3938
- var _ref2 = _objectEntries2[_i2];
3939
- var key = _ref2[0];
3940
- var value = _ref2[1];
3941
- map[key] = value;
3942
- }
3943
-
3944
- return map;
3945
- }
3946
-
3947
- /* eslint-disable no-redeclare */
3948
- // $FlowFixMe[name-already-bound] workaround for: https://github.com/facebook/flow/issues/4441
3949
- var isFinitePolyfill = Number.isFinite || function (value) {
3950
- return typeof value === 'number' && isFinite(value);
3951
- };
3952
-
3953
- var isFinite$1 = isFinitePolyfill;
3954
-
3955
3846
  function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
3956
3847
  /**
3957
3848
  * Safer version of `Array.from` that return `null` if value isn't convertible to array.
@@ -4017,13 +3908,40 @@ function safeArrayFrom(collection) {
4017
3908
  return null;
4018
3909
  }
4019
3910
 
3911
+ /* eslint-disable no-redeclare */
3912
+ // $FlowFixMe[name-already-bound]
3913
+ var find = Array.prototype.find ? function (list, predicate) {
3914
+ return Array.prototype.find.call(list, predicate);
3915
+ } : function (list, predicate) {
3916
+ for (var _i2 = 0; _i2 < list.length; _i2++) {
3917
+ var value = list[_i2];
3918
+
3919
+ if (predicate(value)) {
3920
+ return value;
3921
+ }
3922
+ }
3923
+ };
3924
+ var find$1 = find;
3925
+
4020
3926
  /* eslint-disable no-redeclare */
4021
3927
  // $FlowFixMe[name-already-bound] workaround for: https://github.com/facebook/flow/issues/4441
4022
- var isInteger = Number.isInteger || function (value) {
4023
- return typeof value === 'number' && isFinite(value) && Math.floor(value) === value;
3928
+ var objectValues = Object.values || function (obj) {
3929
+ return Object.keys(obj).map(function (key) {
3930
+ return obj[key];
3931
+ });
4024
3932
  };
4025
3933
 
4026
- var isInteger$1 = isInteger;
3934
+ var objectValues$1 = objectValues;
3935
+
3936
+ /* eslint-disable no-redeclare */
3937
+ // $FlowFixMe[name-already-bound] workaround for: https://github.com/facebook/flow/issues/4441
3938
+ var objectEntries = Object.entries || function (obj) {
3939
+ return Object.keys(obj).map(function (key) {
3940
+ return [key, obj[key]];
3941
+ });
3942
+ };
3943
+
3944
+ var objectEntries$1 = objectEntries;
4027
3945
 
4028
3946
  /**
4029
3947
  * Creates a keyed JS object from an array, given a function to produce the keys
@@ -4072,6 +3990,24 @@ function mapValue(map, fn) {
4072
3990
  return result;
4073
3991
  }
4074
3992
 
3993
+ function toObjMap(obj) {
3994
+ /* eslint-enable no-redeclare */
3995
+ if (Object.getPrototypeOf(obj) === null) {
3996
+ return obj;
3997
+ }
3998
+
3999
+ var map = Object.create(null);
4000
+
4001
+ for (var _i2 = 0, _objectEntries2 = objectEntries$1(obj); _i2 < _objectEntries2.length; _i2++) {
4002
+ var _ref2 = _objectEntries2[_i2];
4003
+ var key = _ref2[0];
4004
+ var value = _ref2[1];
4005
+ map[key] = value;
4006
+ }
4007
+
4008
+ return map;
4009
+ }
4010
+
4075
4011
  /**
4076
4012
  * Creates a keyed JS object from an array, given a function to produce the keys
4077
4013
  * and a function to produce the values from each item in the array.
@@ -5355,6 +5291,151 @@ function isRequiredInputField(field) {
5355
5291
  return isNonNullType(field.type) && field.defaultValue === undefined;
5356
5292
  }
5357
5293
 
5294
+ /**
5295
+ * Provided a type and a super type, return true if the first type is either
5296
+ * equal or a subset of the second super type (covariant).
5297
+ */
5298
+
5299
+ function isTypeSubTypeOf(schema, maybeSubType, superType) {
5300
+ // Equivalent type is a valid subtype
5301
+ if (maybeSubType === superType) {
5302
+ return true;
5303
+ } // If superType is non-null, maybeSubType must also be non-null.
5304
+
5305
+
5306
+ if (isNonNullType(superType)) {
5307
+ if (isNonNullType(maybeSubType)) {
5308
+ return isTypeSubTypeOf(schema, maybeSubType.ofType, superType.ofType);
5309
+ }
5310
+
5311
+ return false;
5312
+ }
5313
+
5314
+ if (isNonNullType(maybeSubType)) {
5315
+ // If superType is nullable, maybeSubType may be non-null or nullable.
5316
+ return isTypeSubTypeOf(schema, maybeSubType.ofType, superType);
5317
+ } // If superType type is a list, maybeSubType type must also be a list.
5318
+
5319
+
5320
+ if (isListType(superType)) {
5321
+ if (isListType(maybeSubType)) {
5322
+ return isTypeSubTypeOf(schema, maybeSubType.ofType, superType.ofType);
5323
+ }
5324
+
5325
+ return false;
5326
+ }
5327
+
5328
+ if (isListType(maybeSubType)) {
5329
+ // If superType is not a list, maybeSubType must also be not a list.
5330
+ return false;
5331
+ } // If superType type is an abstract type, check if it is super type of maybeSubType.
5332
+ // Otherwise, the child type is not a valid subtype of the parent type.
5333
+
5334
+
5335
+ return isAbstractType(superType) && (isInterfaceType(maybeSubType) || isObjectType(maybeSubType)) && schema.isSubType(superType, maybeSubType);
5336
+ }
5337
+ /**
5338
+ * Provided two composite types, determine if they "overlap". Two composite
5339
+ * types overlap when the Sets of possible concrete types for each intersect.
5340
+ *
5341
+ * This is often used to determine if a fragment of a given type could possibly
5342
+ * be visited in a context of another type.
5343
+ *
5344
+ * This function is commutative.
5345
+ */
5346
+
5347
+ function doTypesOverlap(schema, typeA, typeB) {
5348
+ // Equivalent types overlap
5349
+ if (typeA === typeB) {
5350
+ return true;
5351
+ }
5352
+
5353
+ if (isAbstractType(typeA)) {
5354
+ if (isAbstractType(typeB)) {
5355
+ // If both types are abstract, then determine if there is any intersection
5356
+ // between possible concrete types of each.
5357
+ return schema.getPossibleTypes(typeA).some(function (type) {
5358
+ return schema.isSubType(typeB, type);
5359
+ });
5360
+ } // Determine if the latter type is a possible concrete type of the former.
5361
+
5362
+
5363
+ return schema.isSubType(typeA, typeB);
5364
+ }
5365
+
5366
+ if (isAbstractType(typeB)) {
5367
+ // Determine if the former type is a possible concrete type of the latter.
5368
+ return schema.isSubType(typeB, typeA);
5369
+ } // Otherwise the types do not overlap.
5370
+
5371
+
5372
+ return false;
5373
+ }
5374
+
5375
+ /* eslint-disable no-redeclare */
5376
+ // $FlowFixMe[name-already-bound]
5377
+ var arrayFrom = Array.from || function (obj, mapFn, thisArg) {
5378
+ if (obj == null) {
5379
+ throw new TypeError('Array.from requires an array-like object - not null or undefined');
5380
+ } // Is Iterable?
5381
+
5382
+
5383
+ var iteratorMethod = obj[SYMBOL_ITERATOR];
5384
+
5385
+ if (typeof iteratorMethod === 'function') {
5386
+ var iterator = iteratorMethod.call(obj);
5387
+ var result = [];
5388
+ var step;
5389
+
5390
+ for (var i = 0; !(step = iterator.next()).done; ++i) {
5391
+ result.push(mapFn.call(thisArg, step.value, i)); // Infinite Iterators could cause forEach to run forever.
5392
+ // After a very large number of iterations, produce an error.
5393
+ // istanbul ignore if (Too big to actually test)
5394
+
5395
+ if (i > 9999999) {
5396
+ throw new TypeError('Near-infinite iteration.');
5397
+ }
5398
+ }
5399
+
5400
+ return result;
5401
+ } // Is Array like?
5402
+
5403
+
5404
+ var length = obj.length;
5405
+
5406
+ if (typeof length === 'number' && length >= 0 && length % 1 === 0) {
5407
+ var _result = [];
5408
+
5409
+ for (var _i = 0; _i < length; ++_i) {
5410
+ if (Object.prototype.hasOwnProperty.call(obj, _i)) {
5411
+ _result.push(mapFn.call(thisArg, obj[_i], _i));
5412
+ }
5413
+ }
5414
+
5415
+ return _result;
5416
+ }
5417
+
5418
+ return [];
5419
+ };
5420
+
5421
+ var arrayFrom$1 = arrayFrom;
5422
+
5423
+ /* eslint-disable no-redeclare */
5424
+ // $FlowFixMe[name-already-bound] workaround for: https://github.com/facebook/flow/issues/4441
5425
+ var isFinitePolyfill = Number.isFinite || function (value) {
5426
+ return typeof value === 'number' && isFinite(value);
5427
+ };
5428
+
5429
+ var isFinite$1 = isFinitePolyfill;
5430
+
5431
+ /* eslint-disable no-redeclare */
5432
+ // $FlowFixMe[name-already-bound] workaround for: https://github.com/facebook/flow/issues/4441
5433
+ var isInteger = Number.isInteger || function (value) {
5434
+ return typeof value === 'number' && isFinite(value) && Math.floor(value) === value;
5435
+ };
5436
+
5437
+ var isInteger$1 = isInteger;
5438
+
5358
5439
  // 32-bit signed integer, providing the broadest support across platforms.
5359
5440
  //
5360
5441
  // n.b. JavaScript's integers are safe between -(2^53 - 1) and 2^53 - 1 because
@@ -6831,87 +6912,6 @@ function collectReferencedTypes(type, typeSet) {
6831
6912
  return typeSet;
6832
6913
  }
6833
6914
 
6834
- /**
6835
- * Provided a type and a super type, return true if the first type is either
6836
- * equal or a subset of the second super type (covariant).
6837
- */
6838
-
6839
- function isTypeSubTypeOf(schema, maybeSubType, superType) {
6840
- // Equivalent type is a valid subtype
6841
- if (maybeSubType === superType) {
6842
- return true;
6843
- } // If superType is non-null, maybeSubType must also be non-null.
6844
-
6845
-
6846
- if (isNonNullType(superType)) {
6847
- if (isNonNullType(maybeSubType)) {
6848
- return isTypeSubTypeOf(schema, maybeSubType.ofType, superType.ofType);
6849
- }
6850
-
6851
- return false;
6852
- }
6853
-
6854
- if (isNonNullType(maybeSubType)) {
6855
- // If superType is nullable, maybeSubType may be non-null or nullable.
6856
- return isTypeSubTypeOf(schema, maybeSubType.ofType, superType);
6857
- } // If superType type is a list, maybeSubType type must also be a list.
6858
-
6859
-
6860
- if (isListType(superType)) {
6861
- if (isListType(maybeSubType)) {
6862
- return isTypeSubTypeOf(schema, maybeSubType.ofType, superType.ofType);
6863
- }
6864
-
6865
- return false;
6866
- }
6867
-
6868
- if (isListType(maybeSubType)) {
6869
- // If superType is not a list, maybeSubType must also be not a list.
6870
- return false;
6871
- } // If superType type is an abstract type, check if it is super type of maybeSubType.
6872
- // Otherwise, the child type is not a valid subtype of the parent type.
6873
-
6874
-
6875
- return isAbstractType(superType) && (isInterfaceType(maybeSubType) || isObjectType(maybeSubType)) && schema.isSubType(superType, maybeSubType);
6876
- }
6877
- /**
6878
- * Provided two composite types, determine if they "overlap". Two composite
6879
- * types overlap when the Sets of possible concrete types for each intersect.
6880
- *
6881
- * This is often used to determine if a fragment of a given type could possibly
6882
- * be visited in a context of another type.
6883
- *
6884
- * This function is commutative.
6885
- */
6886
-
6887
- function doTypesOverlap(schema, typeA, typeB) {
6888
- // Equivalent types overlap
6889
- if (typeA === typeB) {
6890
- return true;
6891
- }
6892
-
6893
- if (isAbstractType(typeA)) {
6894
- if (isAbstractType(typeB)) {
6895
- // If both types are abstract, then determine if there is any intersection
6896
- // between possible concrete types of each.
6897
- return schema.getPossibleTypes(typeA).some(function (type) {
6898
- return schema.isSubType(typeB, type);
6899
- });
6900
- } // Determine if the latter type is a possible concrete type of the former.
6901
-
6902
-
6903
- return schema.isSubType(typeA, typeB);
6904
- }
6905
-
6906
- if (isAbstractType(typeB)) {
6907
- // Determine if the former type is a possible concrete type of the latter.
6908
- return schema.isSubType(typeB, typeA);
6909
- } // Otherwise the types do not overlap.
6910
-
6911
-
6912
- return false;
6913
- }
6914
-
6915
6915
  /**
6916
6916
  * Given a Schema and an AST node describing a type, return a GraphQLType
6917
6917
  * definition which applies to that type. For example, if provided the parsed
@@ -10690,10 +10690,19 @@ function transform(root) {
10690
10690
  };
10691
10691
  }
10692
10692
 
10693
- class LuvioGraphQLSchema {
10693
+ class LuvioSchema {
10694
10694
  constructor(luvioSchemaParams) {
10695
+ this.customScalars = [];
10695
10696
  this.schemaName = luvioSchemaParams.schemaName;
10696
10697
  this.schema = luvioSchemaParams.schema;
10698
+ this.extractCustomScalars();
10699
+ }
10700
+ extractCustomScalars() {
10701
+ Object.values(this.schema.getTypeMap()).forEach((def) => {
10702
+ if (isScalarType(def) && def.astNode !== undefined) {
10703
+ this.customScalars.push(def);
10704
+ }
10705
+ });
10697
10706
  }
10698
10707
  }
10699
10708
 
@@ -10706,14 +10715,13 @@ function parseAndVisit(source) {
10706
10715
  }
10707
10716
  function parseLuvioSchema(source, schemaName) {
10708
10717
  const schema = buildASTSchema(parse(source));
10709
- return new LuvioGraphQLSchema({
10718
+ return new LuvioSchema({
10710
10719
  schema,
10711
10720
  schemaName,
10712
10721
  });
10713
10722
  }
10714
10723
 
10715
10724
  exports.Kind = Kind;
10716
- exports.LuvioGraphQLSchema = LuvioGraphQLSchema;
10717
10725
  exports.isScalarType = isScalarType;
10718
10726
  exports.parseAndVisit = parseAndVisit;
10719
10727
  exports.parseLuvioSchema = parseLuvioSchema;
@@ -3839,115 +3839,6 @@ function isTypeExtensionNode(node) {
3839
3839
  return node.kind === Kind.SCALAR_TYPE_EXTENSION || node.kind === Kind.OBJECT_TYPE_EXTENSION || node.kind === Kind.INTERFACE_TYPE_EXTENSION || node.kind === Kind.UNION_TYPE_EXTENSION || node.kind === Kind.ENUM_TYPE_EXTENSION || node.kind === Kind.INPUT_OBJECT_TYPE_EXTENSION;
3840
3840
  }
3841
3841
 
3842
- /* eslint-disable no-redeclare */
3843
- // $FlowFixMe[name-already-bound]
3844
- var find = Array.prototype.find ? function (list, predicate) {
3845
- return Array.prototype.find.call(list, predicate);
3846
- } : function (list, predicate) {
3847
- for (var _i2 = 0; _i2 < list.length; _i2++) {
3848
- var value = list[_i2];
3849
-
3850
- if (predicate(value)) {
3851
- return value;
3852
- }
3853
- }
3854
- };
3855
- var find$1 = find;
3856
-
3857
- /* eslint-disable no-redeclare */
3858
- // $FlowFixMe[name-already-bound]
3859
- var arrayFrom = Array.from || function (obj, mapFn, thisArg) {
3860
- if (obj == null) {
3861
- throw new TypeError('Array.from requires an array-like object - not null or undefined');
3862
- } // Is Iterable?
3863
-
3864
-
3865
- var iteratorMethod = obj[SYMBOL_ITERATOR];
3866
-
3867
- if (typeof iteratorMethod === 'function') {
3868
- var iterator = iteratorMethod.call(obj);
3869
- var result = [];
3870
- var step;
3871
-
3872
- for (var i = 0; !(step = iterator.next()).done; ++i) {
3873
- result.push(mapFn.call(thisArg, step.value, i)); // Infinite Iterators could cause forEach to run forever.
3874
- // After a very large number of iterations, produce an error.
3875
- // istanbul ignore if (Too big to actually test)
3876
-
3877
- if (i > 9999999) {
3878
- throw new TypeError('Near-infinite iteration.');
3879
- }
3880
- }
3881
-
3882
- return result;
3883
- } // Is Array like?
3884
-
3885
-
3886
- var length = obj.length;
3887
-
3888
- if (typeof length === 'number' && length >= 0 && length % 1 === 0) {
3889
- var _result = [];
3890
-
3891
- for (var _i = 0; _i < length; ++_i) {
3892
- if (Object.prototype.hasOwnProperty.call(obj, _i)) {
3893
- _result.push(mapFn.call(thisArg, obj[_i], _i));
3894
- }
3895
- }
3896
-
3897
- return _result;
3898
- }
3899
-
3900
- return [];
3901
- };
3902
-
3903
- var arrayFrom$1 = arrayFrom;
3904
-
3905
- /* eslint-disable no-redeclare */
3906
- // $FlowFixMe[name-already-bound] workaround for: https://github.com/facebook/flow/issues/4441
3907
- var objectValues = Object.values || function (obj) {
3908
- return Object.keys(obj).map(function (key) {
3909
- return obj[key];
3910
- });
3911
- };
3912
-
3913
- var objectValues$1 = objectValues;
3914
-
3915
- /* eslint-disable no-redeclare */
3916
- // $FlowFixMe[name-already-bound] workaround for: https://github.com/facebook/flow/issues/4441
3917
- var objectEntries = Object.entries || function (obj) {
3918
- return Object.keys(obj).map(function (key) {
3919
- return [key, obj[key]];
3920
- });
3921
- };
3922
-
3923
- var objectEntries$1 = objectEntries;
3924
-
3925
- function toObjMap(obj) {
3926
- /* eslint-enable no-redeclare */
3927
- if (Object.getPrototypeOf(obj) === null) {
3928
- return obj;
3929
- }
3930
-
3931
- var map = Object.create(null);
3932
-
3933
- for (var _i2 = 0, _objectEntries2 = objectEntries$1(obj); _i2 < _objectEntries2.length; _i2++) {
3934
- var _ref2 = _objectEntries2[_i2];
3935
- var key = _ref2[0];
3936
- var value = _ref2[1];
3937
- map[key] = value;
3938
- }
3939
-
3940
- return map;
3941
- }
3942
-
3943
- /* eslint-disable no-redeclare */
3944
- // $FlowFixMe[name-already-bound] workaround for: https://github.com/facebook/flow/issues/4441
3945
- var isFinitePolyfill = Number.isFinite || function (value) {
3946
- return typeof value === 'number' && isFinite(value);
3947
- };
3948
-
3949
- var isFinite$1 = isFinitePolyfill;
3950
-
3951
3842
  function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
3952
3843
  /**
3953
3844
  * Safer version of `Array.from` that return `null` if value isn't convertible to array.
@@ -4013,13 +3904,40 @@ function safeArrayFrom(collection) {
4013
3904
  return null;
4014
3905
  }
4015
3906
 
3907
+ /* eslint-disable no-redeclare */
3908
+ // $FlowFixMe[name-already-bound]
3909
+ var find = Array.prototype.find ? function (list, predicate) {
3910
+ return Array.prototype.find.call(list, predicate);
3911
+ } : function (list, predicate) {
3912
+ for (var _i2 = 0; _i2 < list.length; _i2++) {
3913
+ var value = list[_i2];
3914
+
3915
+ if (predicate(value)) {
3916
+ return value;
3917
+ }
3918
+ }
3919
+ };
3920
+ var find$1 = find;
3921
+
4016
3922
  /* eslint-disable no-redeclare */
4017
3923
  // $FlowFixMe[name-already-bound] workaround for: https://github.com/facebook/flow/issues/4441
4018
- var isInteger = Number.isInteger || function (value) {
4019
- return typeof value === 'number' && isFinite(value) && Math.floor(value) === value;
3924
+ var objectValues = Object.values || function (obj) {
3925
+ return Object.keys(obj).map(function (key) {
3926
+ return obj[key];
3927
+ });
4020
3928
  };
4021
3929
 
4022
- var isInteger$1 = isInteger;
3930
+ var objectValues$1 = objectValues;
3931
+
3932
+ /* eslint-disable no-redeclare */
3933
+ // $FlowFixMe[name-already-bound] workaround for: https://github.com/facebook/flow/issues/4441
3934
+ var objectEntries = Object.entries || function (obj) {
3935
+ return Object.keys(obj).map(function (key) {
3936
+ return [key, obj[key]];
3937
+ });
3938
+ };
3939
+
3940
+ var objectEntries$1 = objectEntries;
4023
3941
 
4024
3942
  /**
4025
3943
  * Creates a keyed JS object from an array, given a function to produce the keys
@@ -4068,6 +3986,24 @@ function mapValue(map, fn) {
4068
3986
  return result;
4069
3987
  }
4070
3988
 
3989
+ function toObjMap(obj) {
3990
+ /* eslint-enable no-redeclare */
3991
+ if (Object.getPrototypeOf(obj) === null) {
3992
+ return obj;
3993
+ }
3994
+
3995
+ var map = Object.create(null);
3996
+
3997
+ for (var _i2 = 0, _objectEntries2 = objectEntries$1(obj); _i2 < _objectEntries2.length; _i2++) {
3998
+ var _ref2 = _objectEntries2[_i2];
3999
+ var key = _ref2[0];
4000
+ var value = _ref2[1];
4001
+ map[key] = value;
4002
+ }
4003
+
4004
+ return map;
4005
+ }
4006
+
4071
4007
  /**
4072
4008
  * Creates a keyed JS object from an array, given a function to produce the keys
4073
4009
  * and a function to produce the values from each item in the array.
@@ -5351,6 +5287,151 @@ function isRequiredInputField(field) {
5351
5287
  return isNonNullType(field.type) && field.defaultValue === undefined;
5352
5288
  }
5353
5289
 
5290
+ /**
5291
+ * Provided a type and a super type, return true if the first type is either
5292
+ * equal or a subset of the second super type (covariant).
5293
+ */
5294
+
5295
+ function isTypeSubTypeOf(schema, maybeSubType, superType) {
5296
+ // Equivalent type is a valid subtype
5297
+ if (maybeSubType === superType) {
5298
+ return true;
5299
+ } // If superType is non-null, maybeSubType must also be non-null.
5300
+
5301
+
5302
+ if (isNonNullType(superType)) {
5303
+ if (isNonNullType(maybeSubType)) {
5304
+ return isTypeSubTypeOf(schema, maybeSubType.ofType, superType.ofType);
5305
+ }
5306
+
5307
+ return false;
5308
+ }
5309
+
5310
+ if (isNonNullType(maybeSubType)) {
5311
+ // If superType is nullable, maybeSubType may be non-null or nullable.
5312
+ return isTypeSubTypeOf(schema, maybeSubType.ofType, superType);
5313
+ } // If superType type is a list, maybeSubType type must also be a list.
5314
+
5315
+
5316
+ if (isListType(superType)) {
5317
+ if (isListType(maybeSubType)) {
5318
+ return isTypeSubTypeOf(schema, maybeSubType.ofType, superType.ofType);
5319
+ }
5320
+
5321
+ return false;
5322
+ }
5323
+
5324
+ if (isListType(maybeSubType)) {
5325
+ // If superType is not a list, maybeSubType must also be not a list.
5326
+ return false;
5327
+ } // If superType type is an abstract type, check if it is super type of maybeSubType.
5328
+ // Otherwise, the child type is not a valid subtype of the parent type.
5329
+
5330
+
5331
+ return isAbstractType(superType) && (isInterfaceType(maybeSubType) || isObjectType(maybeSubType)) && schema.isSubType(superType, maybeSubType);
5332
+ }
5333
+ /**
5334
+ * Provided two composite types, determine if they "overlap". Two composite
5335
+ * types overlap when the Sets of possible concrete types for each intersect.
5336
+ *
5337
+ * This is often used to determine if a fragment of a given type could possibly
5338
+ * be visited in a context of another type.
5339
+ *
5340
+ * This function is commutative.
5341
+ */
5342
+
5343
+ function doTypesOverlap(schema, typeA, typeB) {
5344
+ // Equivalent types overlap
5345
+ if (typeA === typeB) {
5346
+ return true;
5347
+ }
5348
+
5349
+ if (isAbstractType(typeA)) {
5350
+ if (isAbstractType(typeB)) {
5351
+ // If both types are abstract, then determine if there is any intersection
5352
+ // between possible concrete types of each.
5353
+ return schema.getPossibleTypes(typeA).some(function (type) {
5354
+ return schema.isSubType(typeB, type);
5355
+ });
5356
+ } // Determine if the latter type is a possible concrete type of the former.
5357
+
5358
+
5359
+ return schema.isSubType(typeA, typeB);
5360
+ }
5361
+
5362
+ if (isAbstractType(typeB)) {
5363
+ // Determine if the former type is a possible concrete type of the latter.
5364
+ return schema.isSubType(typeB, typeA);
5365
+ } // Otherwise the types do not overlap.
5366
+
5367
+
5368
+ return false;
5369
+ }
5370
+
5371
+ /* eslint-disable no-redeclare */
5372
+ // $FlowFixMe[name-already-bound]
5373
+ var arrayFrom = Array.from || function (obj, mapFn, thisArg) {
5374
+ if (obj == null) {
5375
+ throw new TypeError('Array.from requires an array-like object - not null or undefined');
5376
+ } // Is Iterable?
5377
+
5378
+
5379
+ var iteratorMethod = obj[SYMBOL_ITERATOR];
5380
+
5381
+ if (typeof iteratorMethod === 'function') {
5382
+ var iterator = iteratorMethod.call(obj);
5383
+ var result = [];
5384
+ var step;
5385
+
5386
+ for (var i = 0; !(step = iterator.next()).done; ++i) {
5387
+ result.push(mapFn.call(thisArg, step.value, i)); // Infinite Iterators could cause forEach to run forever.
5388
+ // After a very large number of iterations, produce an error.
5389
+ // istanbul ignore if (Too big to actually test)
5390
+
5391
+ if (i > 9999999) {
5392
+ throw new TypeError('Near-infinite iteration.');
5393
+ }
5394
+ }
5395
+
5396
+ return result;
5397
+ } // Is Array like?
5398
+
5399
+
5400
+ var length = obj.length;
5401
+
5402
+ if (typeof length === 'number' && length >= 0 && length % 1 === 0) {
5403
+ var _result = [];
5404
+
5405
+ for (var _i = 0; _i < length; ++_i) {
5406
+ if (Object.prototype.hasOwnProperty.call(obj, _i)) {
5407
+ _result.push(mapFn.call(thisArg, obj[_i], _i));
5408
+ }
5409
+ }
5410
+
5411
+ return _result;
5412
+ }
5413
+
5414
+ return [];
5415
+ };
5416
+
5417
+ var arrayFrom$1 = arrayFrom;
5418
+
5419
+ /* eslint-disable no-redeclare */
5420
+ // $FlowFixMe[name-already-bound] workaround for: https://github.com/facebook/flow/issues/4441
5421
+ var isFinitePolyfill = Number.isFinite || function (value) {
5422
+ return typeof value === 'number' && isFinite(value);
5423
+ };
5424
+
5425
+ var isFinite$1 = isFinitePolyfill;
5426
+
5427
+ /* eslint-disable no-redeclare */
5428
+ // $FlowFixMe[name-already-bound] workaround for: https://github.com/facebook/flow/issues/4441
5429
+ var isInteger = Number.isInteger || function (value) {
5430
+ return typeof value === 'number' && isFinite(value) && Math.floor(value) === value;
5431
+ };
5432
+
5433
+ var isInteger$1 = isInteger;
5434
+
5354
5435
  // 32-bit signed integer, providing the broadest support across platforms.
5355
5436
  //
5356
5437
  // n.b. JavaScript's integers are safe between -(2^53 - 1) and 2^53 - 1 because
@@ -6827,87 +6908,6 @@ function collectReferencedTypes(type, typeSet) {
6827
6908
  return typeSet;
6828
6909
  }
6829
6910
 
6830
- /**
6831
- * Provided a type and a super type, return true if the first type is either
6832
- * equal or a subset of the second super type (covariant).
6833
- */
6834
-
6835
- function isTypeSubTypeOf(schema, maybeSubType, superType) {
6836
- // Equivalent type is a valid subtype
6837
- if (maybeSubType === superType) {
6838
- return true;
6839
- } // If superType is non-null, maybeSubType must also be non-null.
6840
-
6841
-
6842
- if (isNonNullType(superType)) {
6843
- if (isNonNullType(maybeSubType)) {
6844
- return isTypeSubTypeOf(schema, maybeSubType.ofType, superType.ofType);
6845
- }
6846
-
6847
- return false;
6848
- }
6849
-
6850
- if (isNonNullType(maybeSubType)) {
6851
- // If superType is nullable, maybeSubType may be non-null or nullable.
6852
- return isTypeSubTypeOf(schema, maybeSubType.ofType, superType);
6853
- } // If superType type is a list, maybeSubType type must also be a list.
6854
-
6855
-
6856
- if (isListType(superType)) {
6857
- if (isListType(maybeSubType)) {
6858
- return isTypeSubTypeOf(schema, maybeSubType.ofType, superType.ofType);
6859
- }
6860
-
6861
- return false;
6862
- }
6863
-
6864
- if (isListType(maybeSubType)) {
6865
- // If superType is not a list, maybeSubType must also be not a list.
6866
- return false;
6867
- } // If superType type is an abstract type, check if it is super type of maybeSubType.
6868
- // Otherwise, the child type is not a valid subtype of the parent type.
6869
-
6870
-
6871
- return isAbstractType(superType) && (isInterfaceType(maybeSubType) || isObjectType(maybeSubType)) && schema.isSubType(superType, maybeSubType);
6872
- }
6873
- /**
6874
- * Provided two composite types, determine if they "overlap". Two composite
6875
- * types overlap when the Sets of possible concrete types for each intersect.
6876
- *
6877
- * This is often used to determine if a fragment of a given type could possibly
6878
- * be visited in a context of another type.
6879
- *
6880
- * This function is commutative.
6881
- */
6882
-
6883
- function doTypesOverlap(schema, typeA, typeB) {
6884
- // Equivalent types overlap
6885
- if (typeA === typeB) {
6886
- return true;
6887
- }
6888
-
6889
- if (isAbstractType(typeA)) {
6890
- if (isAbstractType(typeB)) {
6891
- // If both types are abstract, then determine if there is any intersection
6892
- // between possible concrete types of each.
6893
- return schema.getPossibleTypes(typeA).some(function (type) {
6894
- return schema.isSubType(typeB, type);
6895
- });
6896
- } // Determine if the latter type is a possible concrete type of the former.
6897
-
6898
-
6899
- return schema.isSubType(typeA, typeB);
6900
- }
6901
-
6902
- if (isAbstractType(typeB)) {
6903
- // Determine if the former type is a possible concrete type of the latter.
6904
- return schema.isSubType(typeB, typeA);
6905
- } // Otherwise the types do not overlap.
6906
-
6907
-
6908
- return false;
6909
- }
6910
-
6911
6911
  /**
6912
6912
  * Given a Schema and an AST node describing a type, return a GraphQLType
6913
6913
  * definition which applies to that type. For example, if provided the parsed
@@ -10686,10 +10686,19 @@ function transform(root) {
10686
10686
  };
10687
10687
  }
10688
10688
 
10689
- class LuvioGraphQLSchema {
10689
+ class LuvioSchema {
10690
10690
  constructor(luvioSchemaParams) {
10691
+ this.customScalars = [];
10691
10692
  this.schemaName = luvioSchemaParams.schemaName;
10692
10693
  this.schema = luvioSchemaParams.schema;
10694
+ this.extractCustomScalars();
10695
+ }
10696
+ extractCustomScalars() {
10697
+ Object.values(this.schema.getTypeMap()).forEach((def) => {
10698
+ if (isScalarType(def) && def.astNode !== undefined) {
10699
+ this.customScalars.push(def);
10700
+ }
10701
+ });
10693
10702
  }
10694
10703
  }
10695
10704
 
@@ -10702,10 +10711,10 @@ function parseAndVisit(source) {
10702
10711
  }
10703
10712
  function parseLuvioSchema(source, schemaName) {
10704
10713
  const schema = buildASTSchema(parse(source));
10705
- return new LuvioGraphQLSchema({
10714
+ return new LuvioSchema({
10706
10715
  schema,
10707
10716
  schemaName,
10708
10717
  });
10709
10718
  }
10710
10719
 
10711
- export { Kind, LuvioGraphQLSchema, isScalarType, parseAndVisit, parseLuvioSchema };
10720
+ export { Kind, isScalarType, parseAndVisit, parseLuvioSchema };
package/dist/main.d.ts CHANGED
@@ -1,11 +1,13 @@
1
- import { BooleanValueNode, EnumTypeDefinitionNode, FieldDefinitionNode, FloatValueNode, InterfaceTypeDefinitionNode, IntValueNode, Kind, NamedTypeNode, ObjectTypeDefinitionNode, StringValueNode, TypeNode, UnionTypeDefinitionNode } from 'graphql/language';
2
- import { isScalarType } from 'graphql/type';
3
1
  import { LuvioDocumentNode, LuvioArgumentNode, LuvioDefinitionNode, LuvioObjectValueNode, LuvioOperationDefinitionNode, LuvioSelectionCustomFieldNode, LuvioSelectionNode, LuvioSelectionObjectFieldNode, LuvioSelectionScalarFieldNode, LuvioValueNode, LuvioFieldNode, LuvioVariableDefinitionNode, LuvioVariableNode, LuvioNamedTypeNode, LuvioListTypeNode, LuvioListValueNode, LuvioTypeNode } from './ast';
4
2
  import { LuvioGraphQLSchema } from './luvio-schema';
5
3
  export declare function parseAndVisit(source: string): LuvioDocumentNode;
6
4
  export declare function parseLuvioSchema(source: string, schemaName: string): LuvioGraphQLSchema;
7
5
  export { LuvioGraphQLSchema };
6
+ export type { GraphQLObjectType, GraphQLInterfaceType } from 'graphql/type';
7
+ export type { ListTypeNode, BooleanValueNode, EnumTypeDefinitionNode, FieldDefinitionNode, FloatValueNode, InterfaceTypeDefinitionNode, IntValueNode, NamedTypeNode, ObjectTypeDefinitionNode, StringValueNode, TypeNode, UnionTypeDefinitionNode, } from 'graphql/language';
8
+ export { Kind } from 'graphql/language';
9
+ export { isScalarType } from 'graphql/type';
8
10
  /**
9
11
  * @deprecated - Schema-backed adapters will use standard graphql types re-exported from @luvio/graphql
10
12
  */
11
- export { isScalarType, BooleanValueNode, EnumTypeDefinitionNode, FieldDefinitionNode, FloatValueNode, InterfaceTypeDefinitionNode, IntValueNode, Kind, NamedTypeNode, ObjectTypeDefinitionNode, StringValueNode, TypeNode, UnionTypeDefinitionNode, LuvioDocumentNode, LuvioArgumentNode, LuvioDefinitionNode, LuvioObjectValueNode, LuvioOperationDefinitionNode, LuvioSelectionCustomFieldNode, LuvioSelectionNode, LuvioSelectionObjectFieldNode, LuvioSelectionScalarFieldNode, LuvioValueNode, LuvioFieldNode, LuvioVariableDefinitionNode, LuvioVariableNode, LuvioNamedTypeNode, LuvioListTypeNode, LuvioListValueNode, LuvioTypeNode, };
13
+ export { LuvioDocumentNode, LuvioArgumentNode, LuvioDefinitionNode, LuvioObjectValueNode, LuvioOperationDefinitionNode, LuvioSelectionCustomFieldNode, LuvioSelectionNode, LuvioSelectionObjectFieldNode, LuvioSelectionScalarFieldNode, LuvioValueNode, LuvioFieldNode, LuvioVariableDefinitionNode, LuvioVariableNode, LuvioNamedTypeNode, LuvioListTypeNode, LuvioListValueNode, LuvioTypeNode, };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@luvio/graphql-parser",
3
- "version": "0.81.0",
3
+ "version": "0.82.1",
4
4
  "description": "GraphQL parser for Luvio GraphQL adapter support",
5
5
  "main": "./dist/luvioGraphqlParser.js",
6
6
  "module": "./dist/luvioGraphqlParser.mjs",
@@ -1,18 +1,35 @@
1
- import type { GraphQLSchema } from 'graphql';
1
+ import type { GraphQLScalarType, GraphQLSchema } from 'graphql';
2
+ import { isScalarType } from 'graphql';
2
3
 
3
4
  interface LuvioGraphQLSchemaParams {
4
5
  schema: GraphQLSchema;
5
6
  schemaName: string;
6
7
  }
7
8
 
8
- export class LuvioGraphQLSchema {
9
+ export interface LuvioGraphQLSchema {
10
+ schema: Readonly<GraphQLSchema>;
11
+ schemaName: Readonly<string>;
12
+ customScalars: GraphQLScalarType[];
13
+ }
14
+
15
+ export class LuvioSchema implements LuvioGraphQLSchema {
9
16
  // INVARIANT - Do not mutate the source schema, or add special AST or schema syntax,
10
17
  // just store additional information alongside it. In this way - we can accept this extra data in basically any format (RAML, JSON, YML)
11
18
  schema: Readonly<GraphQLSchema>;
12
19
  schemaName: Readonly<string>;
20
+ customScalars: GraphQLScalarType[] = [];
13
21
 
14
22
  constructor(luvioSchemaParams: Readonly<LuvioGraphQLSchemaParams>) {
15
23
  this.schemaName = luvioSchemaParams.schemaName;
16
24
  this.schema = luvioSchemaParams.schema;
25
+ this.extractCustomScalars();
26
+ }
27
+
28
+ private extractCustomScalars() {
29
+ Object.values(this.schema.getTypeMap()).forEach((def) => {
30
+ if (isScalarType(def) && def.astNode !== undefined) {
31
+ this.customScalars.push(def);
32
+ }
33
+ });
17
34
  }
18
35
  }
package/src/main.ts CHANGED
@@ -1,19 +1,4 @@
1
- import {
2
- parse,
3
- BooleanValueNode,
4
- EnumTypeDefinitionNode,
5
- FieldDefinitionNode,
6
- FloatValueNode,
7
- InterfaceTypeDefinitionNode,
8
- IntValueNode,
9
- Kind,
10
- NamedTypeNode,
11
- ObjectTypeDefinitionNode,
12
- StringValueNode,
13
- TypeNode,
14
- UnionTypeDefinitionNode,
15
- } from 'graphql/language';
16
- import { isScalarType } from 'graphql/type';
1
+ import { parse } from 'graphql/language';
17
2
  import { buildASTSchema } from 'graphql/utilities';
18
3
  import {
19
4
  LuvioDocumentNode,
@@ -35,7 +20,7 @@ import {
35
20
  LuvioTypeNode,
36
21
  } from './ast';
37
22
  import { transform } from './document';
38
- import { LuvioGraphQLSchema } from './luvio-schema';
23
+ import { LuvioGraphQLSchema, LuvioSchema } from './luvio-schema';
39
24
 
40
25
  /*
41
26
  Deprecated - Remove after existing usages are removed.
@@ -47,7 +32,7 @@ export function parseAndVisit(source: string): LuvioDocumentNode {
47
32
 
48
33
  export function parseLuvioSchema(source: string, schemaName: string): LuvioGraphQLSchema {
49
34
  const schema = buildASTSchema(parse(source));
50
- return new LuvioGraphQLSchema({
35
+ return new LuvioSchema({
51
36
  schema,
52
37
  schemaName,
53
38
  });
@@ -55,23 +40,28 @@ export function parseLuvioSchema(source: string, schemaName: string): LuvioGraph
55
40
 
56
41
  export { LuvioGraphQLSchema };
57
42
 
58
- /**
59
- * @deprecated - Schema-backed adapters will use standard graphql types re-exported from @luvio/graphql
60
- */
61
- export {
62
- isScalarType,
43
+ export type { GraphQLObjectType, GraphQLInterfaceType } from 'graphql/type';
44
+ export type {
45
+ ListTypeNode,
63
46
  BooleanValueNode,
64
47
  EnumTypeDefinitionNode,
65
48
  FieldDefinitionNode,
66
49
  FloatValueNode,
67
50
  InterfaceTypeDefinitionNode,
68
51
  IntValueNode,
69
- Kind,
70
52
  NamedTypeNode,
71
53
  ObjectTypeDefinitionNode,
72
54
  StringValueNode,
73
55
  TypeNode,
74
56
  UnionTypeDefinitionNode,
57
+ } from 'graphql/language';
58
+ export { Kind } from 'graphql/language';
59
+ export { isScalarType } from 'graphql/type';
60
+
61
+ /**
62
+ * @deprecated - Schema-backed adapters will use standard graphql types re-exported from @luvio/graphql
63
+ */
64
+ export {
75
65
  LuvioDocumentNode,
76
66
  LuvioArgumentNode,
77
67
  LuvioDefinitionNode,