Skip to content

Instantly share code, notes, and snippets.

@Yogu
Yogu / aggregators.md
Last active June 17, 2019 16:59
cruddl aggregators (draft)

Collect fields

With the @collect directive, you can define fields that are not persisted but rather compute their value when queried, based on other fields. It allows you to follow a path of relations, child entities and other fields, collect these values and optionally apply aggregations on them.

Basics

Relations and child entity let you define a graph of objects that can be selected by regular GraphQL fields. If you're not interested in the graph structure but only in the objects, you can define a @collect field that follows a path and collects all objects on the way:

type OrderItem @childEntity {
schema {
query: Object159
mutation: Object2
subscription: Object1
}
interface Interface1 {
field1604: ID!
field1605: ID
field1606: String
// prints how long in the past the current "end" of the stream is
// this is a lower bound on latency that's viewer-independent
// put in the m3u of a stream
// e.g. just open network tab, refresh, then filter for m3u
// don't use the meta one (the first) but the one that's called repeatedly
const playlistUrl = "";
async function test() {
const minNow = new Date().getTime();