Fork me on GitHub
Gleb Posobin04:12:37

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?


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

Chris O’Donnell23:12:30

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.

Chris O’Donnell23:12:09

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

Chris O’Donnell23:12:40

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

duckie 3