コンテンツにスキップ

フィルタリングされたリストクエリ

クエリ結果をフィルタリングできます。以下の例では、createdAtfirstNameemailageなどのフィールドとリレーションを含むstudentsというテーブルがあります。

フィルタリングされたレコードのリストをクエリします。filter引数に注意してください。

リクエスト

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が指定されている場合、すべてのフィルタオブジェクトがtrueを返す必要があります。

リクエスト

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が指定されている場合、少なくとも1つのフィルタオブジェクトがtrueを返す必要があります。

リクエスト

query MyQuery1 {
students(
filter: {
OR: {
firstName: {
equals: "Mary"
},
lastName: {
equals: "Williams"
}
}
}
) {
items {
id
createdAt
firstName
email
isActive
}
}
}

レスポンス

{
"data": {
"students": {
"items": [
{
"id": "429cf99f-4481-49c4-adb4-605731b20eb2",
"createdAt": "2025-12-04T14:16:53.049955Z",
"firstName": "Mary",
"email": "mary.brown@example.com",
"isActive": true
},
{
"id": "97fb89ac-e0ad-44f5-b671-24a1b751287c",
"createdAt": "2025-12-02T05:03:17.180675Z",
"firstName": "John",
"email": "john.williams@example.com",
"isActive": true
},
{
"id": "13fcb5bf-a8a4-4e55-860f-74f425944ec0",
"createdAt": "2025-12-04T20:30:58.586321Z",
"firstName": "Mary",
"email": "mary.johnson@example.com",
"isActive": true
},
{
"id": "0174dc55-d494-4ebc-a0e9-13575461cad4",
"createdAt": "2025-12-05T15:20:10.123456Z",
"firstName": "Robert",
"email": "robert.williams@example.com",
"isActive": true
}
]
}
}
}