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?

2
  • What's the version of apollo-client listed in your package.json? Oct 27, 2017 at 2:04
  • @DanielRearden ^2.0.1. And used 2.0.1 version.
    – Colibri
    Oct 27, 2017 at 9:09

2 Answers 2

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
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 [email protected]

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

2

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.