question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

createNetworkInterface is not a function

See original GitHub issue

The docs say that you can create a new Network Interface by using

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

const networkInterface = createNetworkInterface('http://localhost:8080/graphql');

const client = new ApolloClient({
  networkInterface
});

but for me it throws

Uncaught TypeError: (0 , _apolloClient.createNetworkInterface) is not a function

Is there anything that I’m missing?

(I’m using apollo-client with Electron and a normal Graphql Server.)

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:18 (3 by maintainers)

github_iconTop GitHub Comments

23reactions
amackintoshcommented, Nov 1, 2017

I just opened a project and updated react-apollo and it detonated everything, which is also highlighting that https://github.com/apollographql/react-apollo is currently some troll documentation.

I was using these like this in React Native:

import { ApolloClient, createNetworkInterface, ApolloProvider } from 'react-apollo'

It definitely doesn’t work in React Web with react-apollo 2.0.

I checked my RN app and even though I installed it last week~, its using react-apollo 1.4.

I will downgrade back to sub 2.0, and post my results since someone else will surely see this as well.

Thanks to the magic of time travel, here are my results:

$ npm install --save react-apollo@^1.4

There is no 1.5, 1.6, 1.7, 1.8, or 1.9, so that will downgrade you to the newest non-2.0 version, and you can use:

import { ApolloClient, createNetworkInterface, ApolloProvider } from 'react-apollo'

You don’t need to install apollo-client.

yes1

Just kidding, apollo-client is included with react-apollo. You should see it in node_modules if you burn everything to the ground and just install react-apollo 1.4~.

Here is some bonus code, just in case anyone wants to confirm what works well:

./src/index.js

import { ApolloClient, createNetworkInterface, ApolloProvider } from 'react-apollo'

const tokenOnLoad = localStorage.getItem('token')
if (tokenOnLoad) store.dispatch({ type: LOGIN_SUCCESS })

const networkInterface = createNetworkInterface({
  uri: 'http://localhost:7000/graphql',
  opts: {
    credentials: 'same-origin',
    mode: 'cors'
  }
})

networkInterface.use([{
  applyMiddleware(req, next) {
    if (!req.options.headers) req.options.headers = {}
    const token = localStorage.getItem('token')
    req.options.headers.authorization = token || null
    next()
  }
}])

export const client = new ApolloClient({
  networkInterface,
  dataIdFromObject: (o) => o.id
})

const Root = () => (
  <ApolloProvider store={store} client={client}>
    <Router history={history}>
      <Route path="/" component={App} />
    </Router>
  </ApolloProvider>
)

ReactDOM.render(
  <Root />,
  document.querySelector('#root')
)

I imagine you will want to avoid anything to do with this code if you are looking to get to react-apollo 2.0.

I checked it out and the setup looked haywire breaking change, so I won’t be switching to it ASAP unless someone posts a migration path and usage of graphql() and withApollo() are virtually identical.

11reactions
Karsenscommented, Oct 25, 2017

same 🔢

Read more comments on GitHub >

github_iconTop Results From Across the Web

error: createNetworkInterface is not a function on React Native ...
I have really tried my best to look for solutions on how to implement this, but most tutorials/documentations are for react for web...
Read more >
error: createNetworkInterface is not a function on React Native ...
Coding example for the question error: createNetworkInterface is not a function on React Native and Apollo Client-React Native.
Read more >
How can I resolve the AWS Glue error "The specified subnet ...
My AWS Glue extract, transform, and load (ETL) job returns one of the following errors: "The specified subnet does not have enough free ......
Read more >
The provided execution Role does not have Permissions
Open the AWS Lambda console and click on the function's name; Click on the Configuration Tab and then click Permissions. click on role....
Read more >
IAM Permissions For Functions - Serverless Framework
does not define role. func1: # will assume 'myDefaultRole' ... # does not define role ... ec2:CreateNetworkInterface. - ec2:DescribeNetworkInterfaces.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found