@backland/schema
Version:
TypeScript schema declaration and validation library with static type inference
47 lines (46 loc) • 1.18 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.GraphQLPhoneType = void 0;
var _graphql = require("graphql");
var _PhoneField = require("../fields/PhoneField");
const validator = (ast, options) => {
const {
kind,
value
} = ast;
if (kind !== _graphql.Kind.STRING) {
throw new _graphql.GraphQLError(`Query error: Can only parse strings got a: ${kind}`, [ast]);
}
return (0, _PhoneField.validatePhoneNumber)(value, options);
};
class GraphQLPhoneType extends _graphql.GraphQLScalarType {
constructor(options = {}) {
const {
name = 'Phone',
description
} = options || {};
super({
description,
name,
parseLiteral: ast => validator(ast, options),
parseValue: value => {
const ast = {
kind: _graphql.Kind.STRING,
value
};
return validator(ast, options);
},
serialize: value => {
const ast = {
kind: _graphql.Kind.STRING,
value
};
return validator(ast, options);
}
});
}
}
exports.GraphQLPhoneType = GraphQLPhoneType;
//# sourceMappingURL=GraphQLPhoneType.js.map