question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue

This is really strange and demotivating using Apollo from the very beginning.

Here is your docs:

The only thing you need to get started is the endpoint for your GraphQL server. If you don’t pass in uri directly, it defaults to the /graphql endpoint on the same host your app is served from.

I pass the only thing and your package throws you must specify link & cache properties on the config object. How can it be?

Intended outcome: Working client, working app, no erros thrown

Actual outcome:

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.

How to reproduce the issue:

import { ApolloProvider } from 'react-apollo';
import { ApolloClient } from 'apollo-boost';

render() {
      const apolloClient = new ApolloClient({
          uri: AppSync.graphqlEndpoint,
      });
    return (
        <ApolloProvider client={apolloClient}>
            ... app
        </ApolloProvider>
    )
}

Versions System: OS: macOS High Sierra 10.13.4 Binaries: Node: 8.11.3 - /usr/local/bin/node npm: 5.6.0 - /usr/local/bin/npm Browsers: Chrome: 67.0.3396.99 Safari: 11.1 npmPackages: apollo-boost: ^0.1.4 => 0.1.5 apollo-cache-inmemory: ^1.1.0 => 1.2.0 apollo-client: ^2.0.3 => 2.3.0 apollo-link: ^1.0.3 => 1.2.2 apollo-link-http: ^1.2.0 => 1.5.4 react-apollo: ^2.1.1 => 2.1.3

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:39
  • Comments:28 (5 by maintainers)

github_iconTop GitHub Comments

173reactions
hwillsoncommented, Jul 1, 2018

Switch:

import { ApolloClient } from 'apollo-boost';

to

import ApolloClient from 'apollo-boost';

If you do that you’ll then be using the apollo-boost version of Apollo Client, which doesn’t require you to specify a link/cache. You’re encountering this error because apollo-boost also exports the full version of apollo-client, as a named export, for backwards compatibility reasons. So you’re referencing the full apollo-client, which requires you to pass in a link/cache.

Sorry for the confusion! We know this can be a problem, and are planning on changing this around in the future. Thanks!

43reactions
underbluewaterscommented, Nov 25, 2018

I’ve run into so many problems with that tutorial. It makes me reconsider whether to use this library at all.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Configuring the Apollo Client cache - Apollo GraphQL Docs
Create an InMemoryCache object and provide it to the ApolloClient constructor, ... You can configure the cache's behavior to better suit your application....
Read more >
ApolloClient: Invariant Violation 1 – setup apollo client properly
In order to initialize Apollo Client, you must specify 'link' and 'cache' properties in the options object. These options are part of the ......
Read more >
Invariant Violation: In order to initialize Apollo Client, you must ...
Invariant Violation: In order to initialize Apollo Client, you must specify 'link' and 'cache' properties in the options object in Unit Test ...
Read more >
Configure Apollo Client for React and GitHub's GraphQL API
To initialize Apollo Client, you must specify link and cache properties on the config object. Run the application below to verify the configuration...
Read more >
Configuring the Cache – Angular - GraphQL Code Generator
As of Apollo Client 3.0, the InMemoryCache class is provided by the @apollo/client package. No additional libraries are required. Initialization.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found