简体   繁体   中英

ApolloClient is not a constructor react-apollo

I am following this tutorial and trying to implement graphQl. There is an issue with the following line:

const client = new ApolloClient();

Strangely I cannot find anything in the react-apollo GitHub page for this. Is there something stupid that I am doing wrong.

import React, { Component } from 'react';
import ChannelsList from './ChannelsList.js';
import './App.css';

import {
  ApolloClient,
  gpl,
  graphql,
  ApolloProvider
} from 'react-apollo';


//issue with this line
const client = new ApolloClient();

const channelsListQuery = `
  query ChannelsListQuery {
    channels {
      id,
      name
    }
  }
`;

const ChannelsListWithData = graphql(channelsListQuery)(ChannelsList);

class App extends Component {
  render() {
    return (
      <ApolloProvider client={client}>
        <ChannelsListWithData />
      </ApolloProvider>
    );
  }
}

export default App;

To provide a straightforward answer - ApolloClient is no longer a part of the react-apollo package, but made it to a package of it's own: apollo-client .

You may also see it being imported from apollo-boost , a convenience which "includes some packages that we [Apollo's authors] think are essential to developing with Apollo Client."

having the same issue here and actually following the same article ( https://dev-blog.apollodata.com/full-stack-react-graphql-tutorial-582ac8d24e3b ) as the OP. The issue is that the article is really old and out of date and I would not recommend using it as a guide (take a look at the comments in the article).

For a start I'd recommend looking at the docs. This link ( http://graphql.org/graphql-js/ ) in particular is a good starting place for getting something up and running.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM