7

I did this sample: https://github.com/Akryum/vueconf-2017-demo

As a result, I have the same file in my project: https://github.com/Akryum/vueconf-2017-demo/blob/master/src/apollo-client.js

This is the code used in my application:

import { ApolloClient, createNetworkInterface } from 'apollo-client'

const apolloClient = new ApolloClient({
  networkInterface: createNetworkInterface({
    uri: 'http://localhost:3000/graphql',
    transportBatching: true,
  }),
  connectToDevTools: true,
})

export default apolloClient

As a result, I get this error (warning) to the console:

warning  in ./src/apollo/client.js

15:23-45 "export 'createNetworkInterface' was not found in 'apollo-client'

And this is from the browser console:

TypeError: Object(__WEBPACK_IMPORTED_MODULE_0_apollo_client__["createNetworkInterface"]) is not a function. (In 'Object(__WEBPACK_IMPORTED_MODULE_0_apollo_client__["createNetworkInterface"])({
    uri: 'http://localhost:3000/graphql',
    transportBatching: true
  })', 'Object(__WEBPACK_IMPORTED_MODULE_0_apollo_client__["createNetworkInterface"])' is an instance of Object)

What is the problem?

Colibri
  • 993
  • 11
  • 29

2 Answers2

9

It looks like that repo hasn't been updated to use apollo-client's latest version. The Apollo client underwent major changes in version 2.0. You can see a summary of those changes and an upgrade guide here. One of the breaking changes implemented was a switch from NetworkInterface to ApolloLink, which is why you are seeing an error that createNetworkInterface cannot be found.

Either downgrade to version 1.9.3

npm install apollo-client@1.9.3

or follow the upgrade guide in the link above to see how to use version 2.0 in your project.

Daniel Rearden
  • 80,636
  • 11
  • 185
  • 183
  • 1
    apollo 2 is still unstable, and maybe take a lot of weeks to get stable in final version, better use still 1.9.3 – stackdave Oct 28 '17 at 17:00
  • 1
    Link is broken, this one might help: https://github.com/apollographql/apollo-client/blob/master/docs/source/recipes/2.0-migration.md – Alejandro Lora Jun 27 '19 at 10:19
9

Since Version 2.x Apollo has deprecated NetworkInterface in favor of Apollo Link, this unfortunately is a breaking change.

To get your code working again you would need to make the following changes,

replace

import { ApolloClient, createNetworkInterface } from 'apollo-client'

with

import ApolloClient from 'apollo-client';

add

import { HttpLink } from 'apollo-link-http';

and run

npm install --save apollo-link-http

replace

const apolloClient = new ApolloClient({
  networkInterface: createNetworkInterface({
    uri: 'http://localhost:3000/graphql',
    transportBatching: true,
  }),
  connectToDevTools: true,
})

with

const apolloClient = new ApolloClient({
  link: new HttpLink({
    uri: 'http://localhost:3000/graphql'
  }),
  connectToDevTools: true,
})

and don't forget to export your function

export default apolloClient
Faktor 10
  • 1,868
  • 2
  • 21
  • 29