Apollo客户端 - 错误:无法在查询地图

时间:2017-01-29 02:23:22

标签: reactjs graphql apollostack react-apollo apollo-client

我遇到了Apollo Client-React的问题。

我想在用户点击登录按钮时发送登录请求。

我的代码是:

// @vendors
import React from 'react';
import { 
  withApollo
} from 'react-apollo';
import ApolloClient from 'apollo-client';
import gql from 'graphql-tag';
import { Link } from 'react-router';

class Login extends React.Component {

  constructor() {
    super();
    this.state = {
      email: 'user1@email.com'
    }
    this.sendRequest = this.sendRequest.bind(this);
  }

  sendRequest() {
    const {
      email
    } = this.state;

    const FETCH_USER = gql`
      query fetchUser($email: String!) {
        user(email: $email) {
          id
        }
      }
    `;
    return this.props.client.query({
      query: FETCH_USER,
      variables: {email: email}
    })
  }

  render() {
    return (
      <form>
        <div className="form-group">
          <label htmlFor="email">Email:</label>
          <input type="email" className="form-control" id="email" />
        </div>
        <div className="form-group">
          <label htmlFor="password">Password:</label>
          <input type="password" className="form-control" id="password" />
        </div>
        <button onClick={this.sendRequest} className="btn btn-default">Log In</button>
      </form>
    );
  }
}

Login.propTypes = {
  client: React.PropTypes.instanceOf(ApolloClient).isRequired,
}

export default withApollo(Login);

控制台显示:

  

未捕获(承诺)错误:网络错误:无法在查询地图中找到查询。

有人能帮助我吗?

  

更新:

我用过这个版本:

  • &#34; apollo-client&#34;:&#34; ^ 0.6.0&#34;
  • &#34; react-apollo&#34;:&#34; ^ 0.9.0&#34;

0 个答案:

没有答案