Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add FileInput implement #17

Merged
merged 6 commits into from Jun 24, 2017

Conversation

giautm
Copy link
Contributor

@giautm giautm commented Jun 22, 2017

Fix for #10 (comment)

on React Native, upload file via:

import { FileInput } from 'apollo-upload-client'

// Example usage
graphql(UPDATE__MUTATION, {
  props: ({ mutate }) => ({
    update: (input) => {
      const clientMutationId = Date.now();

      return mutate({
        variables: {
          input: {
            ...input,
            clientMutationId,
            signature: new FileInput({
                "name": "file_0",
                "type": "image/png",
                "uri": "/Users/admin/Library/Developer/CoreSimulator/Devices/C02A708F-7003-4747-BB09-AA35530AFAC8/data/Containers/Data/Application/44243AD1-906B-4C2E-AC28-6D700BA99609/tmp/ReactABI17_0_0Native/CA1AD1AC-2B6D-47EB-9AE3-528A537E8AC7.png"
            }),
            photos: FileInput.fromArray([{
                "name": "file_1",
                "type": "image/png",
                "uri": "/Users/admin/Library/Developer/CoreSimulator/Devices/C02A708F-7003-4747-BB09-AA35530AFAC8/data/Containers/Data/Application/44243AD1-906B-4C2E-AC28-6D700BA99609/tmp/ReactABI17_0_0Native/CA1AD1AC-2B6D-47EB-9AE3-528A537E8AC7.png"
            }, {
                "name": "file_2",
                "type": "image/png",
                "uri": "/Users/admin/Library/Developer/CoreSimulator/Devices/C02A708F-7003-4747-BB09-AA35530AFAC8/data/Containers/Data/Application/44243AD1-906B-4C2E-AC28-6D700BA99609/tmp/ReactABI17_0_0Native/CA1AD1AC-2B6D-47EB-9AE3-528A537E8AC7.png"
            }]),
          },
        },
      });
    },
  }),
}),

@jaydenseric
Copy link
Owner

I think our current check is a little too strict as I think name and type is optional for RN file objects. This strategy of using a class would definitely solve the risk of false positives and ease the strictness.

It would make working with RN files a little more complicated, and the bundle size of non RN projects will unfairly increase as the new class has to be imported for the file checks in the extractRequestFiles helper.

I'm leaning towards doing it. This PR needs a bit more polish; I'll jump in where I can.

@jaydenseric
Copy link
Owner

@giautm do you need me to publish a risky beta to test this out?

@jaydenseric jaydenseric merged commit 5862745 into jaydenseric:master Jun 24, 2017
@jaydenseric
Copy link
Owner

This is now live in apollo-upload-client@5.0.0-beta.1 – once verified there are no issues with this release we can move out of of beta.

@giautm
Copy link
Contributor Author

giautm commented Jun 24, 2017

I checked out, it work fine. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants