Relay: [relay-runtime] TypeError: fetch is not a function

Created on 1 Jul 2017  路  3Comments  路  Source: facebook/relay

I try to use whatwg-fetchand babel-polyfill. It is still not working. I had checked fetch does work in my browser, but it is not working in relay-runtime.

Uncaught TypeError: fetch is not a function
    at Object.requestStream (index.js:70194)
    at RelayModernEnvironment.streamQuery (index.js:69649)
    at ReactRelayQueryRenderer._fetch (index.js:65522)
    at new ReactRelayQueryRenderer (index.js:65382)
    at common.js:26301
    at measureLifeCyclePerf (common.js:26082)
    at ReactCompositeComponentWrapper._constructComponentWithoutOwner (common.js:26300)
    at ReactCompositeComponentWrapper._constructComponent (common.js:26286)
    at ReactCompositeComponentWrapper.mountComponent (common.js:26194)
    at Object.mountComponent (common.js:5603)

All 3 comments

I solve the problem.

How did you solve the problem, brother?

I forgot do this:

function fetchQuery(
  operation,
  variables,
  cacheConfig,
  uploadables,
) {
  return fetch('/graphql', {
    method: 'POST',
    headers: {
      // Add authentication and other headers here
      'content-type': 'application/json'
    },
    body: JSON.stringify({
      query: operation.text, // GraphQL text from input
      variables,
    }),
  }).then(response => {
    return response.json();
  });
}

I just added this to my Environment. You can see here.

Was this page helpful?
0 / 5 - 0 ratings