reactjs - React Apollo 显示 "react-apollo only supports a query, subscription, or a mutation per HOC"错误

标签 reactjs react-native graphql react-apollo

我收到以下错误:

ExceptionsManager.js:74 react-apollo only supports a query, subscription, or a mutation per HOC. [object Object] had 2 queries, 0 subscriptions and 0 mutations. You can use 'compose' to join multiple operation types to a component

即使我在组件中使用 compose:

import React from "react";
import React from "react";
import { compose, graphql } from "react-apollo";
import { View } from "react-native";
import { GET_ITEM, GET_REVIEWS } from "../graphql/query";

const PostingDetail = ({ navigation }) => {
  console.log("itemQuery", itemQuery);

  return <View></View>;
};

export default compose(
  graphql(GET_ITEM, { name: "itemQuery" }),
  graphql(GET_REVIEWS, { name: "reviewsQuery" })
)(PostingDetail);

用于 GET_REVIEW 的 GraphQL:

export const GET_REVIEWS = gql'
    query Reviews($id: ID!) {
        reviews(
            id: $id
        )
    }{
        author {
            firstName
            lastName
        }
        comment
        createdAt
    } 
'

用于 GET_ITEM 的 GraphQL:

export const GET_ITEM = gql'
    query Post($id: ID!) {
        post(
            id: $id
        ){
            id
            title
            body
            location
            price
            image
            quantity
            author {
                id
                firstName
                lastName
            }
            latitude
            longitude
            booking {
                startDate
                endDate
            }
        }
    }
'
  

最佳答案

并不是真正修复您当前正在尝试的方法,但更改为 React Hooks 和 useQuery 将使您的代码更简单。

import React from 'react';
import { View } from 'react-native';
import { compose, graphql } from 'react-apollo';
import { GET_ITEM, GET_REVIEWS } from '../graphql/query';
import { useQuery } from '@apollo/react-hooks';

const PostingDetail = ({ navigation }) => {
  const { data: itemData } = useQuery(GET_ITEM);
  const { data: reviewData } = useQuery(GET_REVIEWS);

  console.log('itemQuery', itemData);
  console.log('reviewQuery', reviewData);

  return <View></View>;
};

关于reactjs - React Apollo 显示 "react-apollo only supports a query, subscription, or a mutation per HOC"错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58511834/

相关文章:

javascript - 如何在 React.js 中正确捕获文本输入的 change/focusOut 事件?

javascript - 在React应用程序中添加额外的CSS类名

android - WebStorm 上的 Firebase 设置

reactjs - 如何使用 react-native-testing-library getByRole

reactjs - 如何在 React 中使 owl-carousel 响应式?

react-native - Expo:更改默认 IOS 模拟器

php - SilverStripe GraphQL - 查询具有后代的类型时出错

node.js - 返回 null 的 GraphQL 嵌套查询

graphql - ApolloServer 不触发自定义指令

javascript - React状态钩子(Hook),toogle类,为什么两个元素都获得 "active"类?