ApolloClientProtocol


PROTOCOL

ApolloClientProtocol

Swift
1public protocol ApolloClientProtocol: AnyObject

The ApolloClientProtocol provides the core API for Apollo. This API provides methods to fetch and watch queries, and to perform mutations.

Properties

store

Swift
1var store: ApolloStore

A store used as a local cache.

Methods

clearCache(callbackQueue:completion:)

Swift
1func clearCache(callbackQueue: DispatchQueue, completion: ((Result<Void, Error>) -> Void)?)

Clears the underlying cache. Be aware: In more complex setups, the same underlying cache can be used across multiple instances, so if you call this on one instance, it'll clear that cache across all instances which share that cache.

  • Parameters:

    • callbackQueue: The queue to fall back on. Should default to the main queue.

    • completion: [optional] A completion closure to execute when clearing has completed. Should default to nil.

Parameters

NameDescription
callbackQueueThe queue to fall back on. Should default to the main queue.
completion[optional] A completion closure to execute when clearing has completed. Should default to nil.

fetch(query:cachePolicy:contextIdentifier:queue:resultHandler:)

Swift
1func fetch<Query: GraphQLQuery>(query: Query,
2                                cachePolicy: CachePolicy,
3                                contextIdentifier: UUID?,
4                                queue: DispatchQueue,
5                                resultHandler: GraphQLResultHandler<Query.Data>?) -> Cancellable

Fetches a query from the server or from the local cache, depending on the current contents of the cache and the specified cache policy.

  • Parameters:

    • query: The query to fetch.

    • cachePolicy: A cache policy that specifies when results should be fetched from the server and when data should be loaded from the local cache.

    • queue: A dispatch queue on which the result handler will be called. Should default to the main queue.

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

    • resultHandler: [optional] A closure that is called when query results are available or when an error occurs.

  • Returns: An object that can be used to cancel an in progress fetch.

Parameters

NameDescription
queryThe query to fetch.
cachePolicyA cache policy that specifies when results should be fetched from the server and when data should be loaded from the local cache.
queueA dispatch queue on which the result handler will be called. Should default to the main queue.
contextIdentifier[optional] A unique identifier for this request, to help with deduping cache hits for watchers. Should default to nil.
resultHandler[optional] A closure that is called when query results are available or when an error occurs.

watch(query:cachePolicy:callbackQueue:resultHandler:)

Swift
1func watch<Query: GraphQLQuery>(query: Query,
2                                cachePolicy: CachePolicy,
3                                callbackQueue: DispatchQueue,
4                                resultHandler: @escaping GraphQLResultHandler<Query.Data>) -> GraphQLQueryWatcher<Query>

Watches a query by first fetching an initial result from the server or from the local cache, depending on the current contents of the cache and the specified cache policy. After the initial fetch, the returned query watcher object will get notified whenever any of the data the query result depends on changes in the local cache, and calls the result handler again with the new result.

  • Parameters:

    • query: The query to fetch.

    • cachePolicy: A cache policy that specifies when results should be fetched from the server or from the local cache.

    • callbackQueue: A dispatch queue on which the result handler will be called. Should default to the main queue.

    • resultHandler: [optional] A closure that is called when query results are available or when an error occurs.

  • Returns: A query watcher object that can be used to control the watching behavior.

Parameters

NameDescription
queryThe query to fetch.
cachePolicyA cache policy that specifies when results should be fetched from the server or from the local cache.
callbackQueueA dispatch queue on which the result handler will be called. Should default to the main queue.
resultHandler[optional] A closure that is called when query results are available or when an error occurs.

perform(mutation:publishResultToStore:queue:resultHandler:)

Swift
1func perform<Mutation: GraphQLMutation>(mutation: Mutation,
2                                        publishResultToStore: Bool,
3                                        queue: DispatchQueue,
4                                        resultHandler: GraphQLResultHandler<Mutation.Data>?) -> Cancellable

Performs a mutation by sending it to the server.

  • Parameters:

    • mutation: The mutation to perform.

    • publishResultToStore: If true, this will publish the result returned from the operation to the cache store. Default is true.

    • queue: A dispatch queue on which the result handler will be called. Should default to the main queue.

    • resultHandler: An optional closure that is called when mutation results are available or when an error occurs.

  • Returns: An object that can be used to cancel an in progress mutation.

Parameters

NameDescription
mutationThe mutation to perform.
publishResultToStoreIf true, this will publish the result returned from the operation to the cache store. Default is true.
queueA dispatch queue on which the result handler will be called. Should default to the main queue.
resultHandlerAn optional closure that is called when mutation results are available or when an error occurs.

upload(operation:files:queue:resultHandler:)

Swift
1func upload<Operation: GraphQLOperation>(operation: Operation,
2                                         files: [GraphQLFile],
3                                         queue: DispatchQueue,
4                                         resultHandler: GraphQLResultHandler<Operation.Data>?) -> Cancellable

Uploads the given files with the given operation.

  • Parameters:

    • operation: The operation to send

    • files: An array of GraphQLFile objects to send.

    • queue: A dispatch queue on which the result handler will be called. Should default to the main queue.

    • completionHandler: The completion handler to execute when the request completes or errors. Note that an error will be returned If your networkTransport does not also conform to UploadingNetworkTransport.

  • Returns: An object that can be used to cancel an in progress request.

Parameters

NameDescription
operationThe operation to send
filesAn array of GraphQLFile objects to send.
queueA dispatch queue on which the result handler will be called. Should default to the main queue.
completionHandlerThe completion handler to execute when the request completes or errors. Note that an error will be returned If your networkTransport does not also conform to UploadingNetworkTransport.

subscribe(subscription:queue:resultHandler:)

Swift
1func subscribe<Subscription: GraphQLSubscription>(subscription: Subscription,
2                                                  queue: DispatchQueue,
3                                                  resultHandler: @escaping GraphQLResultHandler<Subscription.Data>) -> Cancellable

Subscribe to a subscription

  • Parameters:

    • subscription: The subscription to subscribe to.

    • fetchHTTPMethod: The HTTP Method to be used.

    • queue: A dispatch queue on which the result handler will be called. Should default to the main queue.

    • resultHandler: An optional closure that is called when mutation results are available or when an error occurs.

  • Returns: An object that can be used to cancel an in progress subscription.

Parameters

NameDescription
subscriptionThe subscription to subscribe to.
fetchHTTPMethodThe HTTP Method to be used.
queueA dispatch queue on which the result handler will be called. Should default to the main queue.
resultHandlerAn optional closure that is called when mutation results are available or when an error occurs.
Feedback

Edit on GitHub

Forums