Skip to content

Commit

Permalink
feature(conditionals): added docs on Select function
Browse files Browse the repository at this point in the history
  • Loading branch information
scottrippey committed Jan 17, 2024
1 parent 79de34a commit 2be8e60
Showing 1 changed file with 26 additions and 1 deletion.
27 changes: 26 additions & 1 deletion packages/groq-builder/docs/CONDITIONALS.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,5 +77,30 @@ Array<

Notice that this type is stronger than the example with `q.conditional$`, because we've detected that the conditions are "exhaustive".

## The `select` function
## The `select` method

Adds support for the `select$` method:
```ts
const qMovies = q.star.filterByType("movie").project({
name: true,
popularity: q.select$({
"popularity > 20": q.value("high"),
"popularity > 10": q.value("medium"),
}, q.value("low")),
});
```

The `$` sign is to indicate that there's some "loosely typed" code in here -- the conditions are unchecked.

## The `selectByType` method

Adds a `selectByType` helper, which facilitates type-based logic. This is completely strongly-typed:
```ts
const qContent = q.star.filterByType("movie", "actor").project(q => ({
name: q.selectByType({
movie: q => q.field("title"),
actor: q => q.field("name"),
})
}));
```

0 comments on commit 2be8e60

Please sign in to comment.