Apollo-client: In order to initialize Apollo Client, you must specify link & cache properties on the config

Created on 6 Dec 2018  路  5Comments  路  Source: apollographql/apollo-client

I was following along the documentation here https://www.apollographql.com/docs/tutorial/client.html, but I'm sure it's incorrect.

Intended outcome:
I was trying to following along with the documentation to connect my API to a client. I expected to be able to following the tutorial and get some sort of connection happening, but I can't.

Actual outcome:
I added the code as per the documentation:

import { ApolloClient } from "apollo-client";

const client = new ApolloClient({
  uri: "http://localhost:4000/graphql"
});

And then receive this issue.

Error: 
        In order to initialize Apollo Client, you must specify link & cache properties on the config object.
        This is part of the required upgrade when migrating from Apollo Client 1.0 to Apollo Client 2.0.
        For more information, please visit:
          https://www.apollographql.com/docs/react/basics/setup.html
        to help you get started.

This is also mentioned here https://github.com/apollographql/apollo-client/issues/3639 but it was closed prematurely in my opinion.

How to reproduce the issue:

import { ApolloClient } from 'apollo-client';

const client = new ApolloClient({ uri: 'http://localhost:4000/graphql' });

Versions

  System:
    OS: macOS 10.14.1
  Binaries:
    Node: 8.12.0 - ~/.nvm/versions/node/v8.12.0/bin/node
    Yarn: 1.10.1 - /usr/local/bin/yarn
    npm: 6.4.1 - ~/.nvm/versions/node/v8.12.0/bin/npm
  Browsers:
    Chrome: 70.0.3538.110
    Firefox: 62.0.3
    Safari: 12.0.1
  npmPackages:
    apollo-client: 2.5.0-alpha.1 => 2.5.0-alpha.1
    react-apollo: 2.3.2 => 2.3.2

Most helpful comment

a lot of the docs have been written with Apollo Client 3.0 in mind, where apollo-boost has been merged into core. however it hasn't yet been done, not even in alpha, so this is the problem when actually trying out whats in the docs. to fix, just import and use from apollo-boost for now.

import ApolloClient from 'apollo-boost';

const client = new ApolloClient({
  uri: 'http://localhost:4000/graphql' // no error
});

All 5 comments

you should import from apollo-boost:
import { ApolloClient } from 'apollo-boost';

but you are right doc seems incorrect

Yeah, I got it working. It's more an issue to fix the docs.

If you happen to see a problem with the docs, the "Edit on Github" button makes it easy to change them.

This one has an open PR: https://github.com/apollographql/apollo/pull/262

a lot of the docs have been written with Apollo Client 3.0 in mind, where apollo-boost has been merged into core. however it hasn't yet been done, not even in alpha, so this is the problem when actually trying out whats in the docs. to fix, just import and use from apollo-boost for now.

import ApolloClient from 'apollo-boost';

const client = new ApolloClient({
  uri: 'http://localhost:4000/graphql' // no error
});

Closing, since docs have been updated with apollographql/apollo#262 :

import { ApolloClient } from "apollo-client";
import { InMemoryCache } from 'apollo-cache-inmemory';
import { HttpLink } from 'apollo-link-http';

const cache = new InMemoryCache();
const client = new ApolloClient({
  cache,
  link: new HttpLink({
    uri: 'http://localhost:4000/graphql',
  }),
});
Was this page helpful?
0 / 5 - 0 ratings