mattkrick / cashay

:moneybag: Relay for the rest of us :moneybag:
MIT License
453 stars 28 forks source link

@localFilter @localSort #114

Closed mattkrick closed 8 years ago

mattkrick commented 8 years ago

Consider the following:

`query {
  getTeamById(id: $id) {
    id
    name
    teamMembers (memberSort: $preferredName) @localSort(field: $doo) {
      id
      preferredName
      projects (projectFilter: $isActive) @localFilter {
        id
        content
      }
    }
  }
}`

The sort/filter variables are going to be passed directly to the server. However, it's possible that we pull every doc from the server & then want to sort on different fields locally. Cashay doesn't know what sort/filter mean, so it needs its own directives: localSort, localFilter. The API might look like this: @localSort(field), @localFilter(field)

Then, you just pass in an object that looks like this:

const options = {
  localFilter: {
    [field]: (doc) => doc.content !== ''
  },
  localSort: {
    [field]: (a,b) => a.preferredName > b.preferredName
  }
}
mattkrick commented 8 years ago

thoughts? @jordanh

jordanh commented 8 years ago

Whoa, interesting. I can see why you'd want to do this. If you can't get it all in a single query, you'd have to do this work somewhere. I think this increases both utility and readability. The holy grail! 🍸

Yes, yes I say. Radness.

Would they combine with the @live directive? I imagine they would...

mattkrick commented 8 years ago

yeah, this would cover all of our usecases except for the meeting members, where we derive things like isConnected, isSelf. For things like that, we can memoize external to cashay.

mattkrick commented 8 years ago

closed with v0.20.0