wilkerlucio / pathom3

Interface with complex data via graph mapping.
https://pathom3.wsscode.com
Eclipse Public License 2.0
376 stars 31 forks source link

Undeclared outputs "leaking" into resolvers #109

Closed mauricioszabo closed 3 years ago

mauricioszabo commented 3 years ago

So, recently I made a typo in my output. And it... worked? this seems weird that's possible.

On newer versions of Pathom this don't work anymore, but the output keeps leaking (if I ask for the leaked attribute as an optional input, it'll be accepted. Even worse, it'll be resolved by the query even if we don't want that)

(pco/defresolver root-resolver [_]
  {::pco/output [:a :b]}
  ;; :c is not declared as an output
  {:a 1 :b 2 :c 3})

(pco/defresolver sum-all [{:keys [a b c]}]
  ;; :c leaks to this resolver
  {::pco/input [:a :b (pco/? :c)]
   ::pco/output [:sum]}
  {:sum (+ a b c)})

; This works. Don't know if it should...
(let [env (indexes/register [root-resolver sum-all])
      env (-> env
              (assoc :com.wsscode.pathom3.error/lenient-mode? true))
      q #(eql/process env %)]
  (q [:c :sum]))
wilkerlucio commented 3 years ago

This should work still because :c was marked as optional, and Pathom always merges all the data that comes in, so by the time it calls the :sum it does have :c, even though wasn't declared.

I have some ideas to add some "linter" code to tell the user it should have expressed :c in the output. But in the terms of behavior, it's correct. Closing for now.

mauricioszabo commented 3 years ago

Ok, but if I don't declare, in sum-all, that :c is an optional input that resolver is never called... is that expected too?

wilkerlucio commented 3 years ago

Correct, because them Pathom scan will see no path to do it.

wilkerlucio commented 2 years ago

Yes, that's expected on lenient mode, I think the linter thing will be nice to point when this kind of thing happens, just need to be something that the user chooses to run because it can add some overhead for production apps.