【问题标题】:Response not sucessful:Recevied status code 500 using apolloclient graphql reactNative响应不成功:使用 apollo 客户端 graphql reactNative 收到状态代码 500
【发布时间】:2022-12-20 04:27:22
【问题描述】:
when put token value as hardcoded it's work properly,but when i got token from asyncstorage and pass token in headers i got this error
Response not sucessful:Recevied status code 500 What is wrong in mycode?


import { ApolloClient,ApolloProvider,InMemoryCache,gql } from '@apollo/client'
import { createUploadLink } from 'apollo-upload-client'
 const getToken = async () => {
  const token = await AsyncStorage.getItem('@storage_Key')
  return token
}
const token = getToken()
const client = new ApolloClient({
  link: createUploadLink({
    uri: 'http://192.168.1.82:8080/graphql',
    headers: {
      authorization: token
    }
  }),
  cache: new InMemoryCache()
})

当我在标题中添加授权时,我得到了这个错误:响应不成功:收到状态代码 500 在 React native 中,否则它工作得很好。这里有什么问题?

【问题讨论】:

    标签: react-native graphql


    【解决方案1】:

    你能试试 async 函数的 then 函数吗

    getToken().then((token) => {
      const client = new ApolloClient({
        link: createUploadLink({
          uri: 'http://192.168.1.82:8080/graphql',
          headers: {
            authorization: token
          }
        }),
        cache: new InMemoryCache()
      });
    });
    

    【讨论】:

      猜你喜欢
      • 2019-04-27
      • 2019-02-16
      • 1970-01-01
      • 2019-07-28
      • 1970-01-01
      • 2020-12-27
      • 2018-02-14
      • 2019-06-17
      相关资源
      最近更新 更多