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
4 years ago
|
"use strict";
|
||
|
|
||
|
const { validateArguments } = require("@validatem/core");
|
||
|
const required = require("@validatem/required");
|
||
|
const either = require("@validatem/either");
|
||
|
|
||
|
const isRemoteFieldName = require("../validators/is-remote-field-name");
|
||
|
const isLocalFieldName = require("../validators/is-local-field-name");
|
||
|
const isCollectionName = require("../validators/is-collection-name");
|
||
|
const node = require("../ast-node");
|
||
|
|
||
|
module.exports = function (_operations) {
|
||
|
return function remoteField(_descriptor) {
|
||
|
let [ descriptor ] = validateArguments(arguments, {
|
||
|
descriptor: [ required, either([
|
||
|
[ isRemoteFieldName ], // NOTE: This returns a parsed version of the name
|
||
|
// FIXME: Instruct users to use the below format specifically when dynamically specifying a remote field, rather than string-concatenating
|
||
|
[{
|
||
|
collection: [ required, isCollectionName ],
|
||
|
field: [ required, isLocalFieldName ]
|
||
|
}]
|
||
|
])]
|
||
|
});
|
||
|
|
||
|
return node({
|
||
|
type: "remoteField",
|
||
|
collectionName: descriptor.collection,
|
||
|
fieldName: descriptor.field
|
||
|
});
|
||
|
};
|
||
|
};
|