reactjs - React hooks Apollo Graphql Boolean value always returning false
问题描述
Overview
I am using @apollo/hooks
in a react typescript app, and Hasura/Postgres on an aws ec2 instance. When I make a query to the db from react, all the boolean values in one table are returning as false. By making the same query in the Hasura GraphiQL interface, I can confirm in the database that they are not all false.
More Detail
I am trying to pull in data from a simple postgres table (no foreign keys, links to other tables, etc) that has only 6 fields:
id: number
hero_button_pointer: string
hero_button_text: string
hero_headline_text: string
hero_sub_headline_text: string
active: boolean
When I make this query in the Hasura GraphiQL interface
query GetAllHeroInfo {
main_page_header(order_by: {id: asc}) {
active
hero_button_pointer
hero_button_text
hero_headline_text
hero_sub_headline_text
id
}
}
it returns all of the values correctly. Most importantly the boolean values are correct. I have exactly the same query in my React app:
export const GET_ALL_HERO_INFO = gql`
query GetAllHeroInfo {
main_page_header(order_by: { id: asc }) {
active
hero_button_text
hero_headline_text
hero_sub_headline_text
id
hero_button_pointer
}
}
`;
The Big Problem
In my component I am using the useQuery hook:
import { GET_ALL_HERO_INFO } from "../../graphQL/queries";
const MyComponent: React.FC<Props> = () => {
const { loading, error, data: heroData } = useQuery(GET_ALL_HERO_INFO);
console.log(heroData) //everything logs correctly, except boolean values are all false
return (
// the component
)
};
and when I console.log(heroData)
or try to use the data in any way, all of the boolean values are false
even though I can see in the database that they are true. I've updated some of the other string values directly in the database and those changes are coming through correctly. Its just the boolean values that are always false no matter what the database says.
Any ideas?
Edits
03-16-2020:20:39 - As suggested by @DanielRearden I checked the network tab to see if its a client-side or server-side issue. Looks like I am getting a response that includes a true
value, but still console.log
ing false. I've attached photos below:
解决方案
根据@DanielRearden 的建议,我迁移到了新的 apollo-client 版本,它解决了我的所有问题。看起来这是一个错误¯\_(ツ)_/¯
推荐阅读
- sql - 从 JSON 数据迁移到规范化表
- azure-devops - 适用于 ARM 的 Azure DevOps:初始化时任务失败。错误:需要输入:ConnectedServiceName”
- java - 二叉树中节点的深度(Java)
- rust - 如何获取切片最后一个元素的选定字段或返回错误?
- c++ - 无法加载库 *.dll 未知错误 0x000000c1
- python-3.x - Tkinter 删除按钮使错误列表索引超出范围
- php - Codeigniter 3 应用程序错误:登录用户的头像没有实时更新
- python - 在python中带有变量的SQL Like语句
- node.js - 我在 ionic 中使用 tesseract.js 从图像中提取文本。现在有没有办法在键值对中表示提取的文本?
- excel - 将字符串添加到内容控件框/将下拉列表替换为内容控件