@graphql-mesh/transport-common
Version:
45 lines (41 loc) • 1.2 kB
JavaScript
import { getDocumentString } from '@envelop/core';
export { getDocumentString } from '@envelop/core';
import { memoize1 } from '@graphql-tools/utils';
import { GraphQLScalarType, valueFromASTUntyped, stripIgnoredCharacters, print } from 'graphql';
export { createDefaultExecutor } from '@graphql-tools/delegate';
const ObjMapScalar = new 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 valueFromASTUntyped(ast, variables);
}
});
const defaultPrintFn = memoize1(function defaultPrintFn2(document) {
return stripIgnoredCharacters(getDocumentString(document, print));
});
export { ObjMapScalar, defaultPrintFn };