You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
|
"use strict";
|
|
|
|
|
|
|
|
const node = require("../../ast-node");
|
|
|
|
|
|
|
|
const { validateArguments } = require("@validatem/core");
|
|
|
|
const required = require("@validatem/required");
|
|
|
|
const forbidRemoteFields = require("../../validators/forbid-remote-fields");
|
|
|
|
|
|
|
|
module.exports = function (operations) {
|
|
|
|
const isValueExpression = require("../../validators/operations/is-value-expression")(operations);
|
|
|
|
|
|
|
|
return function defaultTo(_value) {
|
|
|
|
let [ value ] = validateArguments(arguments, {
|
|
|
|
value: [ required, isValueExpression, forbidRemoteFields ] // FIXME: Forbid aggregrate functions?
|
|
|
|
});
|
|
|
|
|
|
|
|
return node({
|
|
|
|
type: "defaultTo",
|
|
|
|
value: value
|
|
|
|
});
|
|
|
|
};
|
|
|
|
};
|