mst-gql
mst-gql copied to clipboard
Make primitives easily chainable
My understanding with primitives is that you have to do something like this to actually be able to continue the chain.
rs => rs.id._(postReactionModelPrimitives.__query).user(blahblah)
Wouldn't be cleaner and more flexible to have
const postReactionModelPrimitives = rs => rs.id.foo.bar.car
That way we could do:
rs => postReactionModelPrimitives(rs).user(blahblah)
Or maybe I'm missing something from the documentation?
I'm not entirely sure what is going on here, what is your use case?
Nevermind, I figured out how to chain these query selectors, we're all good!
Actually @chrisdrackett seems like I'm not out of the woods. When it comes to building selectors, it's quite confusing. There are three variations...all of them "work".
const basicUserSelectorA = (new UserModelSelector()).id.fullName.username
const basicUserSelectorB = u => u.id.fullName.username
queryUser({}, rs => rs.result.user(basicUserSelectorA.foo.bar))
queryUser({}, rs => rs.result.user(u => basicUserSelectorB(u).foo.bar)
queryUser({}, rs => rs.result.user(() => basicUserSelectorA.foo.bar))
All three "work", however I found that when I create long queries, with every refresh, my query would keep concatenating on itself and I would end up with an every increasing query.
This would only happen in this variation:
queryUser({}, rs => rs.result.user(basicUserSelectorA.foo.bar))
How exactly is the recommended way to build selectors, A or B?
And then if you need to combine selectors on the same object, how do you do it.
For example, I have want to have two different selectors:
const basicUserSelectorA = (new UserModelSelector()).id.fullName.username
const basicUserSelectorC = (new UserModelSelector()).birthday
I noticed that the "primitives" auto created by mst-gql are build in this way (not the arrow function way as in basicUserSelectorB). How do you combine two together. Do you have to do:
basicUserSelectorA._(basicUserSelectorC)
^^ Like that?
@Aryk sounds like what you are running into might be related to https://github.com/mobxjs/mst-gql/issues/206
I don't use these selectors / selector builders myself, so it's hard to me to currently comment on how this currently / should work at the moment without digging deeper.
Just curious, do you know if it's required to select the "id" or ID field in the results selector? I've noticed the primitives don't have that included, so I'm wondering how MST GQL knows to assign those attributes to the item in the store with that "id" if the id is not explicitly included.
I believe that both id and __typename are always added as part of the query builder. We still explicitly add them ourselves, just to be safe.
Got it, that's what I thought...I pretty sure it does that bc I left it off a few times and things still work.