You are viewing documentation for a previous version of this software.

Switch to the latest stable version.

RequestChainNetworkTransport


CLASS

RequestChainNetworkTransport

Swift
1open class RequestChainNetworkTransport: NetworkTransport

An implementation of NetworkTransport which creates a RequestChain object for each item sent through it.

Properties

endpointURL

Swift
1public let endpointURL: URL

The GraphQL endpoint URL to use.

additionalHeaders

Swift
1public private(set) var additionalHeaders: [String: String]

Any additional headers that should be automatically added to every request.

autoPersistQueries

Swift
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

Swift
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

Swift
1public let useGETForPersistedQueryRetry: Bool

Set to true to use GET instead of POST for a retry of a persisted query.

requestBodyCreator

Swift
1public var requestBodyCreator: RequestBodyCreator

The RequestBodyCreator object to use to build your URLRequest.

clientName

Swift
1public var clientName = RequestChainNetworkTransport.defaultClientName

clientVersion

Swift
1public var clientVersion = RequestChainNetworkTransport.defaultClientVersion

Methods

init(interceptorProvider:endpointURL:additionalHeaders:autoPersistQueries:requestBodyCreator:useGETForQueries:useGETForPersistedQueryRetry:)

Swift
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 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.

Parameters

NameDescription
interceptorProviderThe interceptor provider to use when constructing chains for a request
endpointURLThe GraphQL endpoint URL to use.
additionalHeadersAny additional headers that should be automatically added to every request. Defaults to an empty dictionary.
autoPersistQueriesPass true if Automatic Persisted Queries should be used to send a query hash instead of the full query body by default. Defaults to false.
requestBodyCreatorThe RequestBodyCreator object to use to build your URLRequest. Defaults to the provided ApolloRequestBodyCreator implementation.
useGETForQueriesPass true if you want to use GET instead of POST for queries, for example to take advantage of a CDN. Defaults to false.
useGETForPersistedQueryRetryPass true to use GET instead of POST for a retry of a persisted query. Defaults to false.

constructRequest(for:cachePolicy:contextIdentifier:)

Swift
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 request

    • contextIdentifier: [optional] A unique identifier for this request, to help with deduping cache hits for watchers. Should default to nil.

  • Returns: The constructed request.

Parameters

NameDescription
operationThe operation to create the request for
cachePolicyThe 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:)

Swift
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

NameDescription
operationThe operation to send.
cachePolicyThe 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.
callbackQueueThe queue to call back on with the results. Should default to .main.
completionHandlerA 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.
Feedback

Edit on GitHub

Forums