响应不成功:使用apolloclient graphql reactNative收到状态代码500

vbopmzt1  于 2022-12-14  发布在  React
关注(0)|答案(1)|浏览(211)
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()
})

当我在头中添加authorizan时,我得到了这个错误:响应不成功:接收到状态代码500在React Native中,否则它的工作很好。这里的问题是什么?

ulydmbyx

ulydmbyx1#

你能尝试一下异步函数的then函数吗

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

相关问题