cashay icon indicating copy to clipboard operation
cashay copied to clipboard

RFC: @computed directive

Open mattkrick opened this issue 7 years ago • 0 comments

let's say you have a bunch of agenda items

  1. mow the lawn
  2. eat
  3. ???
  4. profit

The URL looks like this /agenda/2 Since we're on page 2, that means 1 must be completed, so it should have a strikethrough. That also means "eat" should be BOLD, since that's active.

This is an example of merging local state with domain state. I have a goal to declaratively put house all data requirements inside a GraphQL query

to do this one, the query might look like this:

agenda(teamId: $teamId) @live {
    id
    content
    isComplete
    sortOrder
    teamMemberId
    status @computed
}

The problem is that GraphQL doesn't provide the index to each child. We could do it internally & give it something like source.__idx.

Relying on index is fascinating because the sort/filter doesn't happen until after the index, which means we'd have to denormalize the values, perform a sort/filter, then go back & fill in the computed values.

This is actually pretty easy. When resolving a scalar, see if it's computed. If so, don't write a value yet. Instead, push a function that will write a value to the field to an computedValQueue. Then, after sort/filter, run through the computedValueQueue stack. We'll only run this once, in case people get cute & try to sort on a computed value.

mattkrick avatar Sep 09 '16 21:09 mattkrick