我正在使用 GraphQLClient 将graphql-request请求发送到我的服务器。我正在尝试通过执行以下操作来上传文件:
const graphQLClient = new GraphQLClient('http://localhost:4000/graphql', {
credentials: 'include',
mode: 'cors',
});
const source = gql`
mutation uploadImage($file: Upload!) {
uploadImage(file: $file)
}
`;
const file: RcFile = SOME_FILE; // RcFile (from antd) extends File
await graphQLClient.request<{uploadImage: boolean}>(source, { file });
但是,当我以这种方式向服务器发送请求时,出现以下错误:
GraphQLError: Variable \"$file\" got invalid value {}; Upload value invalid
这就是我的请求在控制台中的样子:
operations: {
"query":"\n mutation uploadProfileImage($file: Upload!){\n uploadProfileImage(file: $file)\n }\n",
"variables":{"file":null}
}
map: {"1":["variables.file"]}
1: (binary)
其他人遇到过这个问题吗?我似乎无法将文件上传到我的后端。
慕田峪9158850
呼唤远方
红颜莎娜
万千封印
相关分类