Apollo GraphQL Client does not work on release build in react native

Viewed 260

it's been around two weeks that I'm dealing with this problem. at first, it did not work at all. After spending several days searching for a solution I could fix it by adding these lines of code to my index.js file.

XMLHttpRequest = GLOBAL.originalXMLHttpRequest ?
    GLOBAL.originalXMLHttpRequest :
    GLOBAL.XMLHttpRequest;
    global.Blob = null

After that, it worked fine in the development mode and everything was fine. But as soon as I released my app I realized it does not work in the release build!

I'm kind of sure it's a problem with fetch API that apollo uses behind the scenes. But I don't know what to do to fix it.

I also tried to run a new project and paste my code on it, but no luck.

this is my apollo client code:

import ApolloClient from 'apollo-client'
import Statics from './statics'
import {HttpLink} from 'apollo-link-http'
import { InMemoryCache } from '@apollo/client';

const customFetch = (uri, options) => {
  return fetch(uri, options)
  .then(response => {
    if (response.status >= 500) {  // or handle 400 errors
      return Promise.reject(response.status);
    }
    return response;
  });
};
export const client = new ApolloClient({
  link: new HttpLink({uri:`${Statics.baseUrl}/graphql`, fetch:customFetch}) ,
  cache: new InMemoryCache(),
    }); 
1 Answers

Try using isomorphic-fetch instead of fetch

Related