graphql-compose
Version:
GraphQL schema builder from different data sources with middleware extensions.
23 lines (19 loc) • 624 B
JavaScript
import { GraphQLScalarType, GraphQLError } from 'graphql';
import { Kind } from 'graphql/language';
function coerceDate(value) {
var json = JSON.stringify(value);
return json.replace(/"/g, '\'');
}
var GenericType = new GraphQLScalarType({
name: 'Generic',
serialize: coerceDate,
parseValue: coerceDate,
parseLiteral: function parseLiteral(ast) {
if (ast.kind !== Kind.STRING) {
throw new GraphQLError('Query error: Can only parse strings to buffers but got a: ' + ast.kind, [ast]);
}
var json = ast.value.replace(/'/g, '"');
return JSON.parse(json);
}
});
export default GenericType;