Fork me on GitHub
#pathom
<
2022-06-30
>
hadils17:06:39

I am trying to use (non-dynamic) resolvers with Datomic pull syntax. I thought it would map easily, but the problem is that if there insufficient data from the pull, then Pathom is throwing an error. I would like it to return nil or find a way to process the error. I am really stuck on this. Any help would be greatly appreciated!

markaddleman17:06:15

Your resolver will have to merge in the nil values. You might try something like this:

(merge {:output/one nil, :output/two nil ...}
       (datomic/pull ...))

markaddleman17:06:46

If you want to be a bit more dynamic, I think there's a way for your resolver to introspect the Pathom environment to discover its output variable.

hadils17:06:13

Thanks @U2845S9KL! That is an excellent way to resolve my issue!

👍 1
roklenarcic18:06:37

Note that expects value that describes the desired output does not describe whether the properties needed are single map or a collection

hadils18:06:01

I need both.

wilkerlucio19:06:04

another option is to use lenient mode, which is fine with partial errors, but this choice should be made depending if you are more like "I need all or nothing" (strict mode, which is the default) or "get me whatever you can and I'll work with it" (lenient mode) https://pathom3.wsscode.com/docs/error-handling#lenient-mode

wilkerlucio19:06:25

the approach of merging is fine and I also used it a bunch of times, but keep in mind that when you do that, you lose the ability to have a separate resolver for those keys from a different source, its not a bad thing nescessarily, but something to keep in mind

hadils19:06:10

I don’t know how to correctly use lenient mode. The errors jam up my middleware, because I don’t process them correctly. Do you have a code snippet for error handling

wilkerlucio19:06:24

lenient mode will always give a map with data, and error details for anything that failed, present at the same level (entity) that had that attr failure, the error handling here is different because you moved from "all or nothing" to partial errors, and when dealing with partial errors you have to handle errors for each attribute individually

wilkerlucio19:06:53

this mode is recommended for example when doing UI's with Fulcro, given that most UI's are fine with partial data missing, but then the UI must check issues per attribute

hadils19:06:53

Ok. I can check on the UI side (I am using re-frame). The difficulty I am having is that the errors don’t serialize properly, so my middleware crashes on it. Any suggestions for that?

wilkerlucio19:06:34

are you using the latest pathom? serialization shouldn't be a problem, but if you are on latest and it is, let me know and we can dig on it

wilkerlucio19:06:01

(latest is 2022.06.01-alpha)

hadils19:06:21

I am using

"2022.06.01-alpha"
I think Exceptions are not serializable. I am using muuntaja

wilkerlucio19:06:58

ok, gimme a sec to check something

wilkerlucio19:06:48

I just tried this demo:

(pco/defresolver error []
  {:error (throw (ex-info "err" {}))})

(def env (-> {:com.wsscode.pathom3.error/lenient-mode? true}
             (pci/register [error])))

(comment
  (p.eql/process env [:error]))

wilkerlucio19:06:16

when I look at the response, its just maps, no Exception entry, so I wonder what is going on at your end

wilkerlucio19:06:35

this is what I see here:

hadils19:06:09

I am using

(defn parser [] (p.eql/boundary-interface pathom))

hadils19:06:27

I am not sure about the boundary interface.

wilkerlucio19:06:17

should yield the same result (tested here):

(pco/defresolver error []
  {:error (throw (ex-info "err" {}))})

(def env (-> {:com.wsscode.pathom3.error/lenient-mode? true}
             (pci/register [error])))

(def request (p.eql/boundary-interface env))

(comment
  (request [:error]))

hadils19:06:26

Ok, let me try it out and respond.

hadils20:06:58

I get the same result as you do.

wilkerlucio20:06:26

so we have to figure whats going on during your other call, can you try to log it at your case and see what is getting in the output?

hadils20:06:48

It works for this simple test. There’s is something else wrong with my muuntaja setup. Thanks @U066U8JQJ for your help.

🙏 1