HTTPRequest


CLASS

HTTPRequest

Swift
1open class HTTPRequest<Operation: GraphQLOperation>: Hashable

Encapsulation of all information about a request before it hits the network

Properties

graphQLEndpoint

Swift
1open var graphQLEndpoint: URL

The endpoint to make a GraphQL request to

operation

Swift
1open var operation: Operation

The GraphQL Operation to execute

additionalHeaders

Swift
1open var additionalHeaders: [String: String]

Any additional headers you wish to add by default to this request

cachePolicy

Swift
1open var cachePolicy: CachePolicy

The CachePolicy to use for this request.

contextIdentifier

Swift
1public let contextIdentifier: UUID?

[optional] A unique identifier for this request, to help with deduping cache hits for watchers.

Methods

init(graphQLEndpoint:operation:contextIdentifier:contentType:clientName:clientVersion:additionalHeaders:cachePolicy:)

Swift
1public init(graphQLEndpoint: URL,
2            operation: Operation,
3            contextIdentifier: UUID? = nil,
4            contentType: String,
5            clientName: String,
6            clientVersion: String,
7            additionalHeaders: [String: String],
8            cachePolicy: CachePolicy = .default)

Designated Initializer

  • Parameters:

    • graphQLEndpoint: The endpoint to make a GraphQL request to

    • operation: The GraphQL Operation to execute

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

    • contentType: The Content-Type header's value. Should usually be set for you by a subclass.

    • clientName: The name of the client to send with the "apollographql-client-name" header

    • clientVersion: The version of the client to send with the "apollographql-client-version" header

    • additionalHeaders: Any additional headers you wish to add by default to this request.

    • cachePolicy: The CachePolicy to use for this request. Defaults to the .default policy

Parameters

NameDescription
graphQLEndpointThe endpoint to make a GraphQL request to
operationThe GraphQL Operation to execute
contextIdentifier[optional] A unique identifier for this request, to help with deduping cache hits for watchers. Defaults to nil.
contentTypeThe Content-Type header’s value. Should usually be set for you by a subclass.
clientNameThe name of the client to send with the "apollographql-client-name" header
clientVersionThe version of the client to send with the "apollographql-client-version" header
additionalHeadersAny additional headers you wish to add by default to this request.
cachePolicyThe CachePolicy to use for this request. Defaults to the .default policy

addHeader(name:value:)

Swift
1open func addHeader(name: String, value: String)

updateContentType(to:)

Swift
1open func updateContentType(to contentType: String)

toURLRequest()

Swift
1open func toURLRequest() throws -> URLRequest

Converts this object to a fully fleshed-out URLRequest

  • Throws: Any error in creating the request

  • Returns: The URL request, ready to send to your server.

hash(into:)

Swift
1public func hash(into hasher: inout Hasher)

Parameters

NameDescription
hasherThe hasher to use when combining the components of this instance.

==(_:_:)

Swift
1public static func == (lhs: HTTPRequest<Operation>, rhs: HTTPRequest<Operation>) -> Bool

Parameters

NameDescription
lhsA value to compare.
rhsAnother value to compare.
Feedback

Edit on GitHub

Forums