微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

使用带有 apollo react-hooks 的 graphql 查询时缺少字段 __typename

如何解决使用带有 apollo react-hooks 的 graphql 查询时缺少字段 __typename

我在 GRAPHQL 中遇到查询问题

这是我的查询

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

我正在使用 react-hooks
import { useQuery } from "@apollo/react-hooks";

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"
}

解决方法

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

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

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。