过滤列表查询
您可以过滤查询结果。在以下示例中,我们有一个名为 students 的表,其中包含诸如 createdAt、firstName、email、age 等字段和关系。
在查询中使用过滤器
Section titled “在查询中使用过滤器”查询经过过滤的记录列表。请注意过滤器参数。
请求
query MyQuery1 { students( filter: { createdAt: { gt: "2025-12-01T13:00:00.000Z" }, email: { contains: "williams" } } ) { items { id createdAt firstName email } }}响应
{ "data": { "students": { "items": [ { "id": "97fb89ac-e0ad-44f5-b671-24a1b751287c", "createdAt": "2025-12-02T05:03:17.180675Z", "firstName": "John", "email": "john.williams@example.com" }, { "id": "e25c4955-7ea7-4a83-a3de-d4c7427cc9fa", "createdAt": "2025-12-04T14:18:15.955194Z", "firstName": "Robert", "email": "robert.williams@example.com" } ] } }}条件过滤器使用 AND 和 OR 键。
使用 AND
Section titled “使用 AND”指定 AND 时,所有过滤器对象必须返回真值。
请求
query MyQuery1 { students( filter: { AND: { email: { contains: "johnson" }, isActive: { not_equals: false } } } ) { items { id createdAt firstName email isActive } }}响应
{ "data": { "students": { "items": [ { "id": "13fcb5bf-a8a4-4e55-860f-74f425944ec0", "createdAt": "2025-12-04T20:30:58.586321Z", "firstName": "Mary", "email": "mary.johnson@example.com", "isActive": true } ] } }}指定 OR 时,至少一个过滤器对象必须返回真值。
请求
query MyQuery1 { students( filter: { OR: { firstName: { equals: "Mary" }, lastName: { equals: "Williams" } } } ) { items { id createdAt firstName email isActive } }}