【发布时间】: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 代码块并引发网络错误。
【问题讨论】:
-
也许有帮助 [link] (github.com/apollographql/apollo-client/issues/…)
-
谢谢,这与我的解决方案相同,但更好的解决方案是通过网络安全配置文件。
标签: react-native graphql apollo react-apollo apollo-client