【问题标题】:Missing field __typename while using graphql query with apollo react-hooks使用带有 apollo react-hooks 的 graphql 查询时缺少字段 __typename
【发布时间】:2021-07-15 08:55:54
【问题描述】:

我在 GRAPHQL 中遇到查询问题

这是我的查询

const discussionform = gql`
  query totara_mobile_discussion {
    discussion {
      __typename
      us
      sys
    }
  }
`;

我正在使用 react-hooks。
从“@apollo/react-hooks”导入 { useQuery };

const Profile = ({ navigation }: ProfileProps) => {
  const { loading, data, error } = useQuery(discussionform);
  if (loading) return <Loading testID={"test_ProfileLoading"} />;
  return (
    <View>
      <Text>{data}</Text>
    </View>
  );
};

我遇到的错误

Missing field __typename in {
  "us": "General news and announcements",
  "sys": "tesr"
}

【问题讨论】:

    标签: react-native graphql apollo react-apollo react-apollo-hooks


    【解决方案1】:

    通过在服务器端的架构中添加 __typename,问题将得到解决。

       query totara_mobile_discussion {
      discussion  : totara_mobile_discussion {
        us
        sys
        __typename
      }
    }
    

    【讨论】:

      猜你喜欢
      • 2019-04-18
      • 2020-05-05
      • 2021-10-03
      • 2019-02-22
      • 2020-01-23
      • 2017-08-15
      • 2019-12-18
      • 2018-03-10
      • 2019-06-13
      相关资源
      最近更新 更多