Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ember-fetch polyfill causing error with default settings #366

Open
brandonmarino opened this issue Aug 12, 2020 · 3 comments
Open

ember-fetch polyfill causing error with default settings #366

brandonmarino opened this issue Aug 12, 2020 · 3 comments

Comments

@brandonmarino
Copy link

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: ember-cli/ember-fetch#45 (comment)

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
Copy link

👍

Does anyone have thoughts on this?

@josemarluedke
Copy link
Member

josemarluedke commented Oct 14, 2020

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
Copy link

levimoore commented Nov 15, 2020

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants