graphql - 使用 GraphQL 在 react-admin 列表组件中过滤
问题描述
在我的应用程序中,我有location
实体和DPD
实体。DPD 包含location_id
字段。GQL 架构:
type Location @key(fields: "id") {
id: ID!
label: String
address: Address
tenant: Tenant
manager: User
}
extend type Query {
Location(id: ID!): Location
allLocations(
page: Int
perPage: Int
sortField: String
sortOrder: String
filter: LocationFilter
): [Location]
_allLocationsMeta(
page: Int
perPage: Int
sortField: String
sortOrder: String
filter: LocationFilter
): ListMetadata
}
input LocationFilter {
ids: [ID]
label: String
}
type DPD @key(fields: "id") {
id: ID
name: String
location: Location
location_id: ID
}
input DPDFilter {
ids: [ID]
id: ID
name: String
location_id: ID
}
extend type Query {
DPD(id: ID!): DPD
allDPDS(page: Int, perPage: Int, sortField: String, sortOrder: String, filter: DPDFilter): [DPD]
_allDPDSMeta(page: Int, perPage: Int, sortField: String, sortOrder: String, filter: DPDFilter): ListMetadata
}
在列出 DPD 时,我需要按location
. 在 RA 项目中,我有DPDList
组件:
const filters = [
<ReferenceInput key="location" source="location.id" reference="Location">
<SelectInput optionText="label" />
</ReferenceInput>,
];
export const DPDList: FC<ResourceComponentProps> = (props: ResourceComponentProps) => (
<List {...props} filter={filters}>
<Datagrid>
<TextField source="name" />
<ReferenceField label="Location" source="location.id" reference="Location" sortable={false}>
<TextField source="label" />
</ReferenceField>
<EditButton />
</Datagrid>
</List>
);
如果没有应用过滤器,我会呈现正确的列表。我可以看到查询:
allDPDS
带参数:
{filter: {}, page: 0, perPage: 10, sortField: "id", sortOrder: "ASC"}
allLocations
带参数
{filter: {ids: ["3", "1", "4", "7"]}}
当我应用过滤allDPDS
查询更改的参数时:
{filter: {0: {key: "location", ref: null,…}}, page: 0, perPage: 10, sortField: "id", sortOrder: "ASC"}
我有错误:
Variable "$filter" got invalid value ...
我应该在模式(自省)或 RA 中更改什么?
解决方案
推荐阅读
- spring - 为什么我收到此错误 FUNCTION world.next_val 不存在
- python - 在许多文件上并行/调度python函数调用
- r - 安装 Rstudio 并启动它后,我收到一个 rsession.exe 系统错误,提示“Rlapack.dll 从您的计算机中丢失”
- highcharts - 在高图甘特图中垂直排列 yAxis 列的单元格
- tkinter - 用于在 linux 上播放视频的 python-vlc tkinter 应用程序
- reactjs - 亚马逊支付与 React Native 的集成
- excel - 将文本框值添加到连接公式中
- react-native - React Native - 当警报出现时图像消失
- c - 为什么 SW4STM32 subdir.mk 会产生错误?
- python - Pyqt5:在 QtWidgets 中找不到 PasswordEdit