pathom

:pathom: https://github.com/wilkerlucio/pathom/ & https://pathom3.wsscode.com & https://roamresearch.com/#/app/wsscode
Gleb Posobin 2020-12-31T04:55:37.065500Z

Is there a nice way to prevent user for querying some keywords? Say I have a resolver with input = #{:user/id} and output [:user/profile-photo] and use it internally, when resolving say :user/username -> :user/id -> :user/profile-photo , but I don't want to let a user issue queries based on :user/id , they should only be aware of :user/username . Right now I am doing a prewalk over the transaction in a p/pre-process-parser-plugin and replacing all occurrences of the keyword with :forbidden , is there a better solution?

souenzzo 2020-12-31T13:35:51.065800Z

(letfn [(cleanup-query [query allowed-key?]
          (->> query
               eql/query->ast
               (eql/transduce-children (filter (comp allowed-key? :dispatch-key)))
               eql/ast->query))]
  (cleanup-query [:a
                  {:b [:c]}
                  {[:d 1] [:e]}
                  '(f {:g :h})
                  '{(i {:j :k}) [:l]}]
                 #{:a :b :c :d :e 'f 'i :l}))
https://github.com/souenzzo/eql-style-guide/issues/4 I usually do that in my http/middleware stack.

souenzzo 2020-12-31T13:35:51.065800Z

(letfn [(cleanup-query [query allowed-key?]
          (->> query
               eql/query->ast
               (eql/transduce-children (filter (comp allowed-key? :dispatch-key)))
               eql/ast->query))]
  (cleanup-query [:a
                  {:b [:c]}
                  {[:d 1] [:e]}
                  '(f {:g :h})
                  '{(i {:j :k}) [:l]}]
                 #{:a :b :c :d :e 'f 'i :l}))
https://github.com/souenzzo/eql-style-guide/issues/4 I usually do that in my http/middleware stack.

Michael W 2020-12-31T17:55:46.066100Z

@reshef.mann Thanks, that is an awesome article, and gave me a few ideas

Michael W 2020-12-31T17:55:58.066300Z

https://github.com/oliyh/martian

Michael W 2020-12-31T17:56:44.066600Z

I found that too which looks like it does exactly what I wanted but I cannot seem to get it to work against http://swapi.dev as a test

2020-12-31T23:07:30.070Z

I feel like I'm missing something obvious; maybe someone can help. I have this resolver:

(pc/defresolver grocery-item-listing [_ _]
  {::pc/input #{}
   ::pc/output [{:grocery-items [:item/id :item/name :item/position :item/completed-at]}]}
  (go {:grocery-items [{:item/id 1
                        :item/name "Apples"
                        :item/position 1
                        :item/completed-at nil}
                       {:item/id 2
                        :item/name "Oranges"
                        :item/position 2
                        :item/completed-at nil}]}))
This query returns the expected two items:
(let-chan [result (parser {} [{:grocery-items [:item/id :item/name]}])]
    (js/console.log {:result result}))
But if I try to make the same query nested inside an ident, I get :com.wsscode.pathom.core/not-found:
(let-chan [result (parser {} [{[:component/id :grocery-list]
                                 [{:grocery-items [:item/id :item/name]}]}])]
    (js/console.log {:result result}))
I thought making a query a join nested inside an ident just added the ident attribute as an input.

2020-12-31T23:08:09.070300Z

Oh, maybe I'm missing a reader to make that happen

2020-12-31T23:09:40.070700Z

Yep, added pc/open-ident-reader to my list of readers and it works as expected.

1