src/resolvers.js
function resolve_type_define(nextql, fieldValue, fieldDefine, fieldPath) {
	let fd = fieldDefine;
	// First phrase resolve fieldDefine is auto or function into final fieldDefine
	if (fd === 1) {
		if (isPrimitive(fieldValue)) {
			return "*";
		} else {
			fd = nextql.resolveType(fieldValue);
			nextql.afterResolveTypeHooks.forEach(
				hook => (fd = hook(fieldValue) || fd)
			);
		}
	}

	if (typeof fd == "function") {
		fd = fieldDefine(fieldValue);
	}

	// Second phrase resolve fieldDefine is explicit into fieldModel name;
	if (fd == undefined) {
		return new NextQLError(
			"Cannot resolve model: " + JSON.stringify(fieldDefine),
			{ path: fieldPath }
		);
	}

	// InlineModel
	if (fd.constructor && fd.constructor == Object) {
		return new InlineModel(fd);
	}

	// ScalarModel
	if (fd === "*") {
		return "*";
	}

	// NamedModel
	const model = nextql.model(fd);
	if (!model) {
		return new NextQLError("Model not found: " + fd, {
			path: fieldPath
		});
	}

	return model;
}
function resolve_type_define(nextql, fieldValue, fieldDefine, fieldPath) {
	let fd = fieldDefine;
	// First phrase resolve fieldDefine is auto or function into final fieldDefine
	if (fd === 1) {
		if (isPrimitive(fieldValue)) {
			return "*";
		} else {
			fd = nextql.resolveType(fieldValue);
			nextql.afterResolveTypeHooks.forEach(
				hook => (fd = hook(fieldValue) || fd)
			);
		}
	}

	if (typeof fd == "function") {
		fd = fieldDefine(fieldValue);
	}

	// Second phrase resolve fieldDefine is explicit into fieldModel name;
	if (fd == undefined) {
		return new NextQLError(
			"Cannot resolve model: " + JSON.stringify(fieldDefine),
			{ path: fieldPath }
		);
	}

	// InlineModel
	if (fd.constructor && fd.constructor == Object) {
		return new InlineModel(fd);
	}

	// ScalarModel
	if (fd === "*") {
		return "*";
	}

	// NamedModel
	const model = nextql.model(fd);
	if (!model) {
		return new NextQLError("Model not found: " + fd, {
			path: fieldPath
		});
	}

	return model;
}
function resolve_type_define ( nextql , fieldValue , fieldDefine , fieldPath ) { let fd = fieldDefine ; // First phrase resolve fieldDefine is auto or function into final fieldDefine if ( fd === 1 ) { if ( isPrimitive ( fieldValue ) ) { return "*" ; } else { fd = nextql . resolveType ( fieldValue ) ; nextql . afterResolveTypeHooks . forEach ( hook => ( fd = hook ( fieldValue ) || fd ) ) ; } } if ( typeof fd == "function" ) { fd = fieldDefine ( fieldValue ) ; } // Second phrase resolve fieldDefine is explicit into fieldModel name; if ( fd == undefined ) { return new NextQLError ( "Cannot resolve model: " + JSON . stringify ( fieldDefine ) , { path : fieldPath } ) ; } // InlineModel if ( fd . constructor && fd . constructor == Object ) { return new InlineModel ( fd ) ; } // ScalarModel if ( fd === "*" ) { return "*" ; } // NamedModel const model = nextql . model ( fd ) ; if ( ! model ) { return new NextQLError ( "Model not found: " + fd , { path : fieldPath } ) ; } return model ; }
Give field value and field define, resolve field model or error
field path provided for log
@param {*} nextql
@param {string} path
@param {*} value
@param {*} typeDef
@return {*} model
Give field value and field define resolve field model or error field path provided for log