react-native-fullstack-graphql
react-native-fullstack-graphql copied to clipboard
Conditionally set HttpLink URI
There is an issue with fetch in React Native that prevents the usage of localhost
.
A proposed solution is to use Platform.select
to set the ApolloClient's HttpLink
uri to one of several options:
const SERVER_URL = __DEV__
? Platform.select({
ios: 'GET_USERS_IP_ADDRESS_AND_APPEND_PORT_4000',
android: 'http://10.0.2.2:4000'
})
: 'USE_PRODUCTION_GRAPHQL_SERVER_ENV_VAR';
Android apparently allows 10.0.2.2 to equal localhost, but I haven't confirmed this myself.
Alright will handle this asap
Well android does not really, except you are using an emulator. For real device its different, it is based on the ip of the wifi connection which changes every time it restarts. But I will have a fix for that
Is 127.0.0.1
supported instead, @DevanB?
@marktani - apparently, no. It has to do with proxying through with Expo.
@DevanB did you end up finding a solution to this?
@devomacdee unfortunately, no. I haven’t necessarily worked on it much too. The crux of the solution I proposed is figuring out the developer’s IP address when the env is development (don’t worry about production since that should be a separate url for a server).