@graphql-tools/utils 7.2.1 → 7.2.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/astFromValueUntyped.d.ts +17 -0
- package/es5/astFromValueUntyped.d.ts +17 -0
- package/es5/index.cjs.js +104 -16
- package/es5/index.cjs.js.map +1 -1
- package/es5/index.d.ts +1 -0
- package/es5/index.esm.js +104 -17
- package/es5/index.esm.js.map +1 -1
- package/es5/package.json +1 -1
- package/index.cjs.js +102 -15
- package/index.cjs.js.map +1 -1
- package/index.d.ts +1 -0
- package/index.esm.js +102 -16
- package/index.esm.js.map +1 -1
- package/package.json +1 -1
package/es5/index.d.ts
CHANGED
package/es5/index.esm.js
CHANGED
|
@@ -431,6 +431,80 @@ function astFromType(type) {
|
|
|
431
431
|
};
|
|
432
432
|
}
|
|
433
433
|
|
|
434
|
+
/**
|
|
435
|
+
* Produces a GraphQL Value AST given a JavaScript object.
|
|
436
|
+
* Function will match JavaScript/JSON values to GraphQL AST schema format
|
|
437
|
+
* by using the following mapping.
|
|
438
|
+
*
|
|
439
|
+
* | JSON Value | GraphQL Value |
|
|
440
|
+
* | ------------- | -------------------- |
|
|
441
|
+
* | Object | Input Object |
|
|
442
|
+
* | Array | List |
|
|
443
|
+
* | Boolean | Boolean |
|
|
444
|
+
* | String | String |
|
|
445
|
+
* | Number | Int / Float |
|
|
446
|
+
* | null | NullValue |
|
|
447
|
+
*
|
|
448
|
+
*/
|
|
449
|
+
function astFromValueUntyped(value) {
|
|
450
|
+
// only explicit null, not undefined, NaN
|
|
451
|
+
if (value === null) {
|
|
452
|
+
return { kind: Kind.NULL };
|
|
453
|
+
}
|
|
454
|
+
// undefined
|
|
455
|
+
if (value === undefined) {
|
|
456
|
+
return null;
|
|
457
|
+
}
|
|
458
|
+
// Convert JavaScript array to GraphQL list. If the GraphQLType is a list, but
|
|
459
|
+
// the value is not an array, convert the value using the list's item type.
|
|
460
|
+
if (Array.isArray(value)) {
|
|
461
|
+
var valuesNodes_1 = [];
|
|
462
|
+
value.forEach(function (item) {
|
|
463
|
+
var itemNode = astFromValueUntyped(item);
|
|
464
|
+
if (itemNode != null) {
|
|
465
|
+
valuesNodes_1.push(itemNode);
|
|
466
|
+
}
|
|
467
|
+
});
|
|
468
|
+
return { kind: Kind.LIST, values: valuesNodes_1 };
|
|
469
|
+
}
|
|
470
|
+
if (typeof value === 'object') {
|
|
471
|
+
var fieldNodes_1 = [];
|
|
472
|
+
Object.entries(value).forEach(function (_a) {
|
|
473
|
+
var _b = __read(_a, 2), fieldName = _b[0], fieldValue = _b[1];
|
|
474
|
+
var ast = astFromValueUntyped(fieldValue);
|
|
475
|
+
if (ast) {
|
|
476
|
+
fieldNodes_1.push({
|
|
477
|
+
kind: Kind.OBJECT_FIELD,
|
|
478
|
+
name: { kind: Kind.NAME, value: fieldName },
|
|
479
|
+
value: ast,
|
|
480
|
+
});
|
|
481
|
+
}
|
|
482
|
+
});
|
|
483
|
+
return { kind: Kind.OBJECT, fields: fieldNodes_1 };
|
|
484
|
+
}
|
|
485
|
+
// Others serialize based on their corresponding JavaScript scalar types.
|
|
486
|
+
if (typeof value === 'boolean') {
|
|
487
|
+
return { kind: Kind.BOOLEAN, value: value };
|
|
488
|
+
}
|
|
489
|
+
// JavaScript numbers can be Int or Float values.
|
|
490
|
+
if (typeof value === 'number' && isFinite(value)) {
|
|
491
|
+
var stringNum = String(value);
|
|
492
|
+
return integerStringRegExp.test(stringNum)
|
|
493
|
+
? { kind: Kind.INT, value: stringNum }
|
|
494
|
+
: { kind: Kind.FLOAT, value: stringNum };
|
|
495
|
+
}
|
|
496
|
+
if (typeof value === 'string') {
|
|
497
|
+
return { kind: Kind.STRING, value: value };
|
|
498
|
+
}
|
|
499
|
+
throw new TypeError("Cannot convert value to AST: " + value + ".");
|
|
500
|
+
}
|
|
501
|
+
/**
|
|
502
|
+
* IntValue:
|
|
503
|
+
* - NegativeSign? 0
|
|
504
|
+
* - NegativeSign? NonZeroDigit ( Digit+ )?
|
|
505
|
+
*/
|
|
506
|
+
var integerStringRegExp = /^-?(?:0|[1-9][0-9]*)$/;
|
|
507
|
+
|
|
434
508
|
// this approach uses the default schema printer rather than a custom solution, so may be more backwards compatible
|
|
435
509
|
// currently does not allow customization of printSchema options having to do with comments.
|
|
436
510
|
function printSchemaWithDirectives(schema, options) {
|
|
@@ -807,20 +881,35 @@ function makeDeprecatedDirective(deprecationReason) {
|
|
|
807
881
|
}
|
|
808
882
|
function makeDirective(name, args, directive) {
|
|
809
883
|
var directiveArguments = [];
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
884
|
+
if (directive != null) {
|
|
885
|
+
directive.args.forEach(function (arg) {
|
|
886
|
+
var argName = arg.name;
|
|
887
|
+
var argValue = args[argName];
|
|
888
|
+
if (argValue !== undefined) {
|
|
889
|
+
directiveArguments.push({
|
|
890
|
+
kind: Kind.ARGUMENT,
|
|
891
|
+
name: {
|
|
892
|
+
kind: Kind.NAME,
|
|
893
|
+
value: argName,
|
|
894
|
+
},
|
|
895
|
+
value: astFromValue(argValue, arg.type),
|
|
896
|
+
});
|
|
897
|
+
}
|
|
898
|
+
});
|
|
899
|
+
}
|
|
900
|
+
else {
|
|
901
|
+
Object.entries(args).forEach(function (_a) {
|
|
902
|
+
var _b = __read(_a, 2), argName = _b[0], argValue = _b[1];
|
|
814
903
|
directiveArguments.push({
|
|
815
904
|
kind: Kind.ARGUMENT,
|
|
816
905
|
name: {
|
|
817
906
|
kind: Kind.NAME,
|
|
818
907
|
value: argName,
|
|
819
908
|
},
|
|
820
|
-
value:
|
|
909
|
+
value: astFromValueUntyped(argValue),
|
|
821
910
|
});
|
|
822
|
-
}
|
|
823
|
-
}
|
|
911
|
+
});
|
|
912
|
+
}
|
|
824
913
|
return {
|
|
825
914
|
kind: Kind.DIRECTIVE,
|
|
826
915
|
name: {
|
|
@@ -835,15 +924,13 @@ function makeDirectives(schema, directiveValues) {
|
|
|
835
924
|
Object.entries(directiveValues).forEach(function (_a) {
|
|
836
925
|
var _b = __read(_a, 2), directiveName = _b[0], arrayOrSingleValue = _b[1];
|
|
837
926
|
var directive = schema.getDirective(directiveName);
|
|
838
|
-
if (
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
directiveNodes.push(makeDirective(directiveName, arrayOrSingleValue, directive));
|
|
846
|
-
}
|
|
927
|
+
if (Array.isArray(arrayOrSingleValue)) {
|
|
928
|
+
arrayOrSingleValue.forEach(function (value) {
|
|
929
|
+
directiveNodes.push(makeDirective(directiveName, value, directive));
|
|
930
|
+
});
|
|
931
|
+
}
|
|
932
|
+
else {
|
|
933
|
+
directiveNodes.push(makeDirective(directiveName, arrayOrSingleValue, directive));
|
|
847
934
|
}
|
|
848
935
|
});
|
|
849
936
|
return directiveNodes;
|
|
@@ -4209,5 +4296,5 @@ function isDocumentNode(object) {
|
|
|
4209
4296
|
return object.kind !== undefined;
|
|
4210
4297
|
}
|
|
4211
4298
|
|
|
4212
|
-
export { MapperKind, SchemaDirectiveVisitor, SchemaVisitor, VisitSchemaKind, addTypes, appendObjectFields, argsToFieldConfigArgumentMap, argumentToArgumentConfig, asArray, buildOperationNodeForField, checkValidationErrors, cloneDirective, cloneSchema, cloneType, collectFields, compareNodes, compareStrings, correctASTNodes, createNamedStub, createSchemaDefinition, createStub, debugLog, fieldToFieldConfig, filterSchema, fixSchemaAst, fixWindowsPath, flattenArray, forEachDefaultValue, forEachField, getArgumentValues, getBuiltInForStub, getDirectives, getDirectivesInExtensions, getFieldsWithDirectives, getImplementingTypes, getLeadingCommentBlock, getResolversFromSchema, getResponseKeyFromInfo, getUserTypesFromSchema, healSchema, healTypes, implementsAbstractType, inputFieldToFieldConfig, isAsyncIterable, isDescribable, isDocumentNode, isDocumentString, isEqual, isNamedStub, isNotEqual, isValidPath, mapAsyncIterator, mapSchema, mergeDeep, modifyObjectFields, nodeToString, observableToAsyncIterable, parseGraphQLJSON, parseGraphQLSDL, parseInputValue, parseInputValueLiteral, parseSelectionSet, printSchemaWithDirectives, pruneSchema, relocatedError, removeObjectFields, renameType, rewireTypes, selectObjectFields, serializeInputValue, transformCommentsToDescriptions, transformInputValue, updateArgument, validateGraphQlDocuments, valueMatchesCriteria, visitData, visitErrors, visitResult, visitSchema };
|
|
4299
|
+
export { MapperKind, SchemaDirectiveVisitor, SchemaVisitor, VisitSchemaKind, addTypes, appendObjectFields, argsToFieldConfigArgumentMap, argumentToArgumentConfig, asArray, astFromValueUntyped, buildOperationNodeForField, checkValidationErrors, cloneDirective, cloneSchema, cloneType, collectFields, compareNodes, compareStrings, correctASTNodes, createNamedStub, createSchemaDefinition, createStub, debugLog, fieldToFieldConfig, filterSchema, fixSchemaAst, fixWindowsPath, flattenArray, forEachDefaultValue, forEachField, getArgumentValues, getBuiltInForStub, getDirectives, getDirectivesInExtensions, getFieldsWithDirectives, getImplementingTypes, getLeadingCommentBlock, getResolversFromSchema, getResponseKeyFromInfo, getUserTypesFromSchema, healSchema, healTypes, implementsAbstractType, inputFieldToFieldConfig, isAsyncIterable, isDescribable, isDocumentNode, isDocumentString, isEqual, isNamedStub, isNotEqual, isValidPath, mapAsyncIterator, mapSchema, mergeDeep, modifyObjectFields, nodeToString, observableToAsyncIterable, parseGraphQLJSON, parseGraphQLSDL, parseInputValue, parseInputValueLiteral, parseSelectionSet, printSchemaWithDirectives, pruneSchema, relocatedError, removeObjectFields, renameType, rewireTypes, selectObjectFields, serializeInputValue, transformCommentsToDescriptions, transformInputValue, updateArgument, validateGraphQlDocuments, valueMatchesCriteria, visitData, visitErrors, visitResult, visitSchema };
|
|
4213
4300
|
//# sourceMappingURL=index.esm.js.map
|