|
|
|
@ -7,6 +7,7 @@ const Result = require("@joepie91/result");
|
|
|
|
|
const createCursor = require("./cursor");
|
|
|
|
|
const deepMergeAndMap = require("./deep-merge-and-map");
|
|
|
|
|
const loadModules = require("./load-modules");
|
|
|
|
|
const InvalidObject = require("./invalid-object");
|
|
|
|
|
|
|
|
|
|
// TODO: Bounded/unbounded recursion
|
|
|
|
|
// TODO: Should we allow async context generation? Both in root schema *and* in modules
|
|
|
|
@ -16,6 +17,8 @@ const loadModules = require("./load-modules");
|
|
|
|
|
// FIXME: Allow setting an evaluation depth limit for queries, to limit eg. recursion
|
|
|
|
|
// FIXME: recurseDepth, recurseLabel/recurseGoto
|
|
|
|
|
// TODO: Internal queries, but only in modules, and only as a last resort
|
|
|
|
|
// TODO: Throw a useful error when trying to $make a non-existent type
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Process design:
|
|
|
|
|
|
|
|
|
@ -170,7 +173,9 @@ function makeEnvironment(context, getContextForModule) {
|
|
|
|
|
let { cursor } = instruction;
|
|
|
|
|
|
|
|
|
|
if (Array.isArray(value)) {
|
|
|
|
|
return Promise.map(value, (item, i) => {
|
|
|
|
|
return Promise.filter(value, (object) => {
|
|
|
|
|
return (object !== InvalidObject);
|
|
|
|
|
}).map((item, i) => {
|
|
|
|
|
let itemCursor = cursor
|
|
|
|
|
.child(i, i)
|
|
|
|
|
.override({
|
|
|
|
@ -180,7 +185,7 @@ function makeEnvironment(context, getContextForModule) {
|
|
|
|
|
|
|
|
|
|
return applyRules(itemCursor);
|
|
|
|
|
});
|
|
|
|
|
} else {
|
|
|
|
|
} else if (value !== InvalidObject) {
|
|
|
|
|
let itemCursor = cursor
|
|
|
|
|
.override({
|
|
|
|
|
query: query,
|
|
|
|
@ -188,6 +193,8 @@ function makeEnvironment(context, getContextForModule) {
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return applyRules(itemCursor);
|
|
|
|
|
} else {
|
|
|
|
|
return undefined;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -285,7 +292,7 @@ module.exports = function createDLayer(options) {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function make(typeID, args, existenceRequired) {
|
|
|
|
|
async function make(typeID, args, existenceRequired) {
|
|
|
|
|
let type = loaded.types[typeID].func;
|
|
|
|
|
|
|
|
|
|
if (type == null) {
|
|
|
|
@ -295,9 +302,9 @@ module.exports = function createDLayer(options) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
let instance = type(args);
|
|
|
|
|
let instance = await type(args);
|
|
|
|
|
|
|
|
|
|
if (loaded.extensions[typeID] != null) {
|
|
|
|
|
if (loaded.extensions[typeID] != null && instance !== InvalidObject) {
|
|
|
|
|
for (let [ key, extension ] of Object.entries(loaded.extensions[typeID])) {
|
|
|
|
|
// TODO: Possibly make this more performant by making it possible to do an Object.assign? Or does that not matter for performance?
|
|
|
|
|
instance[key] = extension.func;
|
|
|
|
@ -328,4 +335,4 @@ module.exports.markAcceptableError = function (error) {
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
module.exports.InvalidObject = InvalidObject;
|
|
|
|
|