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

Allow single file uploads #10

Open
jaydenseric opened this issue Jan 25, 2017 · 2 comments
Open

Allow single file uploads #10

jaydenseric opened this issue Jan 25, 2017 · 2 comments

Comments

@jaydenseric
Copy link

Basically, allow for mutations instead of just like this:

updateAvatar(userId: String!, file: [UploadedFile!]!): Avatar

Also like this:

updateAvatar(userId: String!, file: UploadedFile!): Avatar
  • Clearer semantics.
  • Better validation for mutations requiring only one file in a variable.
  • It is sometimes easier to get a single File object to send as a mutation parameter:
handleSubmit = event => {
    event.preventDefault()
    const formData = new window.FormData(event.target)
    this.props.mutate({
      variables: {
        userId: this.props.userId,
        file: formData.get('avatar') // Instance of File (not FileList), from <input type='file' name='avatar' required />
      }
    }).then(({data}) => {
      console.log('Avatar updated', data)
    })
  }

To get this to work, handle File as well as FileList here and here.

@jaydenseric
Copy link
Author

Not certain how all this works, but here in graphql-server-express-upload also looks relevant.

@jaydenseric
Copy link
Author

jaydenseric commented Mar 19, 2017

For those who find this pressing, I ended up supporting single File objects, File arrays, and FileList objects anywhere within mutation or query variables with apollo-upload-client.

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

No branches or pull requests

1 participant