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.
32 lines
1.0 KiB
JavaScript
32 lines
1.0 KiB
JavaScript
"use strict";
|
|
|
|
const { validateArguments } = require("@validatem/core");
|
|
const required = require("@validatem/required");
|
|
const arrayOf = require("@validatem/array-of");
|
|
const either = require("@validatem/either");
|
|
|
|
const node = require("../../ast-node");
|
|
|
|
module.exports = function (operations) {
|
|
const isObjectType = require("../../validators/operations/is-object-type")(operations);
|
|
const isPossiblyRemoteField = require("../../validators/operations/is-possibly-remote-field")(operations);
|
|
const wrapWithOperation = require("../../validators/operations/wrap-with-operation")(operations);
|
|
|
|
return function through(_relations) {
|
|
let [ relations ] = validateArguments(arguments, {
|
|
relations: [ required, arrayOf(either([
|
|
[ isObjectType("relation") ],
|
|
[ isPossiblyRemoteField, either([
|
|
[ isObjectType("field"), wrapWithOperation("belongsTo") ],
|
|
[ isObjectType("remoteField"), wrapWithOperation("has") ],
|
|
])]
|
|
]))]
|
|
});
|
|
|
|
return node({
|
|
type: "throughRelations",
|
|
relations: relations
|
|
});
|
|
};
|
|
};
|