simple-graphql
Version:
The simple way to generates GraphQL schemas and Sequelize models from your models definition.
43 lines • 1.16 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const graphql_1 = require("graphql");
function astToJson(ast) {
if (ast.kind === graphql_1.Kind.INT) {
return parseInt(ast.value);
}
if (ast.kind === graphql_1.Kind.FLOAT) {
return parseFloat(ast.value);
}
if (ast.kind === graphql_1.Kind.STRING) {
return ast.value;
}
if (ast.kind === graphql_1.Kind.BOOLEAN) {
return ast.value === 'true' || ast.value === true;
}
if (ast.kind === graphql_1.Kind.LIST) {
return ast.values.map(astToJson);
}
if (ast.kind === graphql_1.Kind.ENUM) {
return ast.value;
}
if (ast.kind === graphql_1.Kind.OBJECT) {
const result = {};
ast.fields.forEach((field) => {
result[field.name.value] = astToJson(field.value);
});
return result;
}
}
exports.default = new graphql_1.GraphQLScalarType({
name: 'Json',
serialize(value) {
return value;
},
parseValue(value) {
return value;
},
parseLiteral(ast) {
return astToJson(ast);
}
});
//# sourceMappingURL=Json.js.map