ember-graphql / ember-apollo-client

🚀 An ember-cli addon for Apollo Client and GraphQL
MIT License
280 stars 72 forks source link

ember-fetch polyfill causing error with default settings #366

Open brandonmarino opened 4 years ago

brandonmarino commented 4 years ago

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.

alexhancock commented 4 years ago

:+1:

Does anyone have thoughts on this?

josemarluedke commented 3 years ago

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.

levimoore commented 3 years ago

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
    },