Fork me on GitHub
#fulcro
<
2022-11-09
>
nigel20:11:13

I have a beginner question. Is it possible to use a dynamic query to derive a set of the results of a component’s query based on another piece of state? Let’s say I have user entities in the Fulcro DB with these properties: {:user/id 1 :user/team 1 :user/name "test-user"} And I have team entities with these properties: {:team/id 1 :team/name "test-team"} And I have some ui state singleton map like {:root/ui {:ui/selected-team 1 } I’d like to have a TeamList component that shows all members of the team that is currently selected int he UI map. I’m imagining something like: (defsc User [_ _] {:query [:user/id :user/name] :ident [:user/id]} …) (defsc TeamList [_ _] {:query [??? (comp/get-query User)] } …) Where ??? is some query fragment that filters users by :team/id.

nigel20:11:44

Looking at this written out, it doesn’t seem like the component query is the right place to filter the query, but if not there, then where? I’ve seen some answers suggest using pathom resolvers, but I don’t want to connect to a server DB or even a client side DB, I’d like to just query the users in the fulcro DB.

cjsauer14:11:43

Maybe you could write a mutation that triggers when a team is selected, and that mutation could perform the filtering and then assoc the results into the proper place. Proper place being your ??? placeholder. Something like :team-list/users.

dvingo20:11:48

This sort of thing is exactly why I started work on a subscriptions library that supports fulcro: https://github.com/matterandvoid-space/subscriptions If you're feeling adventurous you can try using subscriptions to solve this problem with that library. I think it's inane that you would have to use a mutation to solve such a problem.. anyway - happy to assist if you do want to try it out. I have personally stopped using fulcro's UI rendering parts and instead am using helix with subscriptions. You can find an example here: https://github.com/matterandvoid-space/todomvc-fulcro-subscriptions I have spent years learning and building with fulcro and still had trouble figuring out how to solve a simple problem like your filter query example, until I gave up and built something that makes sense to me. It might help you too