当我将图像上传到S3时,需要一段时间才能从AWS返回文件。当尝试使用apollo/rect挂钩的"loading"属性时,它不考虑文件上传,并且总是在图像位置实际返回之前返回true
import React, { useState, useCallback } from "react";
import { useMutation } from "@apollo/react-hooks";
import { UPLOAD_FILE } from "../../queries";
const [uploadFile, { loading, error, data }] = useMutation(UPLOAD_FILE);
if (loading) {
alert(loading)
} else {
if (data) {
console.log(data, 'DATA');
values.image = data
}
}
您是否在ApoloCient中添加了createUploadLink用于文件上传?
import ApolloClient from 'apollo-client';
import { ApolloLink } from 'apollo-link';
import { createUploadLink } from 'apollo-upload-client';
const uploadLink = createUploadLink({
uri: GRAPHQL_URI,
headers: {
'keep-alive': 'true',
},
});
const client = new ApolloClient({
uri: GRAPHQL_URI,
link: ApolloLink.from([errLink, uploadLink, link]),
...
});