Fork me on GitHub
#pathom
<
2019-08-30
>
kenny18:08:06

I am getting an error from a missing mutation:

#:integration{retract "class clojure.lang.ExceptionInfo: Mutation not found - {:mutation integration/retract}"}
What would be removing the pathom errors key from the parsers return value?

kenny18:08:17

Actually there doesn't seem to be an error key for this?

(def example-parser
    (p/parser
      {::p/env     {::p/reader               [p/map-reader
                                              pc/reader2
                                              pc/open-ident-reader
                                              p/env-placeholder-reader]
                    ::p/placeholder-prefixes #{">"}}
       ::p/mutate  pc/mutate
       ::p/plugins [(pc/connect-plugin {::pc/register []})
                    p/error-handler-plugin
                    ;; removes ::p/not-found from outputs
                    (p/post-process-parser-plugin p/elide-not-found)
                    p/request-cache-plugin
                    p/trace-plugin]}))

(example-parser {} `[(foo/bar {})])
#:foo{bar #:com.wsscode.pathom.core{:reader-error "class clojure.lang.ExceptionInfo: Mutation not found - {:mutation foo/bar}"}}

kenny18:08:49

What is the first arg to ::p/process-error fn?

kenny19:08:41

Yeah, when a mutation throws an exception, no ::p/errors key is attached to the return.

wilkerlucio20:08:41

@kenny hello, this code is the full example? the mutation seems to be really missing there, also I'm not seeing a configuration for the ::p/process-error

wilkerlucio20:08:57

what you are seeing is just the default error implementation

wilkerlucio20:08:19

altough is not the best, I don't wanna change because that would mean break the interface for current users that for any reasons didn't need to change it

kenny20:08:19

@wilkerlucio Yes this is the full example. When an error occurs with a non-mutation resolver, you get the ::p/errors get on the top level map. This lets higher level code decide what to do with the response (e.g. if an error occurred perhaps send a 500 HTTP response to the client).

wilkerlucio20:08:29

@kenny this goes a bit against the idea of soft fails, Pathom embraces that if one thing fail, others can still succeed, so we don't encourage this, but if you think makes sense for you, you can do via plugin, you can detect mutations (symbols in the root map) and check on that as well (that + root), makes sense?

kenny20:08:24

@wilkerlucio I suppose I could do that. The asymmetry here is a bit confusing though. For example:

(pc/defmutation example-mutation
  [_ _]
  {::pc/sym    'example
   ::pc/input  []
   ::pc/output []}
  (throw (ex-info "uh oh" {})))

(pc/defresolver example-resolver-throwing
  [_ _]
  {::pc/output [:foo]}
  (throw (ex-info "uh oh" {})))

(def example-parser
  (p/parser
    {::p/env     {::p/reader               [p/map-reader
                                            pc/reader2
                                            pc/open-ident-reader
                                            p/env-placeholder-reader]
                  ::p/placeholder-prefixes #{">"}}
     ::p/mutate  pc/mutate
     ::p/plugins [(pc/connect-plugin {::pc/register [example-mutation
                                                     example-resolver-throwing]})
                  p/error-handler-plugin
                  p/request-cache-plugin
                  p/trace-plugin]}))
Calling the resolver:
(example-parser
    {}
    [:foo])
=> {:foo :com.wsscode.pathom.core/reader-error,
 :com.wsscode.pathom.core/errors {[:foo] "class clojure.lang.ExceptionInfo: uh oh - {}"}}
Calling the mutation:
(example-parser
    {}
    '[(example {})])
=> {example #:com.wsscode.pathom.core{:reader-error "class clojure.lang.ExceptionInfo: uh oh - {}"}}

kenny20:08:51

It's strange that both mutations and resolvers handle errors differently.

kenny20:08:25

I would've expected the mutation call to attach ::p/errors just like the resolver call did.

wilkerlucio20:08:22

@kenny yeah, I can understand the issue with the inconsistency there, to be honest, these days I do the opposite, I move the errors from the outside to the inside (makes much easier to report problems in the UI), pathom has a specific helper for that: https://github.com/wilkerlucio/pathom/blob/master/src/com/wsscode/pathom/core.cljc#L825-L846

wilkerlucio20:08:41

the reason this ended up happening was historical, I kind copy over what GraphQL did in terms of errors (having a separated branch)

wilkerlucio20:08:00

but after experience doing it I feel like its better to have then in the same level they happen

kenny20:08:29

It's definitely a bit strange because typically you want the HTTP status code to match what happened with request processing.

kenny20:08:10

@wilkerlucio Is there a way to change the format of errors? e.g. I want them to be in a cognitect anomaly.

wilkerlucio21:08:56

@kenny yes, use the ::p/process-error in your env

wilkerlucio21:08:04

then you have full control about how they get exposed

kenny21:08:32

Oh cool! Pathom won't care that I messed with those things?

wilkerlucio21:08:47

no, that's expected

wilkerlucio21:08:55

I mean, this how to format the error output, the position will remain

kenny21:08:20

What is the first arg to ::p/process-error fn?