【发布时间】:2018-02-18 23:22:30
【问题描述】:
我正在使用apollo-upload-client,所以调用看起来像这样:
const UPLOAD_IMAGE_MUTATION = gql`
mutation AddImageFileMutation ($file: Upload!, $albumId: String!) {
uploadImage(file: $file, albumId: $albumId){
id
}}`
您可以看到它应该返回id,但我发现情况并非如此。
我的update: 调用显示{data} 包含{data: {uploadImage: null}}(请参阅下面的代码以供参考)。有没有办法让它返回ID?
更新突变(使用 Dropzone 做参考)....
_onDrop = async (acceptedFiles, rejectedFiles) => {
acceptedFiles.map((imageFile, index) => {
const uploadImage = async () => {
const index = Math.random()
this.state.loadingBars.push({index: index, preview: imageFile.preview, percentage: 15})
await this.props.uploadImageMutation({
variables: {file: imageFile, albumId: this.state.albumId},
update: (store, {data: {uploadImage}}) => {
//uploadImage returning null. {data} equals {data: {uploadImage: null}}
//stuff
}
})
};
uploadImage()
})
}
【问题讨论】:
-
如果
uploadImage为空,听起来你的突变的解析器要么没有返回任何东西,要么返回的对象不是预期的形状。查看您的解析器代码可能会有所帮助。 -
你是对的,看更新