UNPKG

@backland/schema

Version:

TypeScript schema declaration and validation library with static type inference

73 lines (71 loc) 2.49 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.lazyCreateGraphTypeInitPayload = lazyCreateGraphTypeInitPayload; var _CircularDeps = require("../CircularDeps"); var _ObjectType = require("../ObjectType"); var _MetaFieldField = require("../fields/MetaFieldField"); var _parseObjectDefinition = require("../parseObjectDefinition"); // used to lazy parse args to improve circular types usage function lazyCreateGraphTypeInitPayload(args, onLoad) { var payload; var id = undefined; var definitionInput; var idFromArgs; if (args.length === 2) { idFromArgs = id = args[0]; definitionInput = args[1]; } else { definitionInput = args[0]; } function initializer(self) { var _field$utils; if (payload) return payload; var def = typeof definitionInput === 'function' ? definitionInput(_CircularDeps.CircularDeps) : definitionInput; var field = (0, _parseObjectDefinition.parseObjectField)('temp', def, { returnInstance: true }); var objectType = _ObjectType.ObjectType.is(field === null || field === void 0 ? void 0 : (_field$utils = field.utils) === null || _field$utils === void 0 ? void 0 : _field$utils.object) ? field.utils.object : undefined; if (objectType) { if (id && objectType.id && objectType.id !== id) { field.utils.object = objectType.clone(function (el) { return el.objectType(id); }); } else if (id) { field.utils.object.identify(id); } } if (!id && objectType) { id = (0, _MetaFieldField.getObjectDefinitionId)(objectType.definition, true // make nullable, the error below about undefined name is more clear ); } if (id && !field.id) { field.id = id; } payload = { definition: field.asFinalFieldDef, definitionInput: definitionInput, field: field, // id can be from inner type, like an object type with id or defined in an argument of createType id: id, idFromArgs: idFromArgs, objectType: objectType }; if (id) { self.identify(id); } var res = onLoad === null || onLoad === void 0 ? void 0 : onLoad(payload); if (res !== undefined) { return res; } return payload; } return { // id can also be from inner type, like an object type with id definitionInput: definitionInput, idFromArgs: idFromArgs, initializer: initializer }; } //# sourceMappingURL=lazyCreateGraphTypeInitPayload.js.map