@luvio/graphql-parser 0.82.1 → 0.85.0
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/luvioGraphqlParser.js +501 -409
- package/dist/luvioGraphqlParser.mjs +496 -409
- package/dist/main.d.ts +6 -6
- package/package.json +1 -1
- package/src/__tests__/__snapshots__/schema.spec.ts.snap +2 -2
- package/src/main.ts +10 -12
- package/dist/luvio-schema.d.ts +0 -18
- package/src/luvio-schema.ts +0 -35
|
@@ -3839,71 +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
|
-
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); }
|
|
3843
|
-
/**
|
|
3844
|
-
* Safer version of `Array.from` that return `null` if value isn't convertible to array.
|
|
3845
|
-
* Also protects against Array-like objects without items.
|
|
3846
|
-
*
|
|
3847
|
-
* @example
|
|
3848
|
-
*
|
|
3849
|
-
* safeArrayFrom([ 1, 2, 3 ]) // [1, 2, 3]
|
|
3850
|
-
* safeArrayFrom('ABC') // null
|
|
3851
|
-
* safeArrayFrom({ length: 1 }) // null
|
|
3852
|
-
* safeArrayFrom({ length: 1, 0: 'Alpha' }) // ['Alpha']
|
|
3853
|
-
* safeArrayFrom({ key: 'value' }) // null
|
|
3854
|
-
* safeArrayFrom(new Map()) // []
|
|
3855
|
-
*
|
|
3856
|
-
*/
|
|
3857
|
-
|
|
3858
|
-
function safeArrayFrom(collection) {
|
|
3859
|
-
var mapFn = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : function (item) {
|
|
3860
|
-
return item;
|
|
3861
|
-
};
|
|
3862
|
-
|
|
3863
|
-
if (collection == null || _typeof(collection) !== 'object') {
|
|
3864
|
-
return null;
|
|
3865
|
-
}
|
|
3866
|
-
|
|
3867
|
-
if (Array.isArray(collection)) {
|
|
3868
|
-
return collection.map(mapFn);
|
|
3869
|
-
} // Is Iterable?
|
|
3870
|
-
|
|
3871
|
-
|
|
3872
|
-
var iteratorMethod = collection[SYMBOL_ITERATOR];
|
|
3873
|
-
|
|
3874
|
-
if (typeof iteratorMethod === 'function') {
|
|
3875
|
-
// $FlowFixMe[incompatible-use]
|
|
3876
|
-
var iterator = iteratorMethod.call(collection);
|
|
3877
|
-
var result = [];
|
|
3878
|
-
var step;
|
|
3879
|
-
|
|
3880
|
-
for (var i = 0; !(step = iterator.next()).done; ++i) {
|
|
3881
|
-
result.push(mapFn(step.value, i));
|
|
3882
|
-
}
|
|
3883
|
-
|
|
3884
|
-
return result;
|
|
3885
|
-
} // Is Array like?
|
|
3886
|
-
|
|
3887
|
-
|
|
3888
|
-
var length = collection.length;
|
|
3889
|
-
|
|
3890
|
-
if (typeof length === 'number' && length >= 0 && length % 1 === 0) {
|
|
3891
|
-
var _result = [];
|
|
3892
|
-
|
|
3893
|
-
for (var _i = 0; _i < length; ++_i) {
|
|
3894
|
-
if (!Object.prototype.hasOwnProperty.call(collection, _i)) {
|
|
3895
|
-
return null;
|
|
3896
|
-
}
|
|
3897
|
-
|
|
3898
|
-
_result.push(mapFn(collection[String(_i)], _i));
|
|
3899
|
-
}
|
|
3900
|
-
|
|
3901
|
-
return _result;
|
|
3902
|
-
}
|
|
3903
|
-
|
|
3904
|
-
return null;
|
|
3905
|
-
}
|
|
3906
|
-
|
|
3907
3842
|
/* eslint-disable no-redeclare */
|
|
3908
3843
|
// $FlowFixMe[name-already-bound]
|
|
3909
3844
|
var find = Array.prototype.find ? function (list, predicate) {
|
|
@@ -5424,6 +5359,71 @@ var isFinitePolyfill = Number.isFinite || function (value) {
|
|
|
5424
5359
|
|
|
5425
5360
|
var isFinite$1 = isFinitePolyfill;
|
|
5426
5361
|
|
|
5362
|
+
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); }
|
|
5363
|
+
/**
|
|
5364
|
+
* Safer version of `Array.from` that return `null` if value isn't convertible to array.
|
|
5365
|
+
* Also protects against Array-like objects without items.
|
|
5366
|
+
*
|
|
5367
|
+
* @example
|
|
5368
|
+
*
|
|
5369
|
+
* safeArrayFrom([ 1, 2, 3 ]) // [1, 2, 3]
|
|
5370
|
+
* safeArrayFrom('ABC') // null
|
|
5371
|
+
* safeArrayFrom({ length: 1 }) // null
|
|
5372
|
+
* safeArrayFrom({ length: 1, 0: 'Alpha' }) // ['Alpha']
|
|
5373
|
+
* safeArrayFrom({ key: 'value' }) // null
|
|
5374
|
+
* safeArrayFrom(new Map()) // []
|
|
5375
|
+
*
|
|
5376
|
+
*/
|
|
5377
|
+
|
|
5378
|
+
function safeArrayFrom(collection) {
|
|
5379
|
+
var mapFn = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : function (item) {
|
|
5380
|
+
return item;
|
|
5381
|
+
};
|
|
5382
|
+
|
|
5383
|
+
if (collection == null || _typeof(collection) !== 'object') {
|
|
5384
|
+
return null;
|
|
5385
|
+
}
|
|
5386
|
+
|
|
5387
|
+
if (Array.isArray(collection)) {
|
|
5388
|
+
return collection.map(mapFn);
|
|
5389
|
+
} // Is Iterable?
|
|
5390
|
+
|
|
5391
|
+
|
|
5392
|
+
var iteratorMethod = collection[SYMBOL_ITERATOR];
|
|
5393
|
+
|
|
5394
|
+
if (typeof iteratorMethod === 'function') {
|
|
5395
|
+
// $FlowFixMe[incompatible-use]
|
|
5396
|
+
var iterator = iteratorMethod.call(collection);
|
|
5397
|
+
var result = [];
|
|
5398
|
+
var step;
|
|
5399
|
+
|
|
5400
|
+
for (var i = 0; !(step = iterator.next()).done; ++i) {
|
|
5401
|
+
result.push(mapFn(step.value, i));
|
|
5402
|
+
}
|
|
5403
|
+
|
|
5404
|
+
return result;
|
|
5405
|
+
} // Is Array like?
|
|
5406
|
+
|
|
5407
|
+
|
|
5408
|
+
var length = collection.length;
|
|
5409
|
+
|
|
5410
|
+
if (typeof length === 'number' && length >= 0 && length % 1 === 0) {
|
|
5411
|
+
var _result = [];
|
|
5412
|
+
|
|
5413
|
+
for (var _i = 0; _i < length; ++_i) {
|
|
5414
|
+
if (!Object.prototype.hasOwnProperty.call(collection, _i)) {
|
|
5415
|
+
return null;
|
|
5416
|
+
}
|
|
5417
|
+
|
|
5418
|
+
_result.push(mapFn(collection[String(_i)], _i));
|
|
5419
|
+
}
|
|
5420
|
+
|
|
5421
|
+
return _result;
|
|
5422
|
+
}
|
|
5423
|
+
|
|
5424
|
+
return null;
|
|
5425
|
+
}
|
|
5426
|
+
|
|
5427
5427
|
/* eslint-disable no-redeclare */
|
|
5428
5428
|
// $FlowFixMe[name-already-bound] workaround for: https://github.com/facebook/flow/issues/4441
|
|
5429
5429
|
var isInteger = Number.isInteger || function (value) {
|
|
@@ -6942,321 +6942,54 @@ function typeFromAST(schema, typeNode) {
|
|
|
6942
6942
|
}
|
|
6943
6943
|
|
|
6944
6944
|
/**
|
|
6945
|
-
*
|
|
6946
|
-
*
|
|
6947
|
-
* A GraphQL type must be provided, which will be used to interpret different
|
|
6948
|
-
* GraphQL Value literals.
|
|
6949
|
-
*
|
|
6950
|
-
* Returns `undefined` when the value could not be validly coerced according to
|
|
6951
|
-
* the provided type.
|
|
6952
|
-
*
|
|
6953
|
-
* | GraphQL Value | JSON Value |
|
|
6954
|
-
* | -------------------- | ------------- |
|
|
6955
|
-
* | Input Object | Object |
|
|
6956
|
-
* | List | Array |
|
|
6957
|
-
* | Boolean | Boolean |
|
|
6958
|
-
* | String | String |
|
|
6959
|
-
* | Int / Float | Number |
|
|
6960
|
-
* | Enum Value | Mixed |
|
|
6961
|
-
* | NullValue | null |
|
|
6945
|
+
* Executable definitions
|
|
6962
6946
|
*
|
|
6947
|
+
* A GraphQL document is only valid for execution if all definitions are either
|
|
6948
|
+
* operation or fragment definitions.
|
|
6963
6949
|
*/
|
|
6950
|
+
function ExecutableDefinitionsRule(context) {
|
|
6951
|
+
return {
|
|
6952
|
+
Document: function Document(node) {
|
|
6953
|
+
for (var _i2 = 0, _node$definitions2 = node.definitions; _i2 < _node$definitions2.length; _i2++) {
|
|
6954
|
+
var definition = _node$definitions2[_i2];
|
|
6964
6955
|
|
|
6965
|
-
|
|
6966
|
-
|
|
6967
|
-
|
|
6968
|
-
|
|
6969
|
-
|
|
6970
|
-
}
|
|
6971
|
-
|
|
6972
|
-
if (valueNode.kind === Kind.VARIABLE) {
|
|
6973
|
-
var variableName = valueNode.name.value;
|
|
6974
|
-
|
|
6975
|
-
if (variables == null || variables[variableName] === undefined) {
|
|
6976
|
-
// No valid return value.
|
|
6977
|
-
return;
|
|
6978
|
-
}
|
|
6979
|
-
|
|
6980
|
-
var variableValue = variables[variableName];
|
|
6981
|
-
|
|
6982
|
-
if (variableValue === null && isNonNullType(type)) {
|
|
6983
|
-
return; // Invalid: intentionally return no value.
|
|
6984
|
-
} // Note: This does no further checking that this variable is correct.
|
|
6985
|
-
// This assumes that this query has been validated and the variable
|
|
6986
|
-
// usage here is of the correct type.
|
|
6987
|
-
|
|
6988
|
-
|
|
6989
|
-
return variableValue;
|
|
6990
|
-
}
|
|
6956
|
+
if (!isExecutableDefinitionNode(definition)) {
|
|
6957
|
+
var defName = definition.kind === Kind.SCHEMA_DEFINITION || definition.kind === Kind.SCHEMA_EXTENSION ? 'schema' : '"' + definition.name.value + '"';
|
|
6958
|
+
context.reportError(new GraphQLError("The ".concat(defName, " definition is not executable."), definition));
|
|
6959
|
+
}
|
|
6960
|
+
}
|
|
6991
6961
|
|
|
6992
|
-
|
|
6993
|
-
if (valueNode.kind === Kind.NULL) {
|
|
6994
|
-
return; // Invalid: intentionally return no value.
|
|
6962
|
+
return false;
|
|
6995
6963
|
}
|
|
6964
|
+
};
|
|
6965
|
+
}
|
|
6996
6966
|
|
|
6997
|
-
|
|
6998
|
-
|
|
6999
|
-
|
|
7000
|
-
|
|
7001
|
-
|
|
7002
|
-
|
|
7003
|
-
|
|
7004
|
-
|
|
7005
|
-
|
|
7006
|
-
|
|
7007
|
-
|
|
7008
|
-
if (valueNode.kind === Kind.LIST) {
|
|
7009
|
-
var coercedValues = [];
|
|
7010
|
-
|
|
7011
|
-
for (var _i2 = 0, _valueNode$values2 = valueNode.values; _i2 < _valueNode$values2.length; _i2++) {
|
|
7012
|
-
var itemNode = _valueNode$values2[_i2];
|
|
7013
|
-
|
|
7014
|
-
if (isMissingVariable(itemNode, variables)) {
|
|
7015
|
-
// If an array contains a missing variable, it is either coerced to
|
|
7016
|
-
// null or if the item type is non-null, it considered invalid.
|
|
7017
|
-
if (isNonNullType(itemType)) {
|
|
7018
|
-
return; // Invalid: intentionally return no value.
|
|
7019
|
-
}
|
|
6967
|
+
/**
|
|
6968
|
+
* Unique operation names
|
|
6969
|
+
*
|
|
6970
|
+
* A GraphQL document is only valid if all defined operations have unique names.
|
|
6971
|
+
*/
|
|
6972
|
+
function UniqueOperationNamesRule(context) {
|
|
6973
|
+
var knownOperationNames = Object.create(null);
|
|
6974
|
+
return {
|
|
6975
|
+
OperationDefinition: function OperationDefinition(node) {
|
|
6976
|
+
var operationName = node.name;
|
|
7020
6977
|
|
|
7021
|
-
|
|
6978
|
+
if (operationName) {
|
|
6979
|
+
if (knownOperationNames[operationName.value]) {
|
|
6980
|
+
context.reportError(new GraphQLError("There can be only one operation named \"".concat(operationName.value, "\"."), [knownOperationNames[operationName.value], operationName]));
|
|
7022
6981
|
} else {
|
|
7023
|
-
|
|
7024
|
-
|
|
7025
|
-
if (itemValue === undefined) {
|
|
7026
|
-
return; // Invalid: intentionally return no value.
|
|
7027
|
-
}
|
|
7028
|
-
|
|
7029
|
-
coercedValues.push(itemValue);
|
|
6982
|
+
knownOperationNames[operationName.value] = operationName;
|
|
7030
6983
|
}
|
|
7031
6984
|
}
|
|
7032
6985
|
|
|
7033
|
-
return
|
|
7034
|
-
}
|
|
7035
|
-
|
|
7036
|
-
|
|
7037
|
-
|
|
7038
|
-
if (coercedValue === undefined) {
|
|
7039
|
-
return; // Invalid: intentionally return no value.
|
|
6986
|
+
return false;
|
|
6987
|
+
},
|
|
6988
|
+
FragmentDefinition: function FragmentDefinition() {
|
|
6989
|
+
return false;
|
|
7040
6990
|
}
|
|
7041
|
-
|
|
7042
|
-
|
|
7043
|
-
}
|
|
7044
|
-
|
|
7045
|
-
if (isInputObjectType(type)) {
|
|
7046
|
-
if (valueNode.kind !== Kind.OBJECT) {
|
|
7047
|
-
return; // Invalid: intentionally return no value.
|
|
7048
|
-
}
|
|
7049
|
-
|
|
7050
|
-
var coercedObj = Object.create(null);
|
|
7051
|
-
var fieldNodes = keyMap(valueNode.fields, function (field) {
|
|
7052
|
-
return field.name.value;
|
|
7053
|
-
});
|
|
7054
|
-
|
|
7055
|
-
for (var _i4 = 0, _objectValues2 = objectValues$1(type.getFields()); _i4 < _objectValues2.length; _i4++) {
|
|
7056
|
-
var field = _objectValues2[_i4];
|
|
7057
|
-
var fieldNode = fieldNodes[field.name];
|
|
7058
|
-
|
|
7059
|
-
if (!fieldNode || isMissingVariable(fieldNode.value, variables)) {
|
|
7060
|
-
if (field.defaultValue !== undefined) {
|
|
7061
|
-
coercedObj[field.name] = field.defaultValue;
|
|
7062
|
-
} else if (isNonNullType(field.type)) {
|
|
7063
|
-
return; // Invalid: intentionally return no value.
|
|
7064
|
-
}
|
|
7065
|
-
|
|
7066
|
-
continue;
|
|
7067
|
-
}
|
|
7068
|
-
|
|
7069
|
-
var fieldValue = valueFromAST(fieldNode.value, field.type, variables);
|
|
7070
|
-
|
|
7071
|
-
if (fieldValue === undefined) {
|
|
7072
|
-
return; // Invalid: intentionally return no value.
|
|
7073
|
-
}
|
|
7074
|
-
|
|
7075
|
-
coercedObj[field.name] = fieldValue;
|
|
7076
|
-
}
|
|
7077
|
-
|
|
7078
|
-
return coercedObj;
|
|
7079
|
-
} // istanbul ignore else (See: 'https://github.com/graphql/graphql-js/issues/2618')
|
|
7080
|
-
|
|
7081
|
-
|
|
7082
|
-
if (isLeafType(type)) {
|
|
7083
|
-
// Scalars and Enums fulfill parsing a literal value via parseLiteral().
|
|
7084
|
-
// Invalid values represent a failure to parse correctly, in which case
|
|
7085
|
-
// no value is returned.
|
|
7086
|
-
var result;
|
|
7087
|
-
|
|
7088
|
-
try {
|
|
7089
|
-
result = type.parseLiteral(valueNode, variables);
|
|
7090
|
-
} catch (_error) {
|
|
7091
|
-
return; // Invalid: intentionally return no value.
|
|
7092
|
-
}
|
|
7093
|
-
|
|
7094
|
-
if (result === undefined) {
|
|
7095
|
-
return; // Invalid: intentionally return no value.
|
|
7096
|
-
}
|
|
7097
|
-
|
|
7098
|
-
return result;
|
|
7099
|
-
} // istanbul ignore next (Not reachable. All possible input types have been considered)
|
|
7100
|
-
|
|
7101
|
-
|
|
7102
|
-
invariant(0, 'Unexpected input type: ' + inspect(type));
|
|
7103
|
-
} // Returns true if the provided valueNode is a variable which is not defined
|
|
7104
|
-
// in the set of variables.
|
|
7105
|
-
|
|
7106
|
-
function isMissingVariable(valueNode, variables) {
|
|
7107
|
-
return valueNode.kind === Kind.VARIABLE && (variables == null || variables[valueNode.name.value] === undefined);
|
|
7108
|
-
}
|
|
7109
|
-
|
|
7110
|
-
/**
|
|
7111
|
-
* Prepares an object map of argument values given a list of argument
|
|
7112
|
-
* definitions and list of argument AST nodes.
|
|
7113
|
-
*
|
|
7114
|
-
* Note: The returned value is a plain Object with a prototype, since it is
|
|
7115
|
-
* exposed to user code. Care should be taken to not pull values from the
|
|
7116
|
-
* Object prototype.
|
|
7117
|
-
*
|
|
7118
|
-
* @internal
|
|
7119
|
-
*/
|
|
7120
|
-
|
|
7121
|
-
|
|
7122
|
-
function getArgumentValues(def, node, variableValues) {
|
|
7123
|
-
var _node$arguments;
|
|
7124
|
-
|
|
7125
|
-
var coercedValues = {}; // istanbul ignore next (See: 'https://github.com/graphql/graphql-js/issues/2203')
|
|
7126
|
-
|
|
7127
|
-
var argumentNodes = (_node$arguments = node.arguments) !== null && _node$arguments !== void 0 ? _node$arguments : [];
|
|
7128
|
-
var argNodeMap = keyMap(argumentNodes, function (arg) {
|
|
7129
|
-
return arg.name.value;
|
|
7130
|
-
});
|
|
7131
|
-
|
|
7132
|
-
for (var _i4 = 0, _def$args2 = def.args; _i4 < _def$args2.length; _i4++) {
|
|
7133
|
-
var argDef = _def$args2[_i4];
|
|
7134
|
-
var name = argDef.name;
|
|
7135
|
-
var argType = argDef.type;
|
|
7136
|
-
var argumentNode = argNodeMap[name];
|
|
7137
|
-
|
|
7138
|
-
if (!argumentNode) {
|
|
7139
|
-
if (argDef.defaultValue !== undefined) {
|
|
7140
|
-
coercedValues[name] = argDef.defaultValue;
|
|
7141
|
-
} else if (isNonNullType(argType)) {
|
|
7142
|
-
throw new GraphQLError("Argument \"".concat(name, "\" of required type \"").concat(inspect(argType), "\" ") + 'was not provided.', node);
|
|
7143
|
-
}
|
|
7144
|
-
|
|
7145
|
-
continue;
|
|
7146
|
-
}
|
|
7147
|
-
|
|
7148
|
-
var valueNode = argumentNode.value;
|
|
7149
|
-
var isNull = valueNode.kind === Kind.NULL;
|
|
7150
|
-
|
|
7151
|
-
if (valueNode.kind === Kind.VARIABLE) {
|
|
7152
|
-
var variableName = valueNode.name.value;
|
|
7153
|
-
|
|
7154
|
-
if (variableValues == null || !hasOwnProperty(variableValues, variableName)) {
|
|
7155
|
-
if (argDef.defaultValue !== undefined) {
|
|
7156
|
-
coercedValues[name] = argDef.defaultValue;
|
|
7157
|
-
} else if (isNonNullType(argType)) {
|
|
7158
|
-
throw new GraphQLError("Argument \"".concat(name, "\" of required type \"").concat(inspect(argType), "\" ") + "was provided the variable \"$".concat(variableName, "\" which was not provided a runtime value."), valueNode);
|
|
7159
|
-
}
|
|
7160
|
-
|
|
7161
|
-
continue;
|
|
7162
|
-
}
|
|
7163
|
-
|
|
7164
|
-
isNull = variableValues[variableName] == null;
|
|
7165
|
-
}
|
|
7166
|
-
|
|
7167
|
-
if (isNull && isNonNullType(argType)) {
|
|
7168
|
-
throw new GraphQLError("Argument \"".concat(name, "\" of non-null type \"").concat(inspect(argType), "\" ") + 'must not be null.', valueNode);
|
|
7169
|
-
}
|
|
7170
|
-
|
|
7171
|
-
var coercedValue = valueFromAST(valueNode, argType, variableValues);
|
|
7172
|
-
|
|
7173
|
-
if (coercedValue === undefined) {
|
|
7174
|
-
// Note: ValuesOfCorrectTypeRule validation should catch this before
|
|
7175
|
-
// execution. This is a runtime check to ensure execution does not
|
|
7176
|
-
// continue with an invalid argument value.
|
|
7177
|
-
throw new GraphQLError("Argument \"".concat(name, "\" has invalid value ").concat(print(valueNode), "."), valueNode);
|
|
7178
|
-
}
|
|
7179
|
-
|
|
7180
|
-
coercedValues[name] = coercedValue;
|
|
7181
|
-
}
|
|
7182
|
-
|
|
7183
|
-
return coercedValues;
|
|
7184
|
-
}
|
|
7185
|
-
/**
|
|
7186
|
-
* Prepares an object map of argument values given a directive definition
|
|
7187
|
-
* and a AST node which may contain directives. Optionally also accepts a map
|
|
7188
|
-
* of variable values.
|
|
7189
|
-
*
|
|
7190
|
-
* If the directive does not exist on the node, returns undefined.
|
|
7191
|
-
*
|
|
7192
|
-
* Note: The returned value is a plain Object with a prototype, since it is
|
|
7193
|
-
* exposed to user code. Care should be taken to not pull values from the
|
|
7194
|
-
* Object prototype.
|
|
7195
|
-
*/
|
|
7196
|
-
|
|
7197
|
-
function getDirectiveValues(directiveDef, node, variableValues) {
|
|
7198
|
-
var directiveNode = node.directives && find$1(node.directives, function (directive) {
|
|
7199
|
-
return directive.name.value === directiveDef.name;
|
|
7200
|
-
});
|
|
7201
|
-
|
|
7202
|
-
if (directiveNode) {
|
|
7203
|
-
return getArgumentValues(directiveDef, directiveNode, variableValues);
|
|
7204
|
-
}
|
|
7205
|
-
}
|
|
7206
|
-
|
|
7207
|
-
function hasOwnProperty(obj, prop) {
|
|
7208
|
-
return Object.prototype.hasOwnProperty.call(obj, prop);
|
|
7209
|
-
}
|
|
7210
|
-
|
|
7211
|
-
/**
|
|
7212
|
-
* Executable definitions
|
|
7213
|
-
*
|
|
7214
|
-
* A GraphQL document is only valid for execution if all definitions are either
|
|
7215
|
-
* operation or fragment definitions.
|
|
7216
|
-
*/
|
|
7217
|
-
function ExecutableDefinitionsRule(context) {
|
|
7218
|
-
return {
|
|
7219
|
-
Document: function Document(node) {
|
|
7220
|
-
for (var _i2 = 0, _node$definitions2 = node.definitions; _i2 < _node$definitions2.length; _i2++) {
|
|
7221
|
-
var definition = _node$definitions2[_i2];
|
|
7222
|
-
|
|
7223
|
-
if (!isExecutableDefinitionNode(definition)) {
|
|
7224
|
-
var defName = definition.kind === Kind.SCHEMA_DEFINITION || definition.kind === Kind.SCHEMA_EXTENSION ? 'schema' : '"' + definition.name.value + '"';
|
|
7225
|
-
context.reportError(new GraphQLError("The ".concat(defName, " definition is not executable."), definition));
|
|
7226
|
-
}
|
|
7227
|
-
}
|
|
7228
|
-
|
|
7229
|
-
return false;
|
|
7230
|
-
}
|
|
7231
|
-
};
|
|
7232
|
-
}
|
|
7233
|
-
|
|
7234
|
-
/**
|
|
7235
|
-
* Unique operation names
|
|
7236
|
-
*
|
|
7237
|
-
* A GraphQL document is only valid if all defined operations have unique names.
|
|
7238
|
-
*/
|
|
7239
|
-
function UniqueOperationNamesRule(context) {
|
|
7240
|
-
var knownOperationNames = Object.create(null);
|
|
7241
|
-
return {
|
|
7242
|
-
OperationDefinition: function OperationDefinition(node) {
|
|
7243
|
-
var operationName = node.name;
|
|
7244
|
-
|
|
7245
|
-
if (operationName) {
|
|
7246
|
-
if (knownOperationNames[operationName.value]) {
|
|
7247
|
-
context.reportError(new GraphQLError("There can be only one operation named \"".concat(operationName.value, "\"."), [knownOperationNames[operationName.value], operationName]));
|
|
7248
|
-
} else {
|
|
7249
|
-
knownOperationNames[operationName.value] = operationName;
|
|
7250
|
-
}
|
|
7251
|
-
}
|
|
7252
|
-
|
|
7253
|
-
return false;
|
|
7254
|
-
},
|
|
7255
|
-
FragmentDefinition: function FragmentDefinition() {
|
|
7256
|
-
return false;
|
|
7257
|
-
}
|
|
7258
|
-
};
|
|
7259
|
-
}
|
|
6991
|
+
};
|
|
6992
|
+
}
|
|
7260
6993
|
|
|
7261
6994
|
/**
|
|
7262
6995
|
* Lone anonymous operation
|
|
@@ -9550,27 +9283,294 @@ function assertValidSDL(documentAST) {
|
|
|
9550
9283
|
}
|
|
9551
9284
|
}
|
|
9552
9285
|
|
|
9553
|
-
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
|
|
9554
|
-
|
|
9555
|
-
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
|
|
9556
|
-
|
|
9557
|
-
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
9558
9286
|
/**
|
|
9559
|
-
*
|
|
9287
|
+
* Produces a JavaScript value given a GraphQL Value AST.
|
|
9288
|
+
*
|
|
9289
|
+
* A GraphQL type must be provided, which will be used to interpret different
|
|
9290
|
+
* GraphQL Value literals.
|
|
9291
|
+
*
|
|
9292
|
+
* Returns `undefined` when the value could not be validly coerced according to
|
|
9293
|
+
* the provided type.
|
|
9294
|
+
*
|
|
9295
|
+
* | GraphQL Value | JSON Value |
|
|
9296
|
+
* | -------------------- | ------------- |
|
|
9297
|
+
* | Input Object | Object |
|
|
9298
|
+
* | List | Array |
|
|
9299
|
+
* | Boolean | Boolean |
|
|
9300
|
+
* | String | String |
|
|
9301
|
+
* | Int / Float | Number |
|
|
9302
|
+
* | Enum Value | Mixed |
|
|
9303
|
+
* | NullValue | null |
|
|
9304
|
+
*
|
|
9560
9305
|
*/
|
|
9561
9306
|
|
|
9562
|
-
function
|
|
9563
|
-
|
|
9564
|
-
|
|
9565
|
-
|
|
9566
|
-
|
|
9567
|
-
|
|
9568
|
-
// have the same name. For example, a type named "skip".
|
|
9569
|
-
|
|
9570
|
-
var directiveDefs = [];
|
|
9571
|
-
var schemaDef; // Schema extensions are collected which may add additional operation types.
|
|
9307
|
+
function valueFromAST(valueNode, type, variables) {
|
|
9308
|
+
if (!valueNode) {
|
|
9309
|
+
// When there is no node, then there is also no value.
|
|
9310
|
+
// Importantly, this is different from returning the value null.
|
|
9311
|
+
return;
|
|
9312
|
+
}
|
|
9572
9313
|
|
|
9573
|
-
|
|
9314
|
+
if (valueNode.kind === Kind.VARIABLE) {
|
|
9315
|
+
var variableName = valueNode.name.value;
|
|
9316
|
+
|
|
9317
|
+
if (variables == null || variables[variableName] === undefined) {
|
|
9318
|
+
// No valid return value.
|
|
9319
|
+
return;
|
|
9320
|
+
}
|
|
9321
|
+
|
|
9322
|
+
var variableValue = variables[variableName];
|
|
9323
|
+
|
|
9324
|
+
if (variableValue === null && isNonNullType(type)) {
|
|
9325
|
+
return; // Invalid: intentionally return no value.
|
|
9326
|
+
} // Note: This does no further checking that this variable is correct.
|
|
9327
|
+
// This assumes that this query has been validated and the variable
|
|
9328
|
+
// usage here is of the correct type.
|
|
9329
|
+
|
|
9330
|
+
|
|
9331
|
+
return variableValue;
|
|
9332
|
+
}
|
|
9333
|
+
|
|
9334
|
+
if (isNonNullType(type)) {
|
|
9335
|
+
if (valueNode.kind === Kind.NULL) {
|
|
9336
|
+
return; // Invalid: intentionally return no value.
|
|
9337
|
+
}
|
|
9338
|
+
|
|
9339
|
+
return valueFromAST(valueNode, type.ofType, variables);
|
|
9340
|
+
}
|
|
9341
|
+
|
|
9342
|
+
if (valueNode.kind === Kind.NULL) {
|
|
9343
|
+
// This is explicitly returning the value null.
|
|
9344
|
+
return null;
|
|
9345
|
+
}
|
|
9346
|
+
|
|
9347
|
+
if (isListType(type)) {
|
|
9348
|
+
var itemType = type.ofType;
|
|
9349
|
+
|
|
9350
|
+
if (valueNode.kind === Kind.LIST) {
|
|
9351
|
+
var coercedValues = [];
|
|
9352
|
+
|
|
9353
|
+
for (var _i2 = 0, _valueNode$values2 = valueNode.values; _i2 < _valueNode$values2.length; _i2++) {
|
|
9354
|
+
var itemNode = _valueNode$values2[_i2];
|
|
9355
|
+
|
|
9356
|
+
if (isMissingVariable(itemNode, variables)) {
|
|
9357
|
+
// If an array contains a missing variable, it is either coerced to
|
|
9358
|
+
// null or if the item type is non-null, it considered invalid.
|
|
9359
|
+
if (isNonNullType(itemType)) {
|
|
9360
|
+
return; // Invalid: intentionally return no value.
|
|
9361
|
+
}
|
|
9362
|
+
|
|
9363
|
+
coercedValues.push(null);
|
|
9364
|
+
} else {
|
|
9365
|
+
var itemValue = valueFromAST(itemNode, itemType, variables);
|
|
9366
|
+
|
|
9367
|
+
if (itemValue === undefined) {
|
|
9368
|
+
return; // Invalid: intentionally return no value.
|
|
9369
|
+
}
|
|
9370
|
+
|
|
9371
|
+
coercedValues.push(itemValue);
|
|
9372
|
+
}
|
|
9373
|
+
}
|
|
9374
|
+
|
|
9375
|
+
return coercedValues;
|
|
9376
|
+
}
|
|
9377
|
+
|
|
9378
|
+
var coercedValue = valueFromAST(valueNode, itemType, variables);
|
|
9379
|
+
|
|
9380
|
+
if (coercedValue === undefined) {
|
|
9381
|
+
return; // Invalid: intentionally return no value.
|
|
9382
|
+
}
|
|
9383
|
+
|
|
9384
|
+
return [coercedValue];
|
|
9385
|
+
}
|
|
9386
|
+
|
|
9387
|
+
if (isInputObjectType(type)) {
|
|
9388
|
+
if (valueNode.kind !== Kind.OBJECT) {
|
|
9389
|
+
return; // Invalid: intentionally return no value.
|
|
9390
|
+
}
|
|
9391
|
+
|
|
9392
|
+
var coercedObj = Object.create(null);
|
|
9393
|
+
var fieldNodes = keyMap(valueNode.fields, function (field) {
|
|
9394
|
+
return field.name.value;
|
|
9395
|
+
});
|
|
9396
|
+
|
|
9397
|
+
for (var _i4 = 0, _objectValues2 = objectValues$1(type.getFields()); _i4 < _objectValues2.length; _i4++) {
|
|
9398
|
+
var field = _objectValues2[_i4];
|
|
9399
|
+
var fieldNode = fieldNodes[field.name];
|
|
9400
|
+
|
|
9401
|
+
if (!fieldNode || isMissingVariable(fieldNode.value, variables)) {
|
|
9402
|
+
if (field.defaultValue !== undefined) {
|
|
9403
|
+
coercedObj[field.name] = field.defaultValue;
|
|
9404
|
+
} else if (isNonNullType(field.type)) {
|
|
9405
|
+
return; // Invalid: intentionally return no value.
|
|
9406
|
+
}
|
|
9407
|
+
|
|
9408
|
+
continue;
|
|
9409
|
+
}
|
|
9410
|
+
|
|
9411
|
+
var fieldValue = valueFromAST(fieldNode.value, field.type, variables);
|
|
9412
|
+
|
|
9413
|
+
if (fieldValue === undefined) {
|
|
9414
|
+
return; // Invalid: intentionally return no value.
|
|
9415
|
+
}
|
|
9416
|
+
|
|
9417
|
+
coercedObj[field.name] = fieldValue;
|
|
9418
|
+
}
|
|
9419
|
+
|
|
9420
|
+
return coercedObj;
|
|
9421
|
+
} // istanbul ignore else (See: 'https://github.com/graphql/graphql-js/issues/2618')
|
|
9422
|
+
|
|
9423
|
+
|
|
9424
|
+
if (isLeafType(type)) {
|
|
9425
|
+
// Scalars and Enums fulfill parsing a literal value via parseLiteral().
|
|
9426
|
+
// Invalid values represent a failure to parse correctly, in which case
|
|
9427
|
+
// no value is returned.
|
|
9428
|
+
var result;
|
|
9429
|
+
|
|
9430
|
+
try {
|
|
9431
|
+
result = type.parseLiteral(valueNode, variables);
|
|
9432
|
+
} catch (_error) {
|
|
9433
|
+
return; // Invalid: intentionally return no value.
|
|
9434
|
+
}
|
|
9435
|
+
|
|
9436
|
+
if (result === undefined) {
|
|
9437
|
+
return; // Invalid: intentionally return no value.
|
|
9438
|
+
}
|
|
9439
|
+
|
|
9440
|
+
return result;
|
|
9441
|
+
} // istanbul ignore next (Not reachable. All possible input types have been considered)
|
|
9442
|
+
|
|
9443
|
+
|
|
9444
|
+
invariant(0, 'Unexpected input type: ' + inspect(type));
|
|
9445
|
+
} // Returns true if the provided valueNode is a variable which is not defined
|
|
9446
|
+
// in the set of variables.
|
|
9447
|
+
|
|
9448
|
+
function isMissingVariable(valueNode, variables) {
|
|
9449
|
+
return valueNode.kind === Kind.VARIABLE && (variables == null || variables[valueNode.name.value] === undefined);
|
|
9450
|
+
}
|
|
9451
|
+
|
|
9452
|
+
/**
|
|
9453
|
+
* Prepares an object map of argument values given a list of argument
|
|
9454
|
+
* definitions and list of argument AST nodes.
|
|
9455
|
+
*
|
|
9456
|
+
* Note: The returned value is a plain Object with a prototype, since it is
|
|
9457
|
+
* exposed to user code. Care should be taken to not pull values from the
|
|
9458
|
+
* Object prototype.
|
|
9459
|
+
*
|
|
9460
|
+
* @internal
|
|
9461
|
+
*/
|
|
9462
|
+
|
|
9463
|
+
|
|
9464
|
+
function getArgumentValues(def, node, variableValues) {
|
|
9465
|
+
var _node$arguments;
|
|
9466
|
+
|
|
9467
|
+
var coercedValues = {}; // istanbul ignore next (See: 'https://github.com/graphql/graphql-js/issues/2203')
|
|
9468
|
+
|
|
9469
|
+
var argumentNodes = (_node$arguments = node.arguments) !== null && _node$arguments !== void 0 ? _node$arguments : [];
|
|
9470
|
+
var argNodeMap = keyMap(argumentNodes, function (arg) {
|
|
9471
|
+
return arg.name.value;
|
|
9472
|
+
});
|
|
9473
|
+
|
|
9474
|
+
for (var _i4 = 0, _def$args2 = def.args; _i4 < _def$args2.length; _i4++) {
|
|
9475
|
+
var argDef = _def$args2[_i4];
|
|
9476
|
+
var name = argDef.name;
|
|
9477
|
+
var argType = argDef.type;
|
|
9478
|
+
var argumentNode = argNodeMap[name];
|
|
9479
|
+
|
|
9480
|
+
if (!argumentNode) {
|
|
9481
|
+
if (argDef.defaultValue !== undefined) {
|
|
9482
|
+
coercedValues[name] = argDef.defaultValue;
|
|
9483
|
+
} else if (isNonNullType(argType)) {
|
|
9484
|
+
throw new GraphQLError("Argument \"".concat(name, "\" of required type \"").concat(inspect(argType), "\" ") + 'was not provided.', node);
|
|
9485
|
+
}
|
|
9486
|
+
|
|
9487
|
+
continue;
|
|
9488
|
+
}
|
|
9489
|
+
|
|
9490
|
+
var valueNode = argumentNode.value;
|
|
9491
|
+
var isNull = valueNode.kind === Kind.NULL;
|
|
9492
|
+
|
|
9493
|
+
if (valueNode.kind === Kind.VARIABLE) {
|
|
9494
|
+
var variableName = valueNode.name.value;
|
|
9495
|
+
|
|
9496
|
+
if (variableValues == null || !hasOwnProperty(variableValues, variableName)) {
|
|
9497
|
+
if (argDef.defaultValue !== undefined) {
|
|
9498
|
+
coercedValues[name] = argDef.defaultValue;
|
|
9499
|
+
} else if (isNonNullType(argType)) {
|
|
9500
|
+
throw new GraphQLError("Argument \"".concat(name, "\" of required type \"").concat(inspect(argType), "\" ") + "was provided the variable \"$".concat(variableName, "\" which was not provided a runtime value."), valueNode);
|
|
9501
|
+
}
|
|
9502
|
+
|
|
9503
|
+
continue;
|
|
9504
|
+
}
|
|
9505
|
+
|
|
9506
|
+
isNull = variableValues[variableName] == null;
|
|
9507
|
+
}
|
|
9508
|
+
|
|
9509
|
+
if (isNull && isNonNullType(argType)) {
|
|
9510
|
+
throw new GraphQLError("Argument \"".concat(name, "\" of non-null type \"").concat(inspect(argType), "\" ") + 'must not be null.', valueNode);
|
|
9511
|
+
}
|
|
9512
|
+
|
|
9513
|
+
var coercedValue = valueFromAST(valueNode, argType, variableValues);
|
|
9514
|
+
|
|
9515
|
+
if (coercedValue === undefined) {
|
|
9516
|
+
// Note: ValuesOfCorrectTypeRule validation should catch this before
|
|
9517
|
+
// execution. This is a runtime check to ensure execution does not
|
|
9518
|
+
// continue with an invalid argument value.
|
|
9519
|
+
throw new GraphQLError("Argument \"".concat(name, "\" has invalid value ").concat(print(valueNode), "."), valueNode);
|
|
9520
|
+
}
|
|
9521
|
+
|
|
9522
|
+
coercedValues[name] = coercedValue;
|
|
9523
|
+
}
|
|
9524
|
+
|
|
9525
|
+
return coercedValues;
|
|
9526
|
+
}
|
|
9527
|
+
/**
|
|
9528
|
+
* Prepares an object map of argument values given a directive definition
|
|
9529
|
+
* and a AST node which may contain directives. Optionally also accepts a map
|
|
9530
|
+
* of variable values.
|
|
9531
|
+
*
|
|
9532
|
+
* If the directive does not exist on the node, returns undefined.
|
|
9533
|
+
*
|
|
9534
|
+
* Note: The returned value is a plain Object with a prototype, since it is
|
|
9535
|
+
* exposed to user code. Care should be taken to not pull values from the
|
|
9536
|
+
* Object prototype.
|
|
9537
|
+
*/
|
|
9538
|
+
|
|
9539
|
+
function getDirectiveValues(directiveDef, node, variableValues) {
|
|
9540
|
+
var directiveNode = node.directives && find$1(node.directives, function (directive) {
|
|
9541
|
+
return directive.name.value === directiveDef.name;
|
|
9542
|
+
});
|
|
9543
|
+
|
|
9544
|
+
if (directiveNode) {
|
|
9545
|
+
return getArgumentValues(directiveDef, directiveNode, variableValues);
|
|
9546
|
+
}
|
|
9547
|
+
}
|
|
9548
|
+
|
|
9549
|
+
function hasOwnProperty(obj, prop) {
|
|
9550
|
+
return Object.prototype.hasOwnProperty.call(obj, prop);
|
|
9551
|
+
}
|
|
9552
|
+
|
|
9553
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
|
|
9554
|
+
|
|
9555
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
|
|
9556
|
+
|
|
9557
|
+
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
9558
|
+
/**
|
|
9559
|
+
* @internal
|
|
9560
|
+
*/
|
|
9561
|
+
|
|
9562
|
+
function extendSchemaImpl(schemaConfig, documentAST, options) {
|
|
9563
|
+
var _schemaDef, _schemaDef$descriptio, _schemaDef2, _options$assumeValid;
|
|
9564
|
+
|
|
9565
|
+
// Collect the type definitions and extensions found in the document.
|
|
9566
|
+
var typeDefs = [];
|
|
9567
|
+
var typeExtensionsMap = Object.create(null); // New directives and types are separate because a directives and types can
|
|
9568
|
+
// have the same name. For example, a type named "skip".
|
|
9569
|
+
|
|
9570
|
+
var directiveDefs = [];
|
|
9571
|
+
var schemaDef; // Schema extensions are collected which may add additional operation types.
|
|
9572
|
+
|
|
9573
|
+
var schemaExtensions = [];
|
|
9574
9574
|
|
|
9575
9575
|
for (var _i2 = 0, _documentAST$definiti2 = documentAST.definitions; _i2 < _documentAST$definiti2.length; _i2++) {
|
|
9576
9576
|
var def = _documentAST$definiti2[_i2];
|
|
@@ -10265,6 +10265,116 @@ function buildASTSchema(documentAST, options) {
|
|
|
10265
10265
|
return new GraphQLSchema(config);
|
|
10266
10266
|
}
|
|
10267
10267
|
|
|
10268
|
+
/**
|
|
10269
|
+
* Strips characters that are not significant to the validity or execution
|
|
10270
|
+
* of a GraphQL document:
|
|
10271
|
+
* - UnicodeBOM
|
|
10272
|
+
* - WhiteSpace
|
|
10273
|
+
* - LineTerminator
|
|
10274
|
+
* - Comment
|
|
10275
|
+
* - Comma
|
|
10276
|
+
* - BlockString indentation
|
|
10277
|
+
*
|
|
10278
|
+
* Note: It is required to have a delimiter character between neighboring
|
|
10279
|
+
* non-punctuator tokens and this function always uses single space as delimiter.
|
|
10280
|
+
*
|
|
10281
|
+
* It is guaranteed that both input and output documents if parsed would result
|
|
10282
|
+
* in the exact same AST except for nodes location.
|
|
10283
|
+
*
|
|
10284
|
+
* Warning: It is guaranteed that this function will always produce stable results.
|
|
10285
|
+
* However, it's not guaranteed that it will stay the same between different
|
|
10286
|
+
* releases due to bugfixes or changes in the GraphQL specification.
|
|
10287
|
+
*
|
|
10288
|
+
* Query example:
|
|
10289
|
+
*
|
|
10290
|
+
* query SomeQuery($foo: String!, $bar: String) {
|
|
10291
|
+
* someField(foo: $foo, bar: $bar) {
|
|
10292
|
+
* a
|
|
10293
|
+
* b {
|
|
10294
|
+
* c
|
|
10295
|
+
* d
|
|
10296
|
+
* }
|
|
10297
|
+
* }
|
|
10298
|
+
* }
|
|
10299
|
+
*
|
|
10300
|
+
* Becomes:
|
|
10301
|
+
*
|
|
10302
|
+
* query SomeQuery($foo:String!$bar:String){someField(foo:$foo bar:$bar){a b{c d}}}
|
|
10303
|
+
*
|
|
10304
|
+
* SDL example:
|
|
10305
|
+
*
|
|
10306
|
+
* """
|
|
10307
|
+
* Type description
|
|
10308
|
+
* """
|
|
10309
|
+
* type Foo {
|
|
10310
|
+
* """
|
|
10311
|
+
* Field description
|
|
10312
|
+
* """
|
|
10313
|
+
* bar: String
|
|
10314
|
+
* }
|
|
10315
|
+
*
|
|
10316
|
+
* Becomes:
|
|
10317
|
+
*
|
|
10318
|
+
* """Type description""" type Foo{"""Field description""" bar:String}
|
|
10319
|
+
*/
|
|
10320
|
+
|
|
10321
|
+
function stripIgnoredCharacters(source) {
|
|
10322
|
+
var sourceObj = isSource(source) ? source : new Source(source);
|
|
10323
|
+
var body = sourceObj.body;
|
|
10324
|
+
var lexer = new Lexer(sourceObj);
|
|
10325
|
+
var strippedBody = '';
|
|
10326
|
+
var wasLastAddedTokenNonPunctuator = false;
|
|
10327
|
+
|
|
10328
|
+
while (lexer.advance().kind !== TokenKind.EOF) {
|
|
10329
|
+
var currentToken = lexer.token;
|
|
10330
|
+
var tokenKind = currentToken.kind;
|
|
10331
|
+
/**
|
|
10332
|
+
* Every two non-punctuator tokens should have space between them.
|
|
10333
|
+
* Also prevent case of non-punctuator token following by spread resulting
|
|
10334
|
+
* in invalid token (e.g. `1...` is invalid Float token).
|
|
10335
|
+
*/
|
|
10336
|
+
|
|
10337
|
+
var isNonPunctuator = !isPunctuatorTokenKind(currentToken.kind);
|
|
10338
|
+
|
|
10339
|
+
if (wasLastAddedTokenNonPunctuator) {
|
|
10340
|
+
if (isNonPunctuator || currentToken.kind === TokenKind.SPREAD) {
|
|
10341
|
+
strippedBody += ' ';
|
|
10342
|
+
}
|
|
10343
|
+
}
|
|
10344
|
+
|
|
10345
|
+
var tokenBody = body.slice(currentToken.start, currentToken.end);
|
|
10346
|
+
|
|
10347
|
+
if (tokenKind === TokenKind.BLOCK_STRING) {
|
|
10348
|
+
strippedBody += dedentBlockString(tokenBody);
|
|
10349
|
+
} else {
|
|
10350
|
+
strippedBody += tokenBody;
|
|
10351
|
+
}
|
|
10352
|
+
|
|
10353
|
+
wasLastAddedTokenNonPunctuator = isNonPunctuator;
|
|
10354
|
+
}
|
|
10355
|
+
|
|
10356
|
+
return strippedBody;
|
|
10357
|
+
}
|
|
10358
|
+
|
|
10359
|
+
function dedentBlockString(blockStr) {
|
|
10360
|
+
// skip leading and trailing triple quotations
|
|
10361
|
+
var rawStr = blockStr.slice(3, -3);
|
|
10362
|
+
var body = dedentBlockStringValue(rawStr);
|
|
10363
|
+
|
|
10364
|
+
if (getBlockStringIndentation(body) > 0) {
|
|
10365
|
+
body = '\n' + body;
|
|
10366
|
+
}
|
|
10367
|
+
|
|
10368
|
+
var lastChar = body[body.length - 1];
|
|
10369
|
+
var hasTrailingQuote = lastChar === '"' && body.slice(-4) !== '\\"""';
|
|
10370
|
+
|
|
10371
|
+
if (hasTrailingQuote || lastChar === '\\') {
|
|
10372
|
+
body += '\n';
|
|
10373
|
+
}
|
|
10374
|
+
|
|
10375
|
+
return '"""' + body + '"""';
|
|
10376
|
+
}
|
|
10377
|
+
|
|
10268
10378
|
/* Util Functions */
|
|
10269
10379
|
function isOperationDefinitionNode(input) {
|
|
10270
10380
|
return input.kind === 'OperationDefinition';
|
|
@@ -10686,35 +10796,12 @@ function transform(root) {
|
|
|
10686
10796
|
};
|
|
10687
10797
|
}
|
|
10688
10798
|
|
|
10689
|
-
class LuvioSchema {
|
|
10690
|
-
constructor(luvioSchemaParams) {
|
|
10691
|
-
this.customScalars = [];
|
|
10692
|
-
this.schemaName = luvioSchemaParams.schemaName;
|
|
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
|
-
});
|
|
10702
|
-
}
|
|
10703
|
-
}
|
|
10704
|
-
|
|
10705
10799
|
/*
|
|
10706
10800
|
Deprecated - Remove after existing usages are removed.
|
|
10707
10801
|
*/
|
|
10708
10802
|
function parseAndVisit(source) {
|
|
10709
10803
|
const ast = parse(source);
|
|
10710
10804
|
return transform(ast);
|
|
10711
|
-
}
|
|
10712
|
-
function parseLuvioSchema(source, schemaName) {
|
|
10713
|
-
const schema = buildASTSchema(parse(source));
|
|
10714
|
-
return new LuvioSchema({
|
|
10715
|
-
schema,
|
|
10716
|
-
schemaName,
|
|
10717
|
-
});
|
|
10718
10805
|
}
|
|
10719
10806
|
|
|
10720
|
-
export { Kind, isScalarType, parseAndVisit,
|
|
10807
|
+
export { GraphQLScalarType, GraphQLSchema, Kind, buildASTSchema, isScalarType, parse, parseAndVisit, print, stripIgnoredCharacters };
|