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.
30 lines
1.4 KiB
JavaScript
30 lines
1.4 KiB
JavaScript
4 years ago
|
"use strict";
|
||
|
|
||
|
const { validateArguments } = require("@validatem/core");
|
||
|
const required = require("@validatem/required");
|
||
|
const anyProperty = require("@validatem/any-property");
|
||
|
|
||
|
const node = require("../../ast-node");
|
||
|
const isLocalFieldName = require("../../validators/is-local-field-name");
|
||
|
|
||
|
// NOTE: `withRelations` structurally functions like a `compute`, except the computation value is a has/belongsTo relation specifier, which gets resolved at query time
|
||
|
// FIXME: Actually implement relation fetching logic. Start by generating relational queries after retrieving the initial data, eventually change this to pre-compute most of the relational queries and leave placeholders for table/column/etc. names. Implement the query generation as a stand-alone "generate relational query" function that takes in the current DB schema + relational specifier (+ clauses).
|
||
|
|
||
|
module.exports = function (operations) {
|
||
|
const isObjectType = require("../../validators/operations/is-object-type")(operations);
|
||
|
|
||
|
return function withRelations(_items) {
|
||
|
let [ items ] = validateArguments(arguments, {
|
||
|
items: [ required, anyProperty({
|
||
|
key: [ required, isLocalFieldName ], // FIXME: Support dot-path notation for nested relation specification? Or let this be handled by a relation's clauses?
|
||
|
value: [ required, isObjectType("relation") ]
|
||
|
})]
|
||
|
});
|
||
|
|
||
|
return node({
|
||
|
type: "withRelations",
|
||
|
items: items
|
||
|
});
|
||
|
};
|
||
|
};
|