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/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.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.Oh, maybe I'm missing a reader to make that happen
Yep, added pc/open-ident-reader
to my list of readers and it works as expected.