我有一个与另一种类型的一对多连接的 graphql 类型。我想用一个过滤很多。因此 Amplify 生成了 graphql 模式,但在列表查询的输入中没有要使用的连接值。
类型:
type Event @model @auth(rules: [{ allow: owner }]) {
id: ID!
name: String!
date: AWSDateTime!
user: User! @connection(name: "EventsUser", sortField: "date")
isDeleted: Boolean!
}
查询:
type Query {
listEvents(filter: ModelEventFilterInput, limit: Int, nextToken: String): modelEventConnection
列表查询输入
input ModelEventFilterInput {
id: ModelIDFilterInput
name: ModelStringFilterInput
date: ModelStringFilterInput
isDeleted: ModelBooleanFilterInput
and: [ModelEventFilterInput]
or: [ModelEventFilterInput]
not: ModelEventFilterInput
}
我尝试使用以下方法在变量对象中传递 id:
variables: {
filter: {
eventUserId: {
eq: props.id,
},
其中 eventUserId 是 amplify 生成并在 DynamoDB 表中使用的字段名称,但这不起作用。你如何根据这个值进行过滤?我必须手动编写吗?
亚当
编辑
我已经弄清楚了一些。我已经添加:
eventUserId: ModelEventUserInput
其中 ModelEventUserInput 是
input ModelEventUserInput {
eq: ID
}
到 ModelEventFilterInput 输入,然后我使用:
variables: {
filter: {
eventUserId: {
eq: props.id,
},
当过滤加载的应用程序不适用于订阅时,这可以过滤正确的事件。我尝试将过滤器对象添加到订阅构造函数中:
this.props.subscribeToEvents(
buildSubscription({
query: gql(onCreateEvent),
variables: {
owner,
filter: {
eventUserId: {
eq: id,
},
isDeleted: {
eq: false,
},
}
},
}, gql(listEvents))
);
但没有任何运气。如何在订阅上实现这种过滤?
亚当