更新时出现存储错误,并且是apollo和graphQL的新手,所以无法理解我在做什么错。 我正在尝试更新一个人的名字和姓氏。 这个对象是嵌套的,我正在传递typeName作为包装对象的typeName。 如果有人知道这一点并可以提出建议,请告诉我
这是在阿波罗中的样子:
validationType:age @ empId
persondetails:personDetailsType
第一个:“ abc”
empId:10002
年龄:“ 21”
上一个:“ def”
值从此处传递:
<Button content="Save"
onClick={(_, {value}) => {
this.props.mutation({
variables: {
persondetails: {
first: this.state.first,
last: this.state.last,
empId: empId,
age: age
},
age,
empId,
}
});
}}
/>
我的更新查询看起来像这样:
updatePersonDetails: (
_,
{persondetails, age, empId},
{cache}
) => {
cache.writeFragment({
id: `validationType:${age}!${empId}`,
fragment: gql`
fragment updatePersonDetails on validationType {
persondetails {
first
last
age
empId
__typename
}
__typename
}
`,
data: {
persondetails: persondetails,
age,
empId,
__typename: 'validationType'
}
});
[Network error]: Error: Error writing result to store for query:
{
...updatePersonDetails
}
fragment persondetails on validationType {
persondetails {
first
last
age
empId
__typename
}
__typename
}
Store error: the application attempted to write an object with no provided typename but the store already contains an object with typename of personDetailsType for the object of id $validationType!21.1002. The selectionSet that was trying to be written is:
persondetails {
first
last
age
empId
__typename
}
答案 0 :(得分:0)
在传递更新时,我在解析器中以错误的方式声明了我的对象。而且我在那个对象中缺少typeName。 正确的语法是:
updatePersonDetails: (
_,
{persondetails, age, empId},
{cache}
) => {
cache.writeFragment({
id: `validationType:${age}!${empId}`,
fragment: gql`
fragment updatePersonDetails on validationType {
persondetails {
first
last
age
empId
__typename
}
__typename
}
`,
data: {
persondetails: {
...persondetails,
__typename: 'persondetailsType'
}
__typename: 'validationType'
}
});