Fork me on GitHub
#fulcro
<
2023-11-28
>
norman18:11:06

Is it reasonable to merge two queries (for a df/load) for if they have the same ident? For example, component1 queiries [:a :b] and component2 queries [:b :c] . I'm not concerned with how to actually merge the query to get [:a :b :c] - I know the logic I want to use. I'm concerned about the metadata of the query and whether there's something hidden going on I should be concerned about. I normally just create a component with hand-merged query [:a :b :c] , but I'm starting to get cases where I have 4 or 5 attribute sets that I want to load in various combinations and it feels awkward to write a component for each combination

tony.kay00:11:39

So technically IF you use the EQL AST and preseve the :component entry (make sure there is a :component on the metadata that has the correct ident function), then it should be fine as long as the ident function on the component is the same.

tony.kay00:11:55

and merge-queries

tony.kay00:11:52

The problem that you are then going to run into is that the load itself wants a component, not a query; however, you can work around that one by making your own load function wrapper that just triggers the internal load mutation.

tony.kay00:11:14

If you look at the implementation of df/load!, you’ll see that it extracts the query from the component. I used to have a load-data that would allow for an arbitrary query, but since the normalization logic on that wasn’t very clear I decided that this kind of advanced usage would be better to just let you do via direct use of the internal-load! mutation.

tony.kay00:11:36

(transact! this [(df/internal-load! 
  {:source-key :person/all
   :query (comp/get-query Person)
   :remote :remote})])
should be exactly equivalent to (df/load! this :person/all Person)

norman00:11:52

Thanks. I'll try that out!