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

Initial work on File and Array<File> support #4

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

sandervanhooft
Copy link
Collaborator

Also see issue #3. My initial work on this. Got the checking to work, but adding the array to the request body fails. I've not tested appending only a File to the body.

@HriBB
Copy link
Owner

HriBB commented Dec 7, 2016

Hmmm ... can we detect variable type from mutation? For example ...

const ADD_PROFILE_PICTURE = gql`
  mutation addProfilePicture($id: Int!, $file: UploadedFile!) {
    addProfilePicture(id: $id, file: $file) {
      id type filename url
    }
  }`

or

const ADD_GALLERY_PICTURES = gql`
  mutation addGalleryPictures($id: Int!, $files: [UploadedFile!]!) {
    addGalleryPictures(id: $id, files: $files) {
      id type filename url
    }
  }`

But we still need to check for File or FileList somehow ... ahh too late, need to get some sleep. Let's discuss this tomorrow.

@@ -46,6 +67,10 @@ export class UploadNetworkInterface extends HTTPFetchNetworkInterface {
let v = request.variables[key]
if (v instanceof FileList) {
Array.from(v).forEach(f => body.append(key, f))
} else if (isArrayOfFiles(v)) {
for (var file in v) {
return body.append(key, file); // this part seems buggy
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return here will cause only the first file to get appended


isUpload({ request }) {
if (request.variables) {
for (let key in request.variables) {
if (request.variables[key] instanceof FileList) {
return true
}
if (request.variables[key] instanceof File) {
return true;
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

indentation is off here

return true;
}
if (this.isArrayOfFiles(request.variables[key])) {
return true;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The rest of this file doesn't use semicolons, probably following Standard Style

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.

3 participants