{"action":"created","issue":{"url":"https://api.github.com/repos/apollostack/apollo/issues/65","repository_url":"https://api.github.com/repos/apollostack/apollo","labels_url":"https://api.github.com/repos/apollostack/apollo/issues/65/labels{/name}","comments_url":"https://api.github.com/repos/apollostack/apollo/issues/65/comments","events_url":"https://api.github.com/repos/apollostack/apollo/issues/65/events","html_url":"https://github.com/apollostack/apollo/issues/65","id":176086526,"number":65,"title":"[Proposal] File Uploads","user":{"login":"jangerhofer","id":671696,"avatar_url":"https://avatars.githubusercontent.com/u/671696?v=3","gravatar_id":"","url":"https://api.github.com/users/jangerhofer","html_url":"https://github.com/jangerhofer","followers_url":"https://api.github.com/users/jangerhofer/followers","following_url":"https://api.github.com/users/jangerhofer/following{/other_user}","gists_url":"https://api.github.com/users/jangerhofer/gists{/gist_id}","starred_url":"https://api.github.com/users/jangerhofer/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jangerhofer/subscriptions","organizations_url":"https://api.github.com/users/jangerhofer/orgs","repos_url":"https://api.github.com/users/jangerhofer/repos","events_url":"https://api.github.com/users/jangerhofer/events{/privacy}","received_events_url":"https://api.github.com/users/jangerhofer/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":34,"created_at":"2016-09-09T19:13:35Z","updated_at":"2016-12-01T23:12:37Z","closed_at":null,"body":"After toying with the [Express-GraphQL file upload demo](https://github.com/graphql/express-graphql/blob/0bf6aac9ec1c02d42f5de93ff068182c304d56a4/src/__tests__/http-test.js#L676), I have been thinking about how to bring file uploads inside GraphQL mutations to Apollo.\n\nHere is the rundown of what I've learned and the best solution I have formulated:\n- Canonical file uploads happen via a `mutipart/form-data` POST request, whereas Apollo Client interfaces with the Server exclusively with `application/json` requests at present.\n- There are other ways to transmit a file from browser to server, but they are often flimsy and poor solutions.\n- The ideal solution delivers both a GraphQL mutation and the uploaded file(s) to the server in such a way that the schema resolvers have access to the files, such that custom logic can test, modify, and/or store the uploads.  The best way to ensure both mutation string and file(s) reach the server at the same time is to merge them into the same request.\n- Thus, I think that Apollo Client needs to either\n  - gain a new method, e.g. `mutateWithFiles( \"gqlQueryString\", { apolloOptions }, [ files ] )` or\n  - include a new option, e.g. `uploadFiles : [ ... ]`\n  \n  which, when used, sends a `multipart/form-data` POST to the specified Apollo Server endpoint.  The request would be identical to the normal request apart from the inclusion of a new `files` field or similar which contains the uploading files.  I think I would lean towards the clarity of a new method on account of readability.\n- Apollo Server will then need to check each request for its `content-type`; if it is `application/json`, then no upload-specific logic happens and the mutation continues as usual.  If, however, the POST is of `content-type` `multipart/form-data`, the server will append the files in memory to the root query object.  The mutation then continues as usual.\n  - This way, the files are available to the resolvers via the first `root` argument and subsequently to connectors if need-be.  \n\nPlease chime in if you have any thoughts.  I'd especially like for members of the Apollo team to offer their opinions.  If we get to a design that satisfies the dev team, I am happy to work alongside any other interested parties to create a PR!\n"},"comment":{"url":"https://api.github.com/repos/apollostack/apollo/issues/comments/264324684","html_url":"https://github.com/apollostack/apollo/issues/65#issuecomment-264324684","issue_url":"https://api.github.com/repos/apollostack/apollo/issues/65","id":264324684,"user":{"login":"guilhermedecampo","id":4806269,"avatar_url":"https://avatars.githubusercontent.com/u/4806269?v=3","gravatar_id":"","url":"https://api.github.com/users/guilhermedecampo","html_url":"https://github.com/guilhermedecampo","followers_url":"https://api.github.com/users/guilhermedecampo/followers","following_url":"https://api.github.com/users/guilhermedecampo/following{/other_user}","gists_url":"https://api.github.com/users/guilhermedecampo/gists{/gist_id}","starred_url":"https://api.github.com/users/guilhermedecampo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/guilhermedecampo/subscriptions","organizations_url":"https://api.github.com/users/guilhermedecampo/orgs","repos_url":"https://api.github.com/users/guilhermedecampo/repos","events_url":"https://api.github.com/users/guilhermedecampo/events{/privacy}","received_events_url":"https://api.github.com/users/guilhermedecampo/received_events","type":"User","site_admin":false},"created_at":"2016-12-01T23:12:37Z","updated_at":"2016-12-01T23:12:37Z","body":"Yeah great @HriBB \r\n\r\nFor sure. I have already done apps that uses AWS, Cloudinary and other third-part ways to upload files.\r\nBut some clients really need the files uploaded to their own servers.\r\n\r\nA good practice and pattern would be awesome for RN.\r\n\r\nLet's see what the core-devs have to say! Really curious about it."}}
{"actor":{"display_login":"guilhermedecampo"}}