如果字段为空,则为apollo-client网络错误

时间:2018-05-03 10:59:42

标签: graphql apollo-client

这个特殊的代码现在已经运行了好几个月,今天早上没有任何相关的变化,我可以在我们的设置或我开始接收的代码中查明

ERROR Error: Uncaught (in promise): Error: Network error: Cannot convert undefined or null to object Error: Network error: Cannot convert undefined or null to object
    at new ApolloError (ApolloError.js:43)
    at eval (QueryManager.js:324)
    at eval (QueryManager.js:755)
    at Array.forEach (<anonymous>)
    at eval (QueryManager.js:754)
    at Map.forEach (<anonymous>)
    at QueryManager.broadcastQueries (QueryManager.js:749)
    at eval (QueryManager.js:251)
    at ZoneDelegate.invoke (zone.js:388)
    at Object.onInvoke (core.js:4733)
    at new ApolloError (ApolloError.js:43)
    at eval (QueryManager.js:324)
    at eval (QueryManager.js:755)
    at Array.forEach (<anonymous>)
    ...
    inline.bundle.js:26 (anonymous) @ main.bundle.js:1

这是因为Object.keys(src).forEach:

的错误
var hasOwn = Object.prototype.hasOwnProperty;
export function merge(dest, src) {
    Object.keys(src).forEach(function (key) {
        var srcVal = src[key];
        if (!hasOwn.call(dest, key)) {
            dest[key] = srcVal;
        }
        else if (srcVal && typeof srcVal === 'object') {
            merge(dest[key], srcVal);
        }
    });
}

错误是:

"Cannot convert undefined or null to object"
从这里调用

merge:

function executeSelectionSet(selectionSet, rootValue, execContext) {
    var fragmentMap = execContext.fragmentMap, contextValue = execContext.contextValue, variables = execContext.variableValues;
    var result = {};
    selectionSet.selections.forEach(function (selection) {
        if (!shouldInclude(selection, variables)) {
            // Skip this entirely
            return;
        }
        if (isField(selection)) {
            var fieldResult = executeField(selection, rootValue, execContext);
            var resultFieldKey = resultKeyNameFromField(selection);
            if (fieldResult !== undefined) {
                if (result[resultFieldKey] === undefined) {
                    result[resultFieldKey] = fieldResult;
                }
                else {
                    merge(result[resultFieldKey], fieldResult);
                }
            }
        }
        else {
            var fragment = void 0;
            if (isInlineFragment(selection)) {
                fragment = selection;
            }
            else {
                // This is a named fragment
                fragment = fragmentMap[selection.name.value];
                if (!fragment) {
                    throw new Error("No fragment named " + selection.name.value);
                }
            }
            var typeCondition = fragment.typeCondition.name.value;
            if (execContext.fragmentMatcher(rootValue, typeCondition, contextValue)) {
                var fragmentResult = executeSelectionSet(fragment.selectionSet, rootValue, execContext);
                merge(result, fragmentResult);
            }
        }
    });
    if (execContext.resultMapper) {
        return execContext.resultMapper(result, rootValue);
    }
    return result;
}

在我确定了正在解析的字段以及它在后端中为空值的事实后,我尝试更改该值,然后将错误移动到同一节点的下一个空值字段。我也试过了其他查询,我们得到了相同的结果。

我们在后端使用django和graphene,在前端使用apollo-client。

我将非常感激这里的任何见解,我仍然想知道昨天23:00(我最近测试现在正在轰炸的代码并且一切都工作的时间)和今晚凌晨1点(自动化的时间)之间发生了什么变化在我们的开发服务器上部署。)

1 个答案:

答案 0 :(得分:1)

昨晚我收到了类似的错误,对于我来说,我能够跟踪graphql-anywhere软件包从版本4.1.8到4.1.9(2天前更新)的更改。

以下是更改日志:https://github.com/apollographql/apollo-client/blob/master/packages/graphql-anywhere/CHANGELOG.md

NDActionSineMoveBy* NDActionSineMoveBy::create(float duration, float sines, float sineSize, const Vec2& deltaPosition) { NDActionSineMoveBy *ret = new (std::nothrow) NDActionSineMoveBy(); if (ret && ret->initWithDuration(duration, sines, sineSize, deltaPosition)) { ret->autorelease(); return ret; } delete ret; return nullptr; } bool NDActionSineMoveBy::initWithDuration(float duration, float sines, float sineSize, const Vec2& deltaPosition) { bool ret = false; if (ActionInterval::initWithDuration(duration)) { _sines = sines; _sineSize = sineSize; _positionDelta = deltaPosition; _baseAngle = atan2f(_positionDelta.y, _positionDelta.x); _currentAngle = _sines * (M_PI * 2); ret = true; } return ret; } NDActionSineMoveBy* NDActionSineMoveBy::clone() const { // no copy constructor return NDActionSineMoveBy::create(_duration, _sines, _sineSize, _positionDelta); } void NDActionSineMoveBy::startWithTarget(Node *target) { ActionInterval::startWithTarget(target); _previousPosition = _startPosition = target->getPosition(); _distance = _positionDelta.length(); } NDActionSineMoveBy* NDActionSineMoveBy::reverse() const { return NDActionSineMoveBy::create(_duration, _sines, _sineSize, -_positionDelta); } void NDActionSineMoveBy::update(float t) { if (_target) { Vec2 newPos; newPos.x = _distance * t; newPos.y = sin(_currentAngle * t) * _sineSize; newPos = rotate(newPos, _baseAngle, Vec2::ZERO); #if CC_ENABLE_STACKABLE_ACTIONS Vec2 currentPos = _target->getPosition(); Vec2 diff = currentPos - _previousPosition; _startPosition = _startPosition + diff; newPos += _startPosition; _target->setPosition(newPos); _previousPosition = newPos; #else newPos += _startPosition; _target->setPosition(newPos); #endif // CC_ENABLE_STACKABLE_ACTIONS } } Vec2 NDActionSineMoveBy::rotate(const Vec2& point, float angle, const Vec2& anchor) { Vec2 res; res.x = cos(angle) * (point.x - anchor.x) - sin(angle) * (point.y - anchor.y) + anchor.x; res.y = sin(angle) * (point.x - anchor.x) + cos(angle) * (point.y - anchor.y) + anchor.y; return res; }; 添加到我的package.json文件已解决了我的应用程序的问题。

相关问题