使用带有 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
  }
}