ABSDKClient

public class ABSDKClient

The ABSDKClient handles network connection, making Query, Mutation and Subscription requests, and resolving the results. The ABSDKClient also manages local caches.

  • Creates a client with the specified ABSDKClientConfiguration.

    Declaration

    Swift

    public init(configuration: ABSDKClientConfiguration) throws

    Parameters

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

    Declaration

    Swift

    @discardableResult
    public func fetch<Query>(query: Query, cachePolicy: CachePolicy = .fetchIgnoringCacheData, queue: DispatchQueue = DispatchQueue.main, resultHandler: OperationResultHandler<Query>? = nil) -> Cancellable

    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. Defaults to the main queue.

    resultHandler

    An optional closure that is called when query results are available or when an error occurs.

    result

    The result of the fetched query, or nil if an error occurred.

    error

    An error that indicates why the fetch failed, or nil if the fetch was succesful.

    Return Value

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

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

    Declaration

    Swift

    @discardableResult
    public func watch<Query>(query: Query, cachePolicy: CachePolicy = .returnCacheDataAndFetch, queue: DispatchQueue = DispatchQueue.main, resultHandler: @escaping OperationResultHandler<Query>) -> GraphQLQueryWatcher<Query>

    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.

    queue

    A dispatch queue on which the result handler will be called. Defaults to the main queue.

    resultHandler

    An optional closure that is called when query results are available or when an error occurs.

    Return Value

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

  • Performs a mutation by sending it to the server.

    Declaration

    Swift

    @discardableResult
    public func perform<Mutation: GraphQLMutation>(mutation: Mutation,
                                                   queue: DispatchQueue = DispatchQueue.main,
                                                   optimisticUpdate: OptimisticResponseBlock? = nil,
                                                   resultHandler: OperationResultHandler<Mutation>? = nil) -> Cancellable

    Parameters

    mutation

    The mutation to perform.

    queue

    A dispatch queue on which the result handler will be called. Defaults to the main queue.

    optimisticUpdate

    An optional closure which gets executed before making the network call, should be used to make local cache update

    resultHandler

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

    Return Value

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

  • Subscribe to a query on the server.

    Declaration

    Swift

    @discardableResult
    public func subscribe<Subscription: GraphQLSubscription>(subscription: Subscription,
                                                             queue: DispatchQueue = DispatchQueue.main,
                                                             resultHandler: @escaping OperationResultHandler<Subscription>) -> Cancellable

    Parameters

    subscription

    The subscription to perform.

    queue

    A dispatch queue on which the result handler will be called. Defaults to the main queue.

    resultHandler

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

    Return Value

    An object that can be used to cancel/unsubscribe an established subscription.