react-apollo错误:[网络错误]:ServerParseError:JSON.parse:JSON数据第1行第1列的意外字符

问题描述 投票:0回答:1

我想通过apollo向服务器发送请求并获取查询:

import React, { Component } from 'react';
import { gql } from 'apollo-boost';
import { graphql } from 'react-apollo';

const getBooksQuery = gql`
{
    books{
        name
        id
    }
}
`

class BookList extends Component {
    render() {
        console.log(this.props);
        return (
            <div>
                <ul id="book-list">
                    <li>Book Name</li>
                </ul>
            </div>
        );
    }
}


export default graphql(getBooksQuery)(BookList);

但是我收到以下错误。

[[网络错误]:ServerParseError:JSON.parse:JSON数据的第1行第1列中的意外字符

我已经使用nodejs和graphql配置了后端服务器。但我可以在浏览器中轻松打开“ http://localhost:4000/graphql/”,发送以下查询

{图书{名称ID}}

并从数据库中获取数据。有人知道问题出在哪里吗?

node.js reactjs graphql react-apollo
1个回答
0
投票

我已经解决了这个问题,并且指出了我的客户错误的URL。

© www.soinside.com 2019 - 2024. All rights reserved.