Apollo-client: "Uncaught TypeError: Cannot set property 'middleware' of undefined" while following instructions for React

Created on 18 Oct 2016  路  4Comments  路  Source: apollographql/apollo-client

Hi - while following the instructions here I get Uncaught TypeError: Cannot set property 'middleware' of undefined when trying to create an ApolloClient. Here's the relevant code:

import React from 'react';
import ReactDOM from 'react-dom';
import ApolloClient, {createNetworkInterface} from 'apollo-client';
import { ApolloProvider } from 'react-apollo';
import App from './App';
import './index.css';

const client = ApolloClient({
  networkInterface: createNetworkInterface('https://api.github.com/graphql')
});

ReactDOM.render(
  <ApolloProvider client={client}>
    <App />
  </ApolloProvider>,
  document.getElementById('root')
);

I also saw this issue, which suggests I might need to do this instead:

const client = ApolloClient({
  networkInterface: createNetworkInterface({uri: 'https://api.github.com/graphql'})
});

This gives exactly the same error however.

Using [email protected] with [email protected]. Any idea what I might be doing wrong?

Also here's a repo with the issue, if that helps. Thanks!

Most helpful comment

It should benew ApolloClient

All 4 comments

It should benew ApolloClient

Doh! Yep that works, thanks!

Someone could send a pr to throw an error when the constructor is called without new!

why not make it return the new class?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

stubailo picture stubailo  路  3Comments

nlko picture nlko  路  3Comments

joergbaier picture joergbaier  路  3Comments

treecy picture treecy  路  3Comments

elie222 picture elie222  路  3Comments