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

Link options not being passed to HttpLink constructor #3447

Closed
corydeppen opened this issue May 12, 2018 · 2 comments
Closed

Link options not being passed to HttpLink constructor #3447

corydeppen opened this issue May 12, 2018 · 2 comments
Labels
🚧 in-triage Issue currently being triaged

Comments

@corydeppen
Copy link

Intended outcome:

I've run into an issue while trying to pass a custom fetch function to allow a client to play nice with IE 11. After a little digging, it appears as though the fetch function never actually gets passed to HttpLink, since fetchOptions is passed but never spread to set fetch. I think part of the confusion may be related to the naming of the fetchOptions property on the PresetConfig interface. Seems like a more appropriate name might be linkOptions, since HttpLink.Options contains both fetch and fetchOptions properties.

Actual outcome:

Receive a console error:

fetch is not found globally and no fetcher passed, to fix pass a fetch for
your environment like https://www.npmjs.com/package/unfetch.
For example:
import fetch from 'unfetch';
import { createHttpLink } from 'apollo-link-http';
const link = createHttpLink({ uri: '/graphql', fetch: fetch });

How to reproduce the issue:

import ApolloClient from 'apollo-boost';
import fetch from 'unfetch';
// Produces an error on IE 11.
const client = new ApolloClient({
  fetchOptions: { fetch },
  uri: process.env.GRAPHQL_API_URL,
});

I think one solution to resolving my issue and a few other issues and PRs related to setting the credentials property may be to simply spread the fetchOptions/linkOptions to overwrite the default values if they exist on the config object.

export interface PresetConfig {
  request?: (operation: Operation) => Promise<void>;
  uri?: string;
--  fetchOptions?: HttpLink.Options;
++  linkOptions?: HttpLink.Options;
  clientState?: ClientStateConfig;
  onError?: ErrorLink.ErrorHandler;
  cacheRedirects?: CacheResolverMap;
}

constructor(config: PresetConfig) {
  // ...
  const httpLink = new HttpLink({
++  credentials: 'same-origin',
--  uri: (config && config.uri) || '/graphql',
++  uri: '/graphql',
--  fetchOptions: (config && config.fetchOptions) || {},
++  ...config,
--  credentials: 'same-origin',
  });
  // ...
}

Version

  • apollo-client@2.3.1
@alexkubica
Copy link

I'm having the same issue, was it fixed?
I tried passing a link created by createHttpLink but it has issues too (it ignore the given uri).

@hwillson hwillson added the 🚧 in-triage Issue currently being triaged label Jul 9, 2019
@hwillson
Copy link
Member

hwillson commented Jul 9, 2019

This issue has been fixed in modern versions of Apollo Client. Thanks!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
🚧 in-triage Issue currently being triaged
Projects
None yet
Development

No branches or pull requests

3 participants