@@ -76,21 +76,22 @@ public class ApolloClient {
7676 ///
7777 /// - Parameters:
7878 /// - query: The query to fetch.
79+ /// - fetchHTTPMethod: The HTTP Method to be used.
7980 /// - cachePolicy: A cache policy that specifies when results should be fetched from the server and when data should be loaded from the local cache.
8081 /// - queue: A dispatch queue on which the result handler will be called. Defaults to the main queue.
8182 /// - resultHandler: An optional closure that is called when query results are available or when an error occurs.
8283 /// - Returns: An object that can be used to cancel an in progress fetch.
83- @discardableResult public func fetch< Query: GraphQLQuery > ( query: Query , cachePolicy: CachePolicy = . returnCacheDataElseFetch, queue: DispatchQueue = DispatchQueue . main, resultHandler: OperationResultHandler < Query > ? = nil ) -> Cancellable {
84- return _fetch ( query: query, cachePolicy: cachePolicy, queue: queue, resultHandler: resultHandler)
84+ @discardableResult public func fetch< Query: GraphQLQuery > ( query: Query , fetchHTTPMethod : FetchHTTPMethod = . POST , cachePolicy: CachePolicy = . returnCacheDataElseFetch, queue: DispatchQueue = DispatchQueue . main, resultHandler: OperationResultHandler < Query > ? = nil ) -> Cancellable {
85+ return _fetch ( query: query, fetchHTTPMethod : fetchHTTPMethod , cachePolicy: cachePolicy, queue: queue, resultHandler: resultHandler)
8586 }
8687
87- func _fetch< Query: GraphQLQuery > ( query: Query , cachePolicy: CachePolicy , context: UnsafeMutableRawPointer ? = nil , queue: DispatchQueue , resultHandler: OperationResultHandler < Query > ? ) -> Cancellable {
88+ func _fetch< Query: GraphQLQuery > ( query: Query , fetchHTTPMethod : FetchHTTPMethod , cachePolicy: CachePolicy , context: UnsafeMutableRawPointer ? = nil , queue: DispatchQueue , resultHandler: OperationResultHandler < Query > ? ) -> Cancellable {
8889 // If we don't have to go through the cache, there is no need to create an operation
8990 // and we can return a network task directly
9091 if cachePolicy == . fetchIgnoringCacheData {
91- return send ( operation: query, context: context, handlerQueue: queue, resultHandler: resultHandler)
92+ return send ( operation: query, fetchHTTPMethod : fetchHTTPMethod , context: context, handlerQueue: queue, resultHandler: resultHandler)
9293 } else {
93- let operation = FetchQueryOperation ( client: self , query: query, cachePolicy: cachePolicy, context: context, handlerQueue: queue, resultHandler: resultHandler)
94+ let operation = FetchQueryOperation ( client: self , query: query, fetchHTTPMethod : fetchHTTPMethod , cachePolicy: cachePolicy, context: context, handlerQueue: queue, resultHandler: resultHandler)
9495 operationQueue. addOperation ( operation)
9596 return operation
9697 }
@@ -100,12 +101,13 @@ public class ApolloClient {
100101 ///
101102 /// - Parameters:
102103 /// - query: The query to fetch.
104+ /// - fetchHTTPMethod: The HTTP Method to be used.
103105 /// - cachePolicy: A cache policy that specifies when results should be fetched from the server or from the local cache.
104106 /// - queue: A dispatch queue on which the result handler will be called. Defaults to the main queue.
105107 /// - resultHandler: An optional closure that is called when query results are available or when an error occurs.
106108 /// - Returns: A query watcher object that can be used to control the watching behavior.
107- public func watch< Query: GraphQLQuery > ( query: Query , cachePolicy: CachePolicy = . returnCacheDataElseFetch, queue: DispatchQueue = DispatchQueue . main, resultHandler: @escaping OperationResultHandler < Query > ) -> GraphQLQueryWatcher < Query > {
108- let watcher = GraphQLQueryWatcher ( client: self , query: query, handlerQueue: queue, resultHandler: resultHandler)
109+ public func watch< Query: GraphQLQuery > ( query: Query , fetchHTTPMethod : FetchHTTPMethod = . POST , cachePolicy: CachePolicy = . returnCacheDataElseFetch, queue: DispatchQueue = DispatchQueue . main, resultHandler: @escaping OperationResultHandler < Query > ) -> GraphQLQueryWatcher < Query > {
110+ let watcher = GraphQLQueryWatcher ( client: self , query: query, fetchHTTPMethod : fetchHTTPMethod , handlerQueue: queue, resultHandler: resultHandler)
109111 watcher. fetch ( cachePolicy: cachePolicy)
110112 return watcher
111113 }
@@ -114,30 +116,32 @@ public class ApolloClient {
114116 ///
115117 /// - Parameters:
116118 /// - mutation: The mutation to perform.
119+ /// - fetchHTTPMethod: The HTTP Method to be used.
117120 /// - queue: A dispatch queue on which the result handler will be called. Defaults to the main queue.
118121 /// - resultHandler: An optional closure that is called when mutation results are available or when an error occurs.
119122 /// - Returns: An object that can be used to cancel an in progress mutation.
120- @discardableResult public func perform< Mutation: GraphQLMutation > ( mutation: Mutation , queue: DispatchQueue = DispatchQueue . main, resultHandler: OperationResultHandler < Mutation > ? = nil ) -> Cancellable {
121- return _perform ( mutation: mutation, queue: queue, resultHandler: resultHandler)
123+ @discardableResult public func perform< Mutation: GraphQLMutation > ( mutation: Mutation , fetchHTTPMethod : FetchHTTPMethod = . POST , queue: DispatchQueue = DispatchQueue . main, resultHandler: OperationResultHandler < Mutation > ? = nil ) -> Cancellable {
124+ return _perform ( mutation: mutation, fetchHTTPMethod : fetchHTTPMethod , queue: queue, resultHandler: resultHandler)
122125 }
123126
124- func _perform< Mutation: GraphQLMutation > ( mutation: Mutation , context: UnsafeMutableRawPointer ? = nil , queue: DispatchQueue , resultHandler: OperationResultHandler < Mutation > ? ) -> Cancellable {
125- return send ( operation: mutation, context: context, handlerQueue: queue, resultHandler: resultHandler)
127+ func _perform< Mutation: GraphQLMutation > ( mutation: Mutation , fetchHTTPMethod : FetchHTTPMethod , context: UnsafeMutableRawPointer ? = nil , queue: DispatchQueue , resultHandler: OperationResultHandler < Mutation > ? ) -> Cancellable {
128+ return send ( operation: mutation, fetchHTTPMethod : fetchHTTPMethod , context: context, handlerQueue: queue, resultHandler: resultHandler)
126129 }
127130
128131 /// Subscribe to a subscription
129132 ///
130133 /// - Parameters:
131134 /// - subscription: The subscription to subscribe to.
135+ /// - fetchHTTPMethod: The HTTP Method to be used.
132136 /// - queue: A dispatch queue on which the result handler will be called. Defaults to the main queue.
133137 /// - resultHandler: An optional closure that is called when mutation results are available or when an error occurs.
134138 /// - Returns: An object that can be used to cancel an in progress subscription.
135- @discardableResult public func subscribe< Subscription: GraphQLSubscription > ( subscription: Subscription , queue: DispatchQueue = DispatchQueue . main, resultHandler: @escaping OperationResultHandler < Subscription > ) -> Cancellable {
136- return send ( operation: subscription, context: nil , handlerQueue: queue, resultHandler: resultHandler)
139+ @discardableResult public func subscribe< Subscription: GraphQLSubscription > ( subscription: Subscription , fetchHTTPMethod : FetchHTTPMethod = . POST , queue: DispatchQueue = DispatchQueue . main, resultHandler: @escaping OperationResultHandler < Subscription > ) -> Cancellable {
140+ return send ( operation: subscription, fetchHTTPMethod : fetchHTTPMethod , context: nil , handlerQueue: queue, resultHandler: resultHandler)
137141 }
138142
139143
140- fileprivate func send< Operation: GraphQLOperation > ( operation: Operation , context: UnsafeMutableRawPointer ? , handlerQueue: DispatchQueue , resultHandler: OperationResultHandler < Operation > ? ) -> Cancellable {
144+ fileprivate func send< Operation: GraphQLOperation > ( operation: Operation , fetchHTTPMethod : FetchHTTPMethod , context: UnsafeMutableRawPointer ? , handlerQueue: DispatchQueue , resultHandler: OperationResultHandler < Operation > ? ) -> Cancellable {
141145 func notifyResultHandler( result: GraphQLResult < Operation . Data > ? , error: Error ? ) {
142146 guard let resultHandler = resultHandler else { return }
143147
@@ -146,7 +150,7 @@ public class ApolloClient {
146150 }
147151 }
148152
149- return networkTransport. send ( operation: operation) { ( response, error) in
153+ return networkTransport. send ( operation: operation, fetchHTTPMethod : fetchHTTPMethod ) { ( response, error) in
150154 guard let response = response else {
151155 notifyResultHandler ( result: nil , error: error)
152156 return
@@ -175,16 +179,18 @@ public class ApolloClient {
175179private final class FetchQueryOperation < Query: GraphQLQuery > : AsynchronousOperation , Cancellable {
176180 let client : ApolloClient
177181 let query : Query
182+ let fetchHTTPMethod : FetchHTTPMethod
178183 let cachePolicy : CachePolicy
179184 let context : UnsafeMutableRawPointer ?
180185 let handlerQueue : DispatchQueue
181186 let resultHandler : OperationResultHandler < Query > ?
182187
183188 private var networkTask : Cancellable ?
184189
185- init ( client: ApolloClient , query: Query , cachePolicy: CachePolicy , context: UnsafeMutableRawPointer ? , handlerQueue: DispatchQueue , resultHandler: OperationResultHandler < Query > ? ) {
190+ init ( client: ApolloClient , query: Query , fetchHTTPMethod : FetchHTTPMethod , cachePolicy: CachePolicy , context: UnsafeMutableRawPointer ? , handlerQueue: DispatchQueue , resultHandler: OperationResultHandler < Query > ? ) {
186191 self . client = client
187192 self . query = query
193+ self . fetchHTTPMethod = fetchHTTPMethod
188194 self . cachePolicy = cachePolicy
189195 self . context = context
190196 self . handlerQueue = handlerQueue
@@ -230,7 +236,7 @@ private final class FetchQueryOperation<Query: GraphQLQuery>: AsynchronousOperat
230236 }
231237
232238 func fetchFromNetwork( ) {
233- networkTask = client. send ( operation: query, context: context, handlerQueue: handlerQueue) { ( result, error) in
239+ networkTask = client. send ( operation: query, fetchHTTPMethod : fetchHTTPMethod , context: context, handlerQueue: handlerQueue) { ( result, error) in
234240 self . notifyResultHandler ( result: result, error: error)
235241 self . state = . finished
236242 return
0 commit comments