反应挂钩Apollo Graphql布尔值始终返回false

时间:2020-03-17 00:46:01

标签: reactjs postgresql graphql apollo hasura

概述

我在React Typescript应用中使用@apollo/hooks,在aws ec2实例上使用Hasura / Postgres。当我从react查询数据库时,一个表中的所有布尔值都返回false。通过在Hasura GraphiQL界面中进行相同的查询,我可以在数据库中确认它们并非全部为假。

更多详细信息

我试图从只有6个字段的简单postgres表(没有外键,到其他表的链接等)中提取数据:

id: number
hero_button_pointer: string
hero_button_text: string
hero_headline_text: string
hero_sub_headline_text: string
active: boolean

当我在Hasura GraphiQL界面中进行此查询时

query GetAllHeroInfo {
  main_page_header(order_by: {id: asc}) {
    active
    hero_button_pointer
    hero_button_text
    hero_headline_text
    hero_sub_headline_text
    id
  }
}

它正确返回所有值。最重要的是,布尔值是正确的。我的React应用程序中有恰好相同的查询:

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
    }
  }
`;

大问题

在我的组件中,我正在使用useQuery挂钩:

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
  )
};

并且当我console.log(heroData)或尝试以任何方式使用数据时,所有布尔值都是false,即使我在数据库中看到它们都是真实的。我已经直接在数据库中更新了其他一些字符串值,这些更改已正确通过。无论数据库怎么说,只是布尔值始终为假。

有什么想法吗?

编辑

03-16-2020:20:39-正如@DanielRearden所建议的那样,我检查了“网络”选项卡以查看其是客户端还是服务器端问题。看起来我收到的响应包含一个true值,但仍然console.log设置为false。我在下面附上了照片:

Network Tab

console.log

1 个答案:

答案 0 :(得分:0)

按照@DanielRearden的建议,我迁移到了新的apollo-client版本,它解决了我的所有问题。好像是一个错误¯\_(ツ)_/¯