【问题标题】:Fetching only distinct data from table using hasura-graphql data provider in react-admin在 react-admin 中使用 hasura-graphql 数据提供程序仅从表中获取不同的数据
【发布时间】:2020-08-18 14:11:38
【问题描述】:

我正在做一个项目,我必须从下拉列表中显示的表格中仅获取不同的数据。我怎样才能做到这一点?我正在使用 '''hasura-graphql''' 数据提供者。那么我怎样才能只从特定列中获取不同的数据呢?

提前致谢。

【问题讨论】:

    标签: graphql react-admin hasura


    【解决方案1】:

    我认为传递一个默认的“distinct_on”过滤器并将列名作为值将完成这项工作。此外,hasura 建议按此列在第一位进行排序。

    通常建议使用 order_by 和 distinct_on 来 确保我们得到可预测的结果(否则任何带有 可以返回列的不同值)。请注意, distinct_on 列需要是 order_by 中的第一列 表达。

    所以我设置了默认排序:

    <ReferenceInput
        reference="yourTable"
        source="yourDistinctColumn"
        sort={{field: "yourDistinctColumn", order: "ASC"}}//or DESC, your choice
        filter={{distinct_on: "yourDistinctColumn"}}
    >
        <SelectInput optionText="yourDistinctColumn"/>
    </ReferenceInput>
    

    https://hasura.io/docs/1.0/graphql/manual/queries/distinct-queries.html

    【讨论】:

    • 感谢您的帮助,但我必须显示 SelectInput 的数据下拉选项。我们如何在 ReferenceInput 中使用过滤器?
    • 我尝试了这个解决方案,但filter={{distinct_on: "distinctColumn"}} 无法正常工作,它的抛出错误无法读取未定义的属性。我是 Hasura 和 react-admin 的新手
    • 您是否将distinctColumn 更改为您需要区分的列?
    • 是的,这是我的代码&lt;ReferenceInput label="Block" reference="location" filter={{ distinct_on: "block" }} &gt; &lt;SelectInput optionText="block" /&gt; &lt;/ReferenceInput&gt;
    • distinct_on 传递给filter 变成where: {"distinct_on": {"_eq": "distinctColumn"}}
    猜你喜欢
    • 1970-01-01
    • 2021-10-26
    • 2019-12-18
    • 2022-01-25
    • 2020-05-08
    • 1970-01-01
    • 2022-12-11
    • 2022-12-29
    • 2022-08-05
    相关资源
    最近更新 更多