在使用 Apollo GraphQL 时,需要在每个请求的头部中包含一个验证令牌。在 iOS Swift 中,您可以使用 ApolloProvider 实例中提供的 httpClient 来设置头部信息。如下所示:
import Apollo
import Alamofire
let token = "your-auth-token"
let configuration = URLSessionConfiguration.default
configuration.httpAdditionalHeaders = ["Authorization": "Bearer \(token)"]
let httpClient = Alamofire.Session(configuration: configuration)
let apollo = ApolloClient(networkTransport: HTTPNetworkTransport(httpClient: httpClient, url: yourGraphQLServerURL))
这样,每个请求都会包含一个名为 'Authorization” 的头部,其值为您的验证令牌。
上一篇:ApolloGraphQL停止报告Opentelemetry跟踪,因为存在不安全的调用。
下一篇:ApollographqluseMutationwouldtriggerthecomponenttore-render。