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.
Hey Apollo Community! I'd like to post a feature request.
Use Case:
I would like to add headers to a
URLRequestconditionally based on the Operation being committed.Analysis:
I see that
HTTPNetworkTransportPreflightDelegatehas a functionfunc networkTransport(_ networkTransport: HTTPNetworkTransport, willSend request: inout URLRequest). This is where it is intended to modify theURLRequestbefore it is actually sent out. However, there is no way to get theGraphQLOperationthat is being committed. That delegate call is called inHTTPNetworkTransport's function:So a copy of the
GraphQLOperationis held here. I was thinking that we could pass the operation with the delegate calls but the existence of an associated type inGraphQLOperationdoes not allow that.The only way around that would be to move out the
Dataassociated 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 ofGraphQLOperationthat is then pass then passed to delegate instead of the Operation itself. I'd be interested in hearing the community's thoughts on this.