Skip to content

Passing Operations through HTTPNetworkTransportDelegate #1189

@Kalvin126

Description

@Kalvin126

Hey Apollo Community! I'd like to post a feature request.

Use Case:
I would like to add headers to a URLRequest conditionally based on the Operation being committed.

Analysis:
I see that HTTPNetworkTransportPreflightDelegate has a function func networkTransport(_ networkTransport: HTTPNetworkTransport, willSend request: inout URLRequest). This is where it is intended to modify the URLRequest before it is actually sent out. However, there is no way to get the GraphQLOperation that is being committed. That delegate call is called in HTTPNetworkTransport's function:

func createRequest<Operation: GraphQLOperation>(for operation: Operation,
                                                isPersistedQueryRetry: Bool,
                                                files: [GraphQLFile]?) throws -> URLRequest

So a copy of the GraphQLOperation is held here. I was thinking that we could pass the operation with the delegate calls but the existence of an associated type in GraphQLOperation does not allow that.

The only way around that would be to move out the Data associated type, but that would break a bunch of other code and would require re-architecting. Another issue did talk about placing a context object. That could be a required member of GraphQLOperation that is then pass then passed to delegate instead of the Operation itself. I'd be interested in hearing the community's thoughts on this.

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