【问题标题】:Graphql Network Error on release version of react-native android appreact-native android应用程序发布版本上的Graphql网络错误
【发布时间】:2020-02-19 12:30:18
【问题描述】:

我开发了一个使用 graphql 的 react-native android 应用程序,我可以连接到 graphql 服务器以及执行突变和查询,但只能在应用程序的调试版本上。当我构建应用程序的发布版本并在我的手机上运行它时,就会出现问题。在执行登录突变时,我面临
'networkError: ', '{"line":123,"column":7285,"sourceURL":"index.android.bundle"}'

Graphql 初始化代码,

const httpLink = createHttpLink({
  uri: 'https://<IP>:4050'
})

const authLink = setContext((_, { headers }) => {
  getMyValue(AUTH_TOKEN)
  return {
    headers: {
      ...headers,
      authorization: token ? `Bearer ${token}` : ''
  }
})

const client = new ApolloClient({
  link: authLink.concat(httpLink),
  cache: new InMemoryCache()
})

这是引发错误的组件,

<Mutation
                mutation={gql`
                  mutation login($username:String!,$password:String!){
                    login(username:$username,password:$password)
                  }
                `}
                variables={{ username, password }}
                onError={(err) => {
                  console.log('err: ', err);
                }}
                onCompleted={data => {...}}
              >
                {mutation => (
                  <Button full style={styles.loginButton}
                    onPress={() => {
                        mutation()
                    }}>
                      <Text>Login</Text>
                  </Button>
                )}
              </Mutation>

在应用程序的调试版本上,它转到 onCompleted 代码块,这也是我想要的应用程序的发布版本。相反,在应用程序的发布版本中,它会转到 onError 代码块并引发网络错误。

【问题讨论】:

标签: react-native graphql apollo react-apollo apollo-client


【解决方案1】:

在你的 android manifest 应用标签中添加这一行

android:usesCleartextTraffic="true"

【讨论】:

    猜你喜欢
    • 2019-11-28
    • 2018-10-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-08-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多