forked from Joystream/hydra
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(hydra-cli): support cross filters for entity relationship (Joyst…
…ream#381) * hydra-cli: update relation decorator with new options * hydra-cli: cross filter queries for oto, mto, otm relation types * hydra-cli: update templates for MTM relations * hydra-cli: fix table name * hydra-cli: cross-relation filters docs * hydra-cli: fix tests * hydra-cli: upgrade warthog version
- Loading branch information
Showing
10 changed files
with
311 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
--- | ||
description: Filter query results with related entity fields | ||
--- | ||
|
||
# Cross-relation filters | ||
|
||
Cross-relation filters allows you to filter query results with the related entity fields. | ||
|
||
During the example we will use the below schema: | ||
|
||
```graphql | ||
type Channel @entity { | ||
id: ID! | ||
handle: String! | ||
videos: [Video!] @derivedFrom(field: "channel") | ||
} | ||
|
||
type Video @entity { | ||
id: ID! | ||
title: String! | ||
channel: Channel! | ||
featured: FeaturedVideo @derivedFrom(field: "video") | ||
publishedBefore: Bool! | ||
} | ||
|
||
type FeaturedVideo @entity { | ||
id: ID! | ||
video: Video! | ||
} | ||
``` | ||
|
||
**Filter 1-1 relations** | ||
|
||
Fetch all the featured videos those title contains `joy`: | ||
|
||
```graphql | ||
query { | ||
featuredVideos(where: { video: { title_contains: "joy" } }) { | ||
id | ||
video { | ||
title | ||
} | ||
} | ||
} | ||
``` | ||
|
||
**Filter 1-M relations** | ||
|
||
Fetch all the videos published under `Joystream` channel: | ||
|
||
```graphql | ||
query { | ||
videos(where: { channel: { handle_eq: "Joystream" } }) { | ||
title | ||
} | ||
} | ||
``` | ||
|
||
**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` | ||
|
||
```graphql | ||
query { | ||
channels(where: { videos_some: { title_contains: "kid" } }) { | ||
handle | ||
videos { | ||
title | ||
} | ||
} | ||
} | ||
``` | ||
|
||
**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`: | ||
|
||
```graphql | ||
query { | ||
channels(where: { videos_every: { publishedBefore_eq: true } }) { | ||
handle | ||
videos { | ||
title | ||
} | ||
} | ||
} | ||
``` | ||
|
||
**Fetch if none of the entities in the relation satify a condition** | ||
|
||
Fetch all channels which have none of their videos `publishedBefore_eq: true`: | ||
|
||
```graphql | ||
query { | ||
channels(where: { videos_none: { publishedBefore_eq: true } }) { | ||
handle | ||
videos { | ||
title | ||
} | ||
} | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.