【问题标题】:Error while wrapping a component in a graphql query在 graphql 查询中包装组件时出错
【发布时间】:2018-09-11 20:22:18
【问题描述】:

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

所以我以这种方式将 react 组件包装在 GraphQL 函数中

GraphQL(query)(HomeView);

我收到了这个错误:

传递给解析器的 [object Object] 参数不是有效的 GraphQL 文档节点。您可能需要使用“graphql-tag”或其他方法 将您的操作转换为文档

我该如何解决这个问题?

这是我的组件代码:

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);

【问题讨论】:

    标签: reactjs graphql react-apollo


    【解决方案1】:

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

    const query = gql`
        {
          hello
        }
    `;
    

    【讨论】:

      猜你喜欢
      • 2018-09-17
      • 2018-01-09
      • 2019-03-02
      • 2019-12-26
      • 2018-11-15
      • 2019-05-17
      • 1970-01-01
      • 2021-09-03
      • 2020-01-20
      相关资源
      最近更新 更多