gql_doc_eval(agooErr err, gqlDoc doc) {
    gqlValue	result;

    if (NULL == doc->op) {
	agoo_err_set(err, AGOO_ERR_EVAL, "Failed to identify operation in doc.");
	return NULL;
    }
    if (NULL != (result = gql_object_create(err))) {
	const char	*key;
	gqlField	field = NULL;
	struct _gqlSel	sel;

	memset(&sel, 0, sizeof(sel));
	doc->funcs.resolve = gql_resolve_func;
	doc->funcs.type = gql_type_func;

	switch (doc->op->kind) {
	case GQL_QUERY:
	    key = "query";
	    break;
	case GQL_MUTATION:
	    key = "mutation";
	    break;
	case GQL_SUBSCRIPTION:
	    key = "subscription";
	    break;
	default:
	    agoo_err_set(err, AGOO_ERR_EVAL, "Not a valid operation on the root object.");
	    gql_value_destroy(result);
	    return NULL;
	    break;
	}
	if (NULL == _gql_root_type && NULL != gql_type_func) {
	    _gql_root_type = gql_type_func(gql_root);
	}
	if (NULL != _gql_root_type) {
	    field = gql_type_get_field(_gql_root_type, key);
	}
	if (NULL == field) {
	    agoo_err_set(err, AGOO_ERR_EVAL, "GraphQL not initialized.");
	    gql_value_destroy(result);
	    return NULL;
	}
	sel.name = key;
	sel.type = _gql_root_type;
	sel.dir = doc->op->dir;
	sel.sels = doc->op->sels;
	if (AGOO_ERR_OK != doc->funcs.resolve(err, doc, gql_root, field, &sel, result, 0)) {
	    gql_value_destroy(result);
	    return NULL;
	}
    }
    return result;
}
gql_doc_eval(agooErr err, gqlDoc doc) {
    gqlValue	result;

    if (NULL == doc->op) {
	agoo_err_set(err, AGOO_ERR_EVAL, "Failed to identify operation in doc.");
	return NULL;
    }
    if (NULL != (result = gql_object_create(err))) {
	const char	*key;
	gqlField	field = NULL;
	struct _gqlSel	sel;

	memset(&sel, 0, sizeof(sel));
	doc->funcs.resolve = gql_resolve_func;
	doc->funcs.type = gql_type_func;

	switch (doc->op->kind) {
	case GQL_QUERY:
	    key = "query";
	    break;
	case GQL_MUTATION:
	    key = "mutation";
	    break;
	case GQL_SUBSCRIPTION:
	    key = "subscription";
	    break;
	default:
	    agoo_err_set(err, AGOO_ERR_EVAL, "Not a valid operation on the root object.");
	    gql_value_destroy(result);
	    return NULL;
	    break;
	}
	if (NULL == _gql_root_type && NULL != gql_type_func) {
	    _gql_root_type = gql_type_func(gql_root);
	}
	if (NULL != _gql_root_type) {
	    field = gql_type_get_field(_gql_root_type, key);
	}
	if (NULL == field) {
	    agoo_err_set(err, AGOO_ERR_EVAL, "GraphQL not initialized.");
	    gql_value_destroy(result);
	    return NULL;
	}
	sel.name = key;
	sel.type = _gql_root_type;
	sel.dir = doc->op->dir;
	sel.sels = doc->op->sels;
	if (AGOO_ERR_OK != doc->funcs.resolve(err, doc, gql_root, field, &sel, result, 0)) {
	    gql_value_destroy(result);
	    return NULL;
	}
    }
    return result;
}