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

Switch to the latest stable version.

JSONRequest


CLASS

JSONRequest

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

A request which sends JSON related to a GraphQL operation.

Properties

requestBodyCreator

Swift
1public let requestBodyCreator: RequestBodyCreator

autoPersistQueries

Swift
1public let autoPersistQueries: Bool

useGETForQueries

Swift
1public let useGETForQueries: Bool

useGETForPersistedQueryRetry

Swift
1public let useGETForPersistedQueryRetry: Bool

isPersistedQueryRetry

Swift
1public var isPersistedQueryRetry = false

body

Swift
1public var body: GraphQLMap

serializationFormat

Swift
1public let serializationFormat = JSONSerializationFormat.self

sendOperationIdentifier

Swift
1open var sendOperationIdentifier: Bool

Methods

init(operation:graphQLEndpoint:contextIdentifier:clientName:clientVersion:additionalHeaders:cachePolicy:autoPersistQueries:useGETForQueries:useGETForPersistedQueryRetry:requestBodyCreator:)

Swift
1public init(operation: Operation,
2            graphQLEndpoint: URL,
3            contextIdentifier: UUID? = nil,
4            clientName: String,
5            clientVersion: String,
6            additionalHeaders: [String: String] = [:],
7            cachePolicy: CachePolicy = .default,
8            autoPersistQueries: Bool = false,
9            useGETForQueries: Bool = false,
10            useGETForPersistedQueryRetry: Bool = false,
11            requestBodyCreator: RequestBodyCreator = ApolloRequestBodyCreator())

Designated initializer

  • Parameters:

    • operation: The GraphQL Operation to execute

    • graphQLEndpoint: The endpoint to make a GraphQL request to

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

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

    • autoPersistQueries: true if Auto-Persisted Queries should be used. Defaults to false.

    • useGETForQueries: true if Queries should use GET instead of POST for HTTP requests. Defaults to false.

    • useGETForPersistedQueryRetry: true if when an Auto-Persisted query is retried, it should use GET instead of POST to send the query. Defaults to false.

    • requestBodyCreator: An object conforming to the RequestBodyCreator protocol to assist with creating the request body. Defaults to the provided ApolloRequestBodyCreator implementation.

Parameters

NameDescription
operationThe GraphQL Operation to execute
graphQLEndpointThe endpoint to make a GraphQL request to
contextIdentifier[optional] A unique identifier for this request, to help with deduping cache hits for watchers. Defaults to nil.
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.
autoPersistQueriestrue if Auto-Persisted Queries should be used. Defaults to false.
useGETForQueriestrue if Queries should use GET instead of POST for HTTP requests. Defaults to false.
useGETForPersistedQueryRetrytrue if when an Auto-Persisted query is retried, it should use GET instead of POST to send the query. Defaults to false.
requestBodyCreatorAn object conforming to the RequestBodyCreator protocol to assist with creating the request body. Defaults to the provided ApolloRequestBodyCreator implementation.

toURLRequest()

Swift
1open override func toURLRequest() throws -> URLRequest
Feedback

Edit on GitHub

Forums