graphql-paper
Version:
A flexible in-memory store based on a GraphQL Schema
24 lines (22 loc) • 695 B
JavaScript
;
var graphql = require('graphql');
var fieldReturnTypeMismatch = require('../errors/field-return-type-mismatch.js');
const scalarFieldValidator = {
skipConnectionValue: false,
skipNullValue: true,
validate({
field,
fieldValue
}) {
const jsScalars = ['boolean', 'number', 'string', 'float'];
if (graphql.isScalarType(field.type) && !jsScalars.includes(typeof fieldValue)) {
throw new fieldReturnTypeMismatch.FieldReturnTypeMismatch({
field: field,
expected: 'boolean, number, string',
actual: typeof fieldValue
});
}
}
};
exports.scalarFieldValidator = scalarFieldValidator;
//# sourceMappingURL=scalar-field.js.map