GraphQLQueryWatcher


CLASS

GraphQLQueryWatcher

Swift
1public final class GraphQLQueryWatcher<Query: GraphQLQuery>: Cancellable, ApolloStoreSubscriber

A GraphQLQueryWatcher is responsible for watching the store, and calling the result handler with a new result whenever any of the data the previous result depends on changes.

NOTE: The store retains the watcher while subscribed. You must call cancel() on your query watcher when you no longer need results. Failure to call cancel() before releasing your reference to the returned watcher will result in a memory leak.

Properties

query

Swift
1public let query: Query

Methods

init(client:query:callbackQueue:resultHandler:)

Swift
1public init(client: ApolloClientProtocol,
2            query: Query,
3            callbackQueue: DispatchQueue = .main,
4            resultHandler: @escaping GraphQLResultHandler<Query.Data>)

Designated initializer

  • Parameters:

    • client: The client protocol to pass in.

    • query: The query to watch.

    • callbackQueue: The queue for the result handler. Defaults to the main queue.

    • resultHandler: The result handler to call with changes.

Parameters

NameDescription
clientThe client protocol to pass in.
queryThe query to watch.
callbackQueueThe queue for the result handler. Defaults to the main queue.
resultHandlerThe result handler to call with changes.

refetch(cachePolicy:)

Swift
1public func refetch(cachePolicy: CachePolicy = .fetchIgnoringCacheData)

Refetch a query from the server.

cancel()

Swift
1public func cancel()

Cancel any in progress fetching operations and unsubscribe from the store.

Feedback

Edit on GitHub

Forums