在尝试更改阿波罗中的本地状态时遇到此错误。
errInvariant Violation:期望解析的GraphQL文档。也许您需要将查询字符串包装在“ gql”标签中? http://docs.apollostack.com/apollo-client/core.html#gql
初始状态
registration: {
__typename: 'Registration',
tempMerchantId: '',
authorizeProfile: {
__typename: 'AuthorizePersonProfile',
nid_front: '',
nid_back: '',
authorized_person_photo: ''
}
}
我的突变
export const setAuthorizePersonQuery = gql`
mutation setAuthorizePersonProfileInfo($authorizePerosnData: Object!){
setAuthorizePersonProfileInfo(authorizePersonData: $authorizePerosnData) @client
}
`;
我的解析器
export const setAuthorizePersonProfileInfo = (
_, { authorizePersonData }, { cache }
) => {
try {
const prevData = cache.readQuery({ getAuthorizePersonProfileQuery });
cache.writeQuery({
getAuthorizePersonProfileQuery,
data: {
registration: {
__typename: 'Registration',
authorizeProfile: {
__typename: 'AuthorizePersonProfile',
...prevData.registration.authorizeProfile,
...authorizePersonData
}
}
}
});
} catch (e) {
console.log(`err${e}`);
}
return null;
};
我试图在按下按钮时改变本地状态,该功能是
const handlePressedNext = () => {
Promise.all([
setAuthorizePersonProfileInfo({
variables: { authorizePersonData: generateNidData() }
})
])
.then(() => {
navigation.navigate('Photograph');
});
};
generateNidData
功能类似于波纹管
const generateNidData = () => ({
nid_front: nidFrontImage,
nid_back: nidBackImage
});
我是apollo客户的新手。我不明白我在做什么错。谁能帮我解决问题?
答案 0 :(得分:2)
getAuthorizePersonProfileQuery
不是readQuery
的有效选项。大概是用query
来代替的。