本文介绍了如何在Apollo GraphQL中添加标题:iOS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
为什么我在使用 Apollo GraphQL 方法的项目中工作正常.但是现在,客户端需要使用Apollo API添加其他标头.但是添加标头后,API的响应将返回为 unAuthorized .
Hy I am working in a project with Apollo GraphQL method and its working fine. But now the client required for adding additional header with Apollo API's. But after adding the header the API's response return as unAuthorized.
我将标题添加为
let apolloAuth: ApolloClient = { let configuration = URLSessionConfiguration.default // Add additional headers as needed configuration.httpAdditionalHeaders = ["Authorization" : self.singleTonInstance.token] configuration.httpAdditionalHeaders = ["channel" : "mobile"] let url = URL(string: "xxx/graphql")! return ApolloClient(networkTransport: HTTPNetworkTransport(url: url, configuration: configuration)) }()任何人都可以帮助我了解如何使用Apollo GraphQL添加标头.
Anyone please help me to find out how to add headers with Apollo GraphQL.
推荐答案最后我找到了答案.通过以下方式添加标题,
Finally I found the answer. Add the header in the following way,
let apolloAuth: ApolloClient = { let configuration = URLSessionConfiguration.default let token = UserDefaults.standard.value(forKey: "token") // Add additional headers as needed configuration.httpAdditionalHeaders = ["authorization":"\(token!)", "channel":"mobile"] let url = URL(string: "xxxx/graphql")! return ApolloClient(networkTransport: HTTPNetworkTransport(url: url, configuration: configuration)) }()希望它将对某人有所帮助.
Hope it will help someone.
更多推荐
如何在Apollo GraphQL中添加标题:iOS
发布评论