ember-apollo-client icon indicating copy to clipboard operation
ember-apollo-client copied to clipboard

ember-fetch polyfill causing error with default settings

Open brandonmarino opened this issue 5 years ago • 3 comments

Hey there!

Following the base configuration guide in the readme with a vanilla ember octane project leads to the following error:

image

We narrowed the cause down to ember-fetch. We found this closed issue on their git being discussed with a solution: https://github.com/ember-cli/ember-fetch/issues/45#issuecomment-448689032

Tested that solution with our project and it's working.

So, from what I can gather, the issue either exists within ember-fetch OR with how ember-apollo-client configures ember-fetch. Or perhaps this is just a case of a missing step in the docs.

brandonmarino avatar Aug 12 '20 21:08 brandonmarino

:+1:

Does anyone have thoughts on this?

alexhancock avatar Aug 14 '20 17:08 alexhancock

This is interesting. Assuming you are doing the prefer native option, I think you would need to overwrite the default link options to pass a different fetch.

It would look something like this:


import ApolloService from 'ember-apollo-client/services/apollo';
import { createHttpLink } from '@apollo/client/core';
import { isPresent } from '@ember/utils';

class OverriddenApolloService extends ApolloService {
  link() {
    const { apiURL, requestCredentials } = this.options;
    const linkOptions = { uri: apiURL, fetch };

    if (isPresent(requestCredentials)) {
      linkOptions.credentials = requestCredentials;
    }
    return createHttpLink(linkOptions);
  }
}

Let me know if this helps.

josemarluedke avatar Oct 14 '20 19:10 josemarluedke

If anyone ends up here because of the above error, adding this to your ember-cli-build.js file will fix it.

  let app = new EmberApp(defaults, {
    'ember-fetch': {
      preferNative: true
    },

levimoore avatar Nov 15 '20 18:11 levimoore