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?
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With