|
| 1 | +**CLASS** |
| 2 | + |
| 3 | +# `ApolloClient` |
| 4 | + |
| 5 | +```swift |
| 6 | +public class ApolloClient |
| 7 | +``` |
| 8 | + |
| 9 | +> The `ApolloClient` class provides the core API for Apollo. This API provides methods to fetch and watch queries, and to perform mutations. |
| 10 | + |
| 11 | +## Properties |
| 12 | +### `store` |
| 13 | + |
| 14 | +```swift |
| 15 | +public let store: ApolloStore |
| 16 | +``` |
| 17 | + |
| 18 | +### `cacheKeyForObject` |
| 19 | + |
| 20 | +```swift |
| 21 | +public var cacheKeyForObject: CacheKeyForObject? |
| 22 | +``` |
| 23 | + |
| 24 | +## Methods |
| 25 | +### `init(networkTransport:store:)` |
| 26 | + |
| 27 | +```swift |
| 28 | +public init(networkTransport: NetworkTransport, store: ApolloStore = ApolloStore(cache: InMemoryNormalizedCache())) |
| 29 | +``` |
| 30 | + |
| 31 | +> Creates a client with the specified network transport and store. |
| 32 | +> |
| 33 | +> - Parameters: |
| 34 | +> - networkTransport: A network transport used to send operations to a server. |
| 35 | +> - store: A store used as a local cache. Defaults to an empty store backed by an in memory cache. |
| 36 | + |
| 37 | +#### Parameters |
| 38 | + |
| 39 | +| Name | Description | |
| 40 | +| ---- | ----------- | |
| 41 | +| networkTransport | A network transport used to send operations to a server. | |
| 42 | +| store | A store used as a local cache. Defaults to an empty store backed by an in memory cache. | |
| 43 | + |
| 44 | +### `init(url:)` |
| 45 | + |
| 46 | +```swift |
| 47 | +public convenience init(url: URL) |
| 48 | +``` |
| 49 | + |
| 50 | +> Creates a client with an HTTP network transport connecting to the specified URL. |
| 51 | +> |
| 52 | +> - Parameter url: The URL of a GraphQL server to connect to. |
| 53 | + |
| 54 | +#### Parameters |
| 55 | + |
| 56 | +| Name | Description | |
| 57 | +| ---- | ----------- | |
| 58 | +| url | The URL of a GraphQL server to connect to. | |
| 59 | + |
| 60 | +### `clearCache()` |
| 61 | + |
| 62 | +```swift |
| 63 | +public func clearCache() -> Promise<Void> |
| 64 | +``` |
| 65 | + |
| 66 | +> Clears apollo cache |
| 67 | +> |
| 68 | +> - Returns: Promise |
| 69 | + |
| 70 | +### `fetch(query:cachePolicy:context:queue:resultHandler:)` |
| 71 | + |
| 72 | +```swift |
| 73 | +@discardableResult public func fetch<Query: GraphQLQuery>(query: Query, cachePolicy: CachePolicy = .returnCacheDataElseFetch, context: UnsafeMutableRawPointer? = nil, queue: DispatchQueue = DispatchQueue.main, resultHandler: GraphQLResultHandler<Query.Data>? = nil) -> Cancellable |
| 74 | +``` |
| 75 | + |
| 76 | +> Fetches a query from the server or from the local cache, depending on the current contents of the cache and the specified cache policy. |
| 77 | +> |
| 78 | +> - Parameters: |
| 79 | +> - query: The query to fetch. |
| 80 | +> - cachePolicy: A cache policy that specifies when results should be fetched from the server and when data should be loaded from the local cache. |
| 81 | +> - queue: A dispatch queue on which the result handler will be called. Defaults to the main queue. |
| 82 | +> - resultHandler: An optional closure that is called when query results are available or when an error occurs. |
| 83 | +> - Returns: An object that can be used to cancel an in progress fetch. |
| 84 | + |
| 85 | +#### Parameters |
| 86 | + |
| 87 | +| Name | Description | |
| 88 | +| ---- | ----------- | |
| 89 | +| query | The query to fetch. | |
| 90 | +| cachePolicy | A cache policy that specifies when results should be fetched from the server and when data should be loaded from the local cache. | |
| 91 | +| queue | A dispatch queue on which the result handler will be called. Defaults to the main queue. | |
| 92 | +| resultHandler | An optional closure that is called when query results are available or when an error occurs. | |
| 93 | + |
| 94 | +### `watch(query:cachePolicy:queue:resultHandler:)` |
| 95 | + |
| 96 | +```swift |
| 97 | +public func watch<Query: GraphQLQuery>(query: Query, cachePolicy: CachePolicy = .returnCacheDataElseFetch, queue: DispatchQueue = DispatchQueue.main, resultHandler: @escaping GraphQLResultHandler<Query.Data>) -> GraphQLQueryWatcher<Query> |
| 98 | +``` |
| 99 | + |
| 100 | +> 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. |
| 101 | +> |
| 102 | +> - Parameters: |
| 103 | +> - query: The query to fetch. |
| 104 | +> - fetchHTTPMethod: The HTTP Method to be used. |
| 105 | +> - cachePolicy: A cache policy that specifies when results should be fetched from the server or from the local cache. |
| 106 | +> - queue: A dispatch queue on which the result handler will be called. Defaults to the main queue. |
| 107 | +> - resultHandler: An optional closure that is called when query results are available or when an error occurs. |
| 108 | +> - Returns: A query watcher object that can be used to control the watching behavior. |
| 109 | + |
| 110 | +#### Parameters |
| 111 | + |
| 112 | +| Name | Description | |
| 113 | +| ---- | ----------- | |
| 114 | +| query | The query to fetch. | |
| 115 | +| fetchHTTPMethod | The HTTP Method to be used. | |
| 116 | +| cachePolicy | A cache policy that specifies when results should be fetched from the server or from the local cache. | |
| 117 | +| queue | A dispatch queue on which the result handler will be called. Defaults to the main queue. | |
| 118 | +| resultHandler | An optional closure that is called when query results are available or when an error occurs. | |
| 119 | + |
| 120 | +### `perform(mutation:context:queue:resultHandler:)` |
| 121 | + |
| 122 | +```swift |
| 123 | +@discardableResult public func perform<Mutation: GraphQLMutation>(mutation: Mutation, context: UnsafeMutableRawPointer? = nil, queue: DispatchQueue = DispatchQueue.main, resultHandler: GraphQLResultHandler<Mutation.Data>? = nil) -> Cancellable |
| 124 | +``` |
| 125 | + |
| 126 | +> Performs a mutation by sending it to the server. |
| 127 | +> |
| 128 | +> - Parameters: |
| 129 | +> - mutation: The mutation to perform. |
| 130 | +> - fetchHTTPMethod: The HTTP Method to be used. |
| 131 | +> - queue: A dispatch queue on which the result handler will be called. Defaults to the main queue. |
| 132 | +> - resultHandler: An optional closure that is called when mutation results are available or when an error occurs. |
| 133 | +> - Returns: An object that can be used to cancel an in progress mutation. |
| 134 | + |
| 135 | +#### Parameters |
| 136 | + |
| 137 | +| Name | Description | |
| 138 | +| ---- | ----------- | |
| 139 | +| mutation | The mutation to perform. | |
| 140 | +| fetchHTTPMethod | The HTTP Method to be used. | |
| 141 | +| queue | A dispatch queue on which the result handler will be called. Defaults to the main queue. | |
| 142 | +| resultHandler | An optional closure that is called when mutation results are available or when an error occurs. | |
| 143 | + |
| 144 | +### `subscribe(subscription:queue:resultHandler:)` |
| 145 | + |
| 146 | +```swift |
| 147 | +@discardableResult public func subscribe<Subscription: GraphQLSubscription>(subscription: Subscription, queue: DispatchQueue = DispatchQueue.main, resultHandler: @escaping GraphQLResultHandler<Subscription.Data>) -> Cancellable |
| 148 | +``` |
| 149 | + |
| 150 | +> Subscribe to a subscription |
| 151 | +> |
| 152 | +> - Parameters: |
| 153 | +> - subscription: The subscription to subscribe to. |
| 154 | +> - fetchHTTPMethod: The HTTP Method to be used. |
| 155 | +> - queue: A dispatch queue on which the result handler will be called. Defaults to the main queue. |
| 156 | +> - resultHandler: An optional closure that is called when mutation results are available or when an error occurs. |
| 157 | +> - Returns: An object that can be used to cancel an in progress subscription. |
| 158 | + |
| 159 | +#### Parameters |
| 160 | + |
| 161 | +| Name | Description | |
| 162 | +| ---- | ----------- | |
| 163 | +| subscription | The subscription to subscribe to. | |
| 164 | +| fetchHTTPMethod | The HTTP Method to be used. | |
| 165 | +| queue | A dispatch queue on which the result handler will be called. Defaults to the main queue. | |
| 166 | +| resultHandler | An optional closure that is called when mutation results are available or when an error occurs. | |
0 commit comments