I did this sample:
As a result, I have the same file in my project: .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?
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?
Share Improve this question edited Oct 27, 2017 at 0:21 Colibri asked Oct 27, 2017 at 0:02 ColibriColibri 1,19515 silver badges35 bronze badges 2 |2 Answers
Reset to default 9Since 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
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.
apollo-client
listed in yourpackage.json
? – Daniel Rearden Commented Oct 27, 2017 at 2:04^2.0.1
. And used2.0.1
version. – Colibri Commented Oct 27, 2017 at 9:09