Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"export 'createNetworkInterface' was not found in 'apollo-client'

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?

like image 735
Colibri Avatar asked Oct 27 '17 00:10

Colibri


1 Answers

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
like image 113
Faktor 10 Avatar answered Oct 21 '22 03:10

Faktor 10