【发布时间】:2018-08-02 12:30:28
【问题描述】:
我创建了一个带有以下架构的 graphQL 服务器:
...
#charts interface
interface Chart {
id: String!
sql: String!
title: String
type: String!
display: String!
}
type Layout{
# Unique layout id
id: String
# The title displayed on the layout tab
title: String
# List of displayed charts
charts: [Chart]
}
...
在我的客户端上,我有一个带有以下 gql 查询的 <SummaryLayout/> 组件:
gql`{
layout(id:"summary"){
title
charts {
id,
title,
type,
display
}
}}`
加载页面时,布局组件将所有图表显示为页面上的网格。用户稍后可以添加新图表,因此我有 2 个突变:一个创建图表,另一个是将新图表添加到布局中:
const addToLayout = gql`
mutation addToLayout($layoutID: String!, $chartID: String!) {
addToLayout(layoutID: $layoutID ,chartID:$chartID){
id
charts {
id
sql
title
type
display
}
}
}`;
const addChart = gql`
mutation addChart($chartConfig:ChartConfig!) {
addChart(chartConfig:$chartConfig){
id
display
}
}`;
this.props.addChart({
variables: {chartConfig: chartConfig}
}).then((response) => {
const chartID = response.data.addChart.id;
console.log("Chart added, DB ID:", chartID);
this.props.addToLayout({
variables: {layoutID: "summary", chartID: chartID},
update: (store, data) => {
console.log("STORE:",store);
}
}).then((response) => {
appState.toggleDialog(false);
})
});
当我登录商店时,我可以看到 Layout:summary 条目已更新,但它没有反映在 UI 中,弹出的另一件事是还有另一个名为 $ROOT_QUERY.layout({"id":"summary"}) 的条目未使用新数据:
我错过了什么?
【问题讨论】:
标签: reactjs graphql store apollo-client