Graphql Error: Network Request Failed only in Android

2.1k views Asked by At

All my queries work well in iOS but give a network request failed error in Android. Some other SO and GitHub solutions suggest that I shouldn't be using localhost for my uri and should use my computer's IP address. But I am already not using localhost.

const httpLink = createHttpLink({
    uri: 'https://gateway_dev.companyName.en/v1/graphql',
  });

  const authLink = setContext(async (_, { headers }) => {
    const token = await auth().currentUser?.getIdToken();
    return {
      headers: {
        ...headers,
        authorization: token ? `Bearer ${token}` : '',
      },
    };
  });

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

  return (
    <Provider store={store}>
        <ApolloProvider client={client}>
...

The uri I am using is the Graphql Endpoint POST url from my Hasura console. I am testing by using an Android emulator from the Android Studio and not on a real device. What else could I try?

I also tried adding this android:usesCleartextTraffic="true" to AndroidManifest.xml file but it doesn't make a difference.

0

There are 0 answers