admin管理员组

文章数量:1305364

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.

本文标签: