我已经实现了从系统中获取活动的模式,并且正在获取整个列表。我想开始传递 user_id 以便根据用户进行过滤或按上周前 10 名的活动进行过滤。我的模式是;
activity.graphql 的架构
type ActivityActivity {
id: ID!
activity: String!
user: User @belongsTo
created_at: String!
updated_at: String
deleted_at: String
createdBy: User @belongsTo
updatedBy: User @belongsTo
deletedBy: User @belongsTo
}
extend type Mutation {
createActivityActivity(
id: ID
activity: String!
user_id: Int!
source_type: String!
source_id: Int!
): ActivityActivity @create(model: "Modules\\Activity\\Entities\\Activity")
updateActivityActivity(
id: ID!
activity: String
user_id: Int
source_type: String
source_id: Int
): ActivityActivity @update(model: "Modules\\Activity\\Entities\\Activity")
deleteActivityActivity(id: [ID!]!): [ActivityActivity!]! @delete(model: "Modules\\Activity\\Entities\\Activity")
}
extend type Query {
activity_activity: [ActivityActivity!]! @paginate(model: "Modules\\Activity\\Entities\\Activity")
find_activity_activity(id: Int! @eq): ActivityActivity @find(model: "Modules\\Activity\\Entities\\Activity")
}
extend type User {
activity: [ActivityActivity!]! @hasMany
}
如何添加具有过滤器或具有 where 子句的 fetch 语句查询,例如
query {
activity_activity(count: 10) {
filters{user_id : 10, created_at:2019-01-01}
data{
activity
created_at,
user{name,email,created_at}
}
}
}
或在查询中添加 where 子句,例如
query {
activity_activity(count: 10) {
where{'user_id = 10 AND created_at=2019-01-01'}
data{
activity
created_at,
user{name,email,created_at}
}
}
}
更新
建议的解决方案是过滤字段如下
extend type Query {
activity_activity(
activity: String @where(operator: "like"),
user_id: Int @eq
): [ActivityActivity!]! @paginate(model: "Modules\\Activity\\Entities\\Activity")
find_activity_activity(id: Int! @eq): ActivityActivity @find(model: "Modules\\Activity\\Entities\\Activity")
}
我正在实施一个 ERP,根据系统设计,用户应该有高级搜索,允许他们执行自定义过滤,例如不等于(!=)、不在(!)、大于(>)等。在当前的实施中,我没有选择但要为每个高级搜索编写不同的过滤器参数。有不同的选择吗?