I'm trying to run tests with apollo against my server.
I'm getting this error with some hints.
Invariant Violation:
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 });
19 |
20 | beforeAll(async () => {
> 21 | client = new ApolloClient({ uri: "http://localhost:3000", fetch });
| ^
This hint does not help at all, because even if I new to apollo, I can create this link, but I have no Idea where to put it..
Moreover, I'm passing fetch as argument and it should fit, but it doesn't.
export default class DefaultClient<TCache> extends ApolloClient<TCache> {
constructor(config?: PresetConfig);
}
export interface PresetConfig {
request?: (operation: Operation) => Promise<void>;
uri?: string;
credentials?: string;
headers?: any;
fetch?: GlobalFetch['fetch'];
fetchOptions?: HttpLink.Options;
clientState?: ClientStateConfig;
onError?: ErrorLink.ErrorHandler;
cacheRedirects?: CacheResolverMap;
cache?: ApolloCache<any>;
name?: string;
version?: string;
resolvers?: Resolvers | Resolvers[];
typeDefs?: string | string[] | DocumentNode | DocumentNode[];
fragmentMatcher?: LocalStateFragmentMatcher;
}
System:
OS: macOS 10.14.3
Binaries:
Node: 11.6.0 - /usr/local/bin/node
Yarn: 1.13.0 - /usr/local/bin/yarn
npm: 6.5.0 - /usr/local/bin/npm
Browsers:
Chrome: 73.0.3683.86
Safari: 12.0.3
npmPackages:
apollo-boost: ^0.3.1 => 0.3.1
Issues here are reserved for Apollo Client bugs. You鈥檒l have a much better chance of getting this answered in Apollo鈥檚 Spectrum community or on Stack Overflow. Thanks!