Skip to content

Availilability of zipping payload while performing mutation query #782

@sauvikaktivo

Description

@sauvikaktivo

The Problem I am facing

For my current project I have a mutation query

mutation updateActivities(
  $activitiesType1: [ActivitiesType1!]!, 
  $activitiesType2: [ActivitiesType2!]!,
  $activitiesType3: [ActivitiesType3!]!, 
  $activitiesType4: [ActivitiesType4!]!, 
  $activitiesType5: [activitiesType5!]!, 
  $activitiesType6: [ActivitiesType6!]!, 
  $isLifetime: Boolean!,
  $steps: [TimedValue!]!, 
  $currTime: DateTimeUtc!, 
  $timezone: String!) {
    
    updateAppleHealthkitActivities(
      activitiesType1: $activitiesType1, 
      activitiesType2: $activitiesType2, 
      activitiesType3: $activitiesType3, 
      activitiesType4: $activitiesType4,
      activitiesType5: $activitiesType5, 
      activitiesType6: $activitiesType6, 
      isLifetime: $isLifetime, 
      steps: $steps, 
      currTime: $currTime,
      timezone: $timezone) {
        ok
    }
}

Sometimes (it's unavoidable in current architecture) the total mutation payload data becomes more than 10MB in size, then, we are unable (or takes too much time for weak cellular networks) to upload the payload.

The solution I am seeking

I want to zip the payload which is getting prepared under ApolloClient.perform(mutation:queue:resultHandler:) of Apollo client using GZip. I dig into HTTPNetworkTransport.send<Operation>(operation: Operation, completionHandler: @escaping (_ response: GraphQLResponse<Operation>?, _ error: Error?) -> Void) -> Cancellable and found body data is getting prepared by serializing request body. Is there any way we can compress this data before assigning to request.httpBody?

  public func send<Operation>(operation: Operation, completionHandler: @escaping (_ response: GraphQLResponse<Operation>?, _ error: Error?) -> Void) -> Cancellable {
    var request = URLRequest(url: url)
    request.httpMethod = "POST"
    
    request.setValue("application/json", forHTTPHeaderField: "Content-Type")

    let body = requestBody(for: operation)
    request.httpBody = try! serializationFormat.serialize(value: body)

    //...
}

Thanks in advance.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementIssues outlining new things we want to do or things that will make our lives as devs easiernetworking-stack

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions