UNPKG

@backland/schema

Version:

TypeScript schema declaration and validation library with static type inference

71 lines (69 loc) 2.38 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) { let payload; let id = undefined; let definitionInput; let 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; const def = typeof definitionInput === 'function' ? definitionInput(_CircularDeps.CircularDeps) : definitionInput; const field = (0, _parseObjectDefinition.parseObjectField)('temp', def, { returnInstance: true }); const 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(el => 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, field, // id can be from inner type, like an object type with id or defined in an argument of createType id, idFromArgs, objectType: objectType }; if (id) { self.identify(id); } const 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, idFromArgs, initializer }; } //# sourceMappingURL=lazyCreateGraphTypeInitPayload.js.map