最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Is there any way to send multipart form request to graphql in reactjs with apollo client - Stack Overflow

programmeradmin0浏览0评论

I am new to react with graphql.

I want to upload .pdf file to server via network interface.

All I need to do is write a graphql query using apollo client which sends multipart form data to server.

I tried to search it on google but I did't found any proper solution.

mutation createUser($user: myfile) {
    createData(myfile: $user) {
        id
        name
        email
    }  
}

I am new to react with graphql.

I want to upload .pdf file to server via network interface.

All I need to do is write a graphql query using apollo client which sends multipart form data to server.

I tried to search it on google but I did't found any proper solution.

mutation createUser($user: myfile) {
    createData(myfile: $user) {
        id
        name
        email
    }  
}
Share Improve this question edited Apr 14, 2017 at 13:55 Mohammad Akbari 4,7846 gold badges51 silver badges78 bronze badges asked Apr 14, 2017 at 12:27 Tejas SatheTejas Sathe 511 gold badge1 silver badge2 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 6

GraphQL doesn't normally deal with multipart data or file uploads, but if you are writing your server yourself you can create a custom request type which has more fields than just the query, and thus make it work. This guy did it here.

This is a rather roundabout way to go at it which will probably give you lots of headaches. I would remend being less stubborn about the single endpoint, and use a different server to manage the upload. After all, there are lots of well tested libraries dealing with all "the devils details" surrounding uploads.

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论