Skip to content

Can't update the RequestBodyCreator for WebSocketTransport #1444

@lowki93

Description

@lowki93

Bug report

We use WebSocketTransport and we need to override the requestBodyCreator parameters.
We define CustomBodyCreator:

struct CustomBodyCreator: RequestBodyCreator {
  
  public func requestBody<Operation: GraphQLOperation>(
    for operation: Operation,
    sendOperationIdentifiers: Bool
  ) -> GraphQLMap {
    .....
  }
  
}

we put it when we initialize the WebSocketTransport:

 WebSocketTransport(request: request, requestBodyCreator: CustomBodyCreator())

The method call in WebSocketTransport don't use the method define in the procotol :

 func sendHelper<Operation: GraphQLOperation>(operation: Operation, resultHandler: @escaping (_ result: Result<JSONObject, Error>) -> Void) -> String? {
    let body = requestBodyCreator.requestBody(for: operation, sendOperationIdentifiers: self.sendOperationIdentifiers)
    ....
    return sequenceNumber
  }

But requestBody from our struct is never call.

There is a an extension for RequestBodyCreator that define the function in the protocol :

extension RequestBodyCreator {
  /// Creates a `GraphQLMap` out of the passed-in operation
  ///
  /// - Parameters:
  ///   - operation: The operation to use
  ///   - sendOperationIdentifiers: Whether or not to send operation identifiers. Defaults to false.
  ///   - sendQueryDocument: Whether or not to send the full query document. Defaults to true.
  ///   - autoPersistQuery: Whether to use auto-persisted query information. Defaults to false.
  /// - Returns: The created `GraphQLMap`
  public func requestBody<Operation: GraphQLOperation>(for operation: Operation,
                                                       sendOperationIdentifiers: Bool = false,
                                                       sendQueryDocument: Bool = true,
                                                       autoPersistQuery: Bool = false) -> GraphQLMap {
.....
}

Why can put this default implementation in ApolloRequestBodyCreator directly ?

// Helper struct to create requests independently of HTTP operations.
public struct ApolloRequestBodyCreator: RequestBodyCreator {
  // Internal init methods cannot be used in public methods
  public init() { }
}

Why we can't override this ?

Versions

Please fill in the versions you're currently using:

  • apollo-ios SDK version: 0.34.1
  • Xcode version: 12.0.1
  • Swift version: 5.2

Further details

We need to override this to make WebSocketTransportwith AppSyncfrom AWS

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions