Skip to content

Conditional dereferencing of elements #372

Closed Answered by scottrippey
mrr11k asked this question in Q&A
Discussion options

You must be logged in to vote

This is officially supported now! With #378 and #376 .

You can do the following: Link to arcade

  q.star
   .filterByType("pokemon")
   .project(q => ({
     name: z.string(),
     types: q.field("types[]").project(q => ({
       ...q.conditionalByType({
         reference: q => q.field("@").deref(),
         link: q => q.field("@"),
       }),
     })),
   }))

Notice the q.field("@") syntax, which is strongly-typed!

Replies: 2 comments 4 replies

Comment options

You must be logged in to vote
3 replies
@scottrippey
Comment options

@mrr11k
Comment options

@scottrippey
Comment options

Comment options

You must be logged in to vote
1 reply
@mrr11k
Comment options

Answer selected by scottrippey
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
enhancement New feature or request groqd-v1 Related to the newer `v1.x` package
2 participants