3

我正在使用 aQueryRenderer在我的应用程序中填充编辑表单。数据还显示在整个页面的其他 DOM 元素中。然后,我通过突变将值保存回表单提交。一切都很好,除了我的用户界面没有反映事后的变化。这是我的初始查询:

    query EditPlanDialogQuery($planId: Int!) {
        planByPlanId(planId: $planId) {
            nodeId
            ...fields
        }
        allSchedules {
            nodes {
                ...fields
            }
        }            
    }

然后我的突变和包装函数定义如下:

    mutation EditPlanDialogMutation($input: UpdatePlanInput!) {
        updatePlan(input: $input) {
            plan {
                ...fields
            }
        }
    }

...

    editPlan = (values: any) => {
        const {
            nodeId,
            ...otherValues
        } = values;
        const variables = {
            input: {
                nodeId: nodeId,
                planPatch: { ...otherValues },
            },
        };
        commitMutation(
            environment,
            {
                mutation,
                variables,
                onCompleted: (response, errors) => alert(response),
                onError: err => alert(err),
            }
        );
    }

同样,数据被正确地保存到数据库中,但是显示数据的其他 DOM 元素未呈现以反映更改。我想简单的更新Relay处理这个?无论如何,根据他们的文档,情况应该如此。我试着弄乱updater回调,最终让页面更新,但它看起来很笨重。任何建议表示赞赏,谢谢!

4

1 回答 1

2

不知道你得到了什么领域,但我猜你没有从突变中得到 id 。您总是需要询问节点的 ID,因此中继可以匹配存储中更新的节点。并且节点的 id 必须命名为 id(不是 nodeId)

mutation EditPlanDialogMutation($input: UpdatePlanInput!) {
    updatePlan(input: $input) {
        plan {
            id
            ...fields
        }
    }
}
于 2018-05-04T19:35:26.823 回答