pathom

:pathom: https://github.com/wilkerlucio/pathom/ & https://pathom3.wsscode.com & https://roamresearch.com/#/app/wsscode
yenda 2020-08-08T12:31:01.405900Z

Is is possible to make the parser use idents in nested queries and put the node at the top level of the output to avoid repetition? Example:

{[user/id "x"] {:user/name "bob}
 :comments [{:message "yo" :>/user [:user/id "x"]}
            {:message "hi" :>/user [:user/id "x"]}]}

yenda 2020-08-08T12:32:56.407500Z

The motivation for that being obviously that it can drastically reduce the size of the response, and it also fits much better with libraries like re-frame which will be perfectly capable of exploiting normalized data like this, instead of having to re-parse and normalize client side

wilkerlucio 2020-08-08T13:39:11.407600Z

from pathom perspective, no, ident normalization is not a concept in pathom, given in Pathom idents just mean setting a value. this also respects a principle that the shape of the response must match the shape of the query, this avoids the user having to deal with complicated things to understand the output shape, by always being the same is simple and predictable

wilkerlucio 2020-08-08T13:39:30.407800Z

what you can do is write some post-processing plugin to move things around after the response is built, makes sense?

yenda 2020-08-08T14:24:52.408100Z

is the placeholder plugin a post processing too? Because what I want to do is basically instead of putting the content, put the indent and move the content to the top level

wilkerlucio 2020-08-08T16:22:54.408600Z

I don't fully understand yet what you are trying to do. can you send a more complete example, with the queyr, and an example of the result structure you are trying to achieve?

yenda 2020-08-08T21:07:00.409100Z

@wilkerlucio query:

[{[:video/id "8ec67237"]
   [:video/id
    {:video/comments
     [:comment/created-on
      {:>/user
       [:user/id
        :user/username
        :user/photo]}
      :comment/id
      {:comment/replies
       [:comment/created-on
        :comment/parent-id
        {:>/user
         [:user/id
          :user/username
          :user/photo]}
        :comment/id
        :comment/text
        :comment/deleted?
        {:comment/mentioned
         [:user/username
          :user/id
          :user/photo]}]}
      :comment/text
      :comment/deleted?]}]}]
response:
{[:video/id "8ec67237"]
 {:video/comments
  [{:comment/created-on 1596324395885,
    :comment/deleted? false,
    :comment/replies
    [{:comment/created-on 1596328542657,
      :comment/deleted? false,
      :comment/id "18ce6026",
      :comment/parent-id "7122c0bf",
      :>/user
      {:user/username "aaaa",
       :user/id "02a4a06c46e9",
       :user/photo
       "6b4439a5.jpeg",},
      :comment/text "Lmfao ong"}],
    :comment/id "12a4a06c46e9",
    :>/user
    {:user/username "bbbb",
     :user/id "0270e3394d0f",
     :user/photo
     "31baab0e.jpeg",},
    :comment/text "the bear rn ????"}
   {:comment/created-on 1596326350002,
    :comment/deleted? false,
    :comment/replies
    [{:comment/created-on 1596333223465,
      :comment/deleted? false,
      :comment/id "02a4a06c46e9",
      :comment/parent-id "02a4a06c46e9",
      :>/user
      {:user/username "bbbb",
       :user/id "0270e3394d0f",
       :user/photo
       "31baab0e.jpeg",},
      :comment/text "Nope ?"}],
    :comment/id "02a4a08c46e9",
    :>/user
    {:user/username "bbbb",
     :user/id "0270e3394d0f",
     :user/photo
     "31baab0e.jpeg",},
    :comment/text "Follow me ?"}],
  :video/id "8ec67237"}}
what I want to achieve:
{[:video/id "8ec67237"]
 {:video/comments
  [{:comment/created-on 1596324395885,
    :comment/deleted? false,
    :comment/replies
    [{:comment/created-on 1596328542657,
      :comment/deleted? false,
      :comment/id "18ce6026",
      :comment/parent-id "7122c0bf",
      :>/user [:user/id "02a4a06c46e9"] ,
      :comment/text "Lmfao ong"}],
    :comment/id "12a4a06c46e9",
    :>/user [:user/id "0270e3394d0f"],
    :comment/text "the bear rn ????"}
   {:comment/created-on 1596326350002,
    :comment/deleted? false,
    :comment/replies
    [{:comment/created-on 1596333223465,
      :comment/deleted? false,
      :comment/id "02a4a06c46e9",
      :comment/parent-id "02a4a06c46e9",
      :>/user [:user/id "0270e3394d0f"],
      :comment/text "Nope ?"}],
    :comment/id "02a4a08c46e9",
    :>/user [:user/id "0270e3394d0f"] ,
    :comment/text "Follow me ?"}],
  :video/id "8ec67237"}
 [:user/id "02a4a06c46e9"] {:user/username "aaaa",
                            :user/id "02a4a06c46e9",
                            :user/photo
                            "6b4439a5.jpeg",}
 [:user/id "0270e3394d0f"] {:user/username "bbbb",
                            :user/id "0270e3394d0f",
                            :user/photo
                            "31baab0e.jpeg",}}

wilkerlucio 2020-08-08T21:10:39.409600Z

to do that you need to figure how to identify each entity in the response tree, this is another kind of information layer, one that's not part of Pathom, you can do it on the same way fulcro does, if at each level you make a way to generate an ident, so you can normalize, but from pathom itself, not enough information (and I think is something to be implemented in user code area as extension, not a core part of pathom, you can do as a post-process)