Skip to content

Allow single file uploads #10

Open
@jaydenseric

Description

@jaydenseric

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions