RequestChainNetworkTransport
CLASS
RequestChainNetworkTransport
1open class RequestChainNetworkTransport: NetworkTransport
An implementation of NetworkTransport
which creates a RequestChain
object
for each item sent through it.
Properties
endpointURL
1public let endpointURL: URL
The GraphQL endpoint URL to use.
additionalHeaders
1public private(set) var additionalHeaders: [String: String]
Any additional headers that should be automatically added to every request.
autoPersistQueries
1public let autoPersistQueries: Bool
Set to true
if Automatic Persisted Queries should be used to send a query hash instead of the full query body by default.
useGETForQueries
1public let useGETForQueries: Bool
Set to true
if you want to use GET
instead of POST
for queries, for example to take advantage of a CDN.
useGETForPersistedQueryRetry
1public let useGETForPersistedQueryRetry: Bool
Set to true
to use GET
instead of POST
for a retry of a persisted query.
requestBodyCreator
1public var requestBodyCreator: RequestBodyCreator
The RequestBodyCreator
object to use to build your URLRequest
.
clientName
1public var clientName = RequestChainNetworkTransport.defaultClientName
clientVersion
1public var clientVersion = RequestChainNetworkTransport.defaultClientVersion
Methods
init(interceptorProvider:endpointURL:additionalHeaders:autoPersistQueries:requestBodyCreator:useGETForQueries:useGETForPersistedQueryRetry:)
1public init(interceptorProvider: InterceptorProvider,
2 endpointURL: URL,
3 additionalHeaders: [String: String] = [:],
4 autoPersistQueries: Bool = false,
5 requestBodyCreator: RequestBodyCreator = ApolloRequestBodyCreator(),
6 useGETForQueries: Bool = false,
7 useGETForPersistedQueryRetry: Bool = false)
Designated initializer
Parameters:
interceptorProvider: The interceptor provider to use when constructing chains for a request
endpointURL: The GraphQL endpoint URL to use.
additionalHeaders: Any additional headers that should be automatically added to every request. Defaults to an empty dictionary.
autoPersistQueries: Pass
true
if Automatic Persisted Queries should be used to send a query hash instead of the full query body by default. Defaults tofalse
.requestBodyCreator: The
RequestBodyCreator
object to use to build yourURLRequest
. Defaults to the providedApolloRequestBodyCreator
implementation.useGETForQueries: Pass
true
if you want to useGET
instead ofPOST
for queries, for example to take advantage of a CDN. Defaults tofalse
.useGETForPersistedQueryRetry: Pass
true
to useGET
instead ofPOST
for a retry of a persisted query. Defaults tofalse
.
Parameters
Name | Description |
---|---|
interceptorProvider | The interceptor provider to use when constructing chains for a request |
endpointURL | The GraphQL endpoint URL to use. |
additionalHeaders | Any additional headers that should be automatically added to every request. Defaults to an empty dictionary. |
autoPersistQueries | Pass true if Automatic Persisted Queries should be used to send a query hash instead of the full query body by default. Defaults to false . |
requestBodyCreator | The RequestBodyCreator object to use to build your URLRequest . Defaults to the provided ApolloRequestBodyCreator implementation. |
useGETForQueries | Pass true if you want to use GET instead of POST for queries, for example to take advantage of a CDN. Defaults to false . |
useGETForPersistedQueryRetry | Pass true to use GET instead of POST for a retry of a persisted query. Defaults to false . |
constructRequest(for:cachePolicy:contextIdentifier:)
1open func constructRequest<Operation: GraphQLOperation>(
2 for operation: Operation,
3 cachePolicy: CachePolicy,
4 contextIdentifier: UUID? = nil) -> HTTPRequest<Operation>
Constructs a default (ie, non-multipart) GraphQL request.
Override this method if you need to use a custom subclass of HTTPRequest
.
Parameters:
operation: The operation to create the request for
cachePolicy: The
CachePolicy
to use when creating the requestcontextIdentifier: [optional] A unique identifier for this request, to help with deduping cache hits for watchers. Should default to
nil
.
Returns: The constructed request.
Parameters
Name | Description |
---|---|
operation | The operation to create the request for |
cachePolicy | The CachePolicy to use when creating the request |
contextIdentifier | [optional] A unique identifier for this request, to help with deduping cache hits for watchers. Should default to nil . |
send(operation:cachePolicy:contextIdentifier:callbackQueue:completionHandler:)
1public func send<Operation: GraphQLOperation>(
2 operation: Operation,
3 cachePolicy: CachePolicy = .default,
4 contextIdentifier: UUID? = nil,
5 callbackQueue: DispatchQueue = .main,
6 completionHandler: @escaping (Result<GraphQLResult<Operation.Data>, Error>) -> Void) -> Cancellable
Parameters
Name | Description |
---|---|
operation | The operation to send. |
cachePolicy | The CachePolicy to use making this request. |
contextIdentifier | [optional] A unique identifier for this request, to help with deduping cache hits for watchers. Defaults to nil . |
callbackQueue | The queue to call back on with the results. Should default to .main . |
completionHandler | A closure to call when a request completes. On success will contain the response received from the server. On failure will contain the error which occurred. |