hydra
Search…
Cross filtering
Filter query results with related entity fields
Cross-relation filters allows you to filter query results with the related entity fields.
During the example we will use the below schema:
1
type Channel @entity {
2
id: ID!
3
handle: String!
4
videos: [Video!] @derivedFrom(field: "channel")
5
}
6
7
type Video @entity {
8
id: ID!
9
title: String!
10
channel: Channel!
11
featured: FeaturedVideo @derivedFrom(field: "video")
12
publishedBefore: Bool!
13
}
14
15
type FeaturedVideo @entity {
16
id: ID!
17
video: Video!
18
}
Copied!
Filter 1-1 relations
Fetch all the featured videos those title contains joy:
1
query {
2
featuredVideos(where: { video: { title_contains: "joy" } }) {
3
id
4
video {
5
title
6
}
7
}
8
}
Copied!
Filter 1-M relations
Fetch all the videos published under Joystream channel:
1
query {
2
videos(where: { channel: { handle_eq: "Joystream" } }) {
3
title
4
}
5
}
Copied!
Modifiers There are three modifiers can be use for M-1 and M-M relationships.
  • some: if any of the entities in the relation satify a condition
  • every: if all of the entities in the relation satify a condition
  • none: if none of the entities in the relation satify a condition
Fetch if any of the entities in the relation satify a condition Example:
Fetch all channels which have at least one video with a title that contains kid
1
query {
2
channels(where: { videos_some: { title_contains: "kid" } }) {
3
handle
4
videos {
5
title
6
}
7
}
8
}
Copied!
Fetch if all of the entities in the relation satify a condition Example:
Fetch all channels which have all of their videos publishedBefore_eq: true:
1
query {
2
channels(where: { videos_every: { publishedBefore_eq: true } }) {
3
handle
4
videos {
5
title
6
}
7
}
8
}
Copied!
Fetch if none of the entities in the relation satify a condition
Fetch all channels which have none of their videos publishedBefore_eq: true:
1
query {
2
channels(where: { videos_none: { publishedBefore_eq: true } }) {
3
handle
4
videos {
5
title
6
}
7
}
8
}
Copied!
Last modified 8mo ago
Copy link