/ react-nativeapollographql

React native with Apollo Graphql works on iOS but not on Android

I am developing a React Native application that uses Graphql to communicate to a Ruby on Rails server. I'm using the amazing Apollo library for this purpose.

The app was working without problems on iOS but when I started expo to run the app on my android phone I had this weird error:

Unhandled (in react-apollo:Apollo(Translate(LandmarksList))), ApolloError@\_modules/react-native-scripts/build/bin/crna-entry.delta?platform=android&dev=true&minify=false:103922:40 currentResult@\_modules/react-native-scripts/build/bin/crna-entry.delta?platform=android&dev=true&minify=false:104057:47 dataForChild@\_modules/react-native-scripts/build/bin/crna-entry.delta?platform=android&dev=true&minify=false:103034:83 render@\_modules/react-native-scripts/build/bin/crna-entry.delta?platform=android&dev=true&minify=false:103103:53 finishClassComponent@\_modules/react-native-scripts/build/bin/crna-entry.delta?platform=android&dev=true&minify=false:8026:43 updateClassComponent@\_modules/react-native-scripts/build/bin/crna-entry.delta?platform=android&dev=true&minify=false:8007:38

After spending some time debugging and googling about the problem it turns out to be the link to the graphql server (a Ruby on Rails app in my case).

iOS simulator uses the same IP as the host whereas android doesn't so the solution was as simple as updating the IP of the graphql server:

const httpLink = new HttpLink({ uri: ''});

You probably have localhost or your local IP on the uri field. If you change it to the IP that is being used by react native then it will work. Tip: You can see your own IP address checking the errors in the log:ApolloError@