Skip to content

Upload multiple files. Variables generated format #979

@alobanov

Description

@alobanov

Apollo supported GraphQL multipart request specification, but I can't do something like this:

// type ImageInput = Type: String!, file: Upload!
mutation SaveFiles($images: [ImageInput]!) { 
  saveFiles(images: $images) {
    ... on Result { ... }
    ... on ValidationErrorsList { ... }
  }
}

Implementation in project:

let image1 = ImageInput(type: .idCardFront, file: "0")
let image2 = ImageInput(type: .idCardBack, file: "1")

let img = (UIImage(named: "image")?.pngData())!
let file1 = GraphQLFile(fieldName: "images", originalName: "ImageFront.png", mimeType: "image/png", data: img)
let file2 = GraphQLFile(fieldName: "images", originalName: "ImageBack.png", mimeType: "image/png", data: img)

let mutation = SaveFiles(...)
apollo.upload(operation: mutation, files: [file1, file2])

After that, under the hud variables transform to:

// Apollo generate:
"variables": { "images": [null, null] }

// !!! but it should be:
"variables": { "images": [ {"Type": "idCardFront", file: null}, {"Type": "idCardBack", file: null} }

Under the hud file variable transform to: (see the code)

// Apollo generate:
map = {"0": "variable.images.0", "1": "variable.images.1"}

// But it should looks like:
map = {"0": "variable.images.0.file", "1": "variable.images.1.file"}

Unfortunately, I can't ask my server side to change implementation. Can you help me with this?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions