如何在Apollo GraphQL中添加标题:iOS

编程入门 行业动态 更新时间:2024-10-10 00:22:36
本文介绍了如何在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

本文发布于:2023-11-28 19:04:17,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1643595.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:标题   如何在   GraphQL   Apollo   iOS

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!