在 graphql 查询中包装组件时出错

Error while wrapping a component in a graphql query

我正在使用 Apollo 客户端向 GraphQL 服务器发送请求。

所以我用这种方式在 GraphQL 函数中包装了一个 React 组件

GraphQL(query)(HomeView);

我遇到了这个错误:

Argument of [object Object] passed to parser was not a valid GraphQL DocumentNode. You may need to use 'graphql-tag' or another method to convert your operation into a document

我该如何解决这个问题?

这是我的组件代码:

import React, {Component} from 'react';

import { graphql } from 'react-apollo';
import gql from 'graphql-tag';

const query = {
    query: gql`
        {
            hello
        }
    `
};

class HomeView extends Component {
    render() {
        return (
            <div>
                <h1>Home</h1>
            </div>
        );
    }
}

export default graphql(query)(HomeView);

您需要将所有查询包装在 gql 标记中:

const query = gql`
    {
      hello
    }
`;