@graphql-mesh/transport-common
Version:
55 lines (50 loc) • 1.42 kB
JavaScript
;
var core = require('@envelop/core');
var utils = require('@graphql-tools/utils');
var graphql = require('graphql');
var delegate = require('@graphql-tools/delegate');
const ObjMapScalar = new graphql.GraphQLScalarType({
name: "ObjMap",
serialize: (value) => {
if (typeof value === "string") {
return value;
}
const stringifiedValue = JSON.stringify(value);
return stringifiedValue;
},
parseValue: (value) => {
if (value == null) {
return null;
}
if (typeof value === "object") {
return value;
}
try {
return JSON.parse(value.toString());
} catch (e) {
return value;
}
},
parseLiteral: (ast, variables) => {
if (ast.kind === "StringValue") {
try {
return JSON.parse(ast.value);
} catch (e) {
}
}
return graphql.valueFromASTUntyped(ast, variables);
}
});
const defaultPrintFn = utils.memoize1(function defaultPrintFn2(document) {
return graphql.stripIgnoredCharacters(core.getDocumentString(document, graphql.print));
});
Object.defineProperty(exports, "getDocumentString", {
enumerable: true,
get: function () { return core.getDocumentString; }
});
Object.defineProperty(exports, "createDefaultExecutor", {
enumerable: true,
get: function () { return delegate.createDefaultExecutor; }
});
exports.ObjMapScalar = ObjMapScalar;
exports.defaultPrintFn = defaultPrintFn;