使用Android模拟器或真机测试时,Apollo client的localhost必须是计算机上的IP地址。例如,如果你的计算机IP地址是192.168.0.100,则应在Apollo client的uri中使用http://192.168.0.100:4000/graphql,而不是http://localhost:4000/graphql。以下代码示例展示了如何在React Native中设置Apollo client URI:
import ApolloClient from 'apollo-boost';
const client = new ApolloClient({
uri: 'http://192.168.0.100:4000/graphql'
});