graphql - 未根据 GraphQL 放大查询中的过滤器获得计数
问题描述
根据过滤器获取扫描计数但不计数数据
count: null
items: [{id: "bcd75096-7fd9-4e9d-8675-6877f0609ac2", name: "dxfrdhjkhklklkl", description: "dgdxrfg",…},…]
0: {id: "bcd75096-7fd9-4e9d-8675-6877f0609ac2", name: "dxfrdhjkhklklkl", description: "dgdxrfg",…}
1: {id: "52f6ff60-fc07-4631-a1fb-b039f376ff21", name: "ghnfgyhj", description: "gyhkjmuhjolk",…}
2: {id: "f73dfb37-2778-4b87-88c7-e6f9f5b5c931", name: "drftgserty", description: "trse54rte54ty",…}
3: {id: "6df9f5c2-ec06-4e70-b5e2-133cb0d8e958", name: "tygujghukuh", description: "tuyjyuikuolnh",…}
4: {id: "9360a766-ac89-420c-881b-2b3089bcca7f", name: "kl;", description: "vcbghnjmk,l", is_active: true,…}
5: {id: "c0dcbaff-37d4-4e4c-9375-584ff7110d77", name: "dfhgbdcb", description: "dfxvcx", is_active: true,…},...
scannedCount: 100
我已按照这些教程获取计数如何使用 AWS AMPLIFY DYNAMODB 和 GRAPHQL 计算结果的数量
筛选
var body = {
filter: {
is_active: {
eq: true
}
}
}
查询以获取待办事项列表
export const listTodos = /* GraphQL */ `
query ListTodos(
$filter: ModelTodoFilterInput
$limit: Int
$nextToken: String
) {
listTodos(filter: $filter, limit: $limit, nextToken: $nextToken) {
count
items {
id
name
description
is_active
createdAt
updatedAt
}
scannedCount
}
}
`;
GraphQl shema
type Todo @model {
id: ID!
name: String!
description: String!
is_active: Boolean
}
type ModelTodoConnection {
items: [Todo]
scannedCount: Int
count: Int
total: Int
}
如果我将限制设置为 5,如果我在数据库中的总数据在 110 左右,它将发回scannedCount
5。我想计算数据的位置 is_active: { eq: true }
解决方案
查看我为解决此问题而编写的包:https ://github.com/multimeric/AmplifyCountDirective 。
按照安装说明进行操作后,为了解决您的问题,我会将架构更改为:
type Todo @model @count {
id: ID!
name: String!
description: String!
is_active: Boolean
}
然后您可以使用 GraphQL 查询来查询计数,例如:
{
countTodo(filter: {
is_active: {
eq: true
}
})
}
推荐阅读
- neo4j - Neo4j Cypher - 创建同态变换
- flutter - 在路线之间移除颤振导航
- sql - 在时态表和 AVERAGE 中成功查询后返回非重复值
- jquery - 在另一个函数中使用来自一个函数的变量
- c# - 即使在实现 INotifyPropertyChanged 之后,DataTemplate 中的字典也不会更新 UI
- ios - SwiftUI:如何在背景中模糊的当前视图顶部弹出一个视图?
- python-3.x - 服务总线未在 Azure 上触发,在本地工作
- angular - Angular Material 反应形式:为每个验证器显示不同的错误消息
- css - 为什么我的媒体查询范围不能正常工作?
- vuejs2 - 带有 flex/grid 包装器的 vue 过渡组项目移动到左上角