Built-in Plugins

Here you will find information about built-in plugins.

[com.wsscode.pathom3.connect.built-in.plugins :as pbip]

Attribute errors

Pathom 3 keeps errors inside the meta-data in responses.

One way to expose these errors in the data is using the attribute-error-plugin.

Example setup:

(ns com.wsscode.pathom3.docs.built-in-plugins
(:require [com.wsscode.pathom3.connect.built-in.plugins :as pbip]
[com.wsscode.pathom3.connect.built-in.resolvers :as pbir]
[com.wsscode.pathom3.connect.indexes :as pci]
[com.wsscode.pathom3.interface.eql :as p.eql]
[com.wsscode.pathom3.plugin :as p.plugin]))
(def env
(-> (pci/register (pbir/single-attr-resolver :x :y inc))
(p.plugin/register (pbip/attribute-errors-plugin))))
(p.eql/process env
{:x "foo"}
[:y])
=>
{:com.wsscode.pathom3.connect.runner/attribute-errors
{:y #error{:cause "class java.lang.String cannot be cast to class java.lang.Number (java.lang.String and java.lang.Number are in module java.base of loader 'bootstrap')",
:via [{:type java.lang.ClassCastException,
:message "class java.lang.String cannot be cast to class java.lang.Number (java.lang.String and java.lang.Number are in module java.base of loader 'bootstrap')",
:at [clojure.lang.Numbers
inc
"Numbers.java"
137]}],
:trace ...}}}

This plugin uses the same error finding described in the debugging page.

Remove stats

This plugin removes all run-stats meta-data from the response, including in the nested responses.

One example case you may need this plugin is to provide a Pathom API. In production, in case you use transit with meta support. It's important to remove this meta to avoid massive payloads.

(ns com.wsscode.pathom3.docs.built-in-plugins
(:require [com.wsscode.pathom3.connect.built-in.plugins :as pbip]
[com.wsscode.pathom3.connect.built-in.resolvers :as pbir]
[com.wsscode.pathom3.connect.indexes :as pci]
[com.wsscode.pathom3.interface.eql :as p.eql]
[com.wsscode.pathom3.plugin :as p.plugin]))
(def env
(-> (pci/register (pbir/single-attr-resolver :x :y inc))
(p.plugin/register pbip/remove-stats-plugin)))
(-> (p.eql/process env
{:x 10}
[:y])
meta)
=> {}

For API's its expected to combine this plugin with the attribute-error plugin. The order of these plugins is important, remember to keep remove-stats-plugin on top:

(def env
(-> (pci/register (pbir/single-attr-resolver :x :y inc))
(p.plugin/register
[pbip/remove-stats-plugin
(pbip/attribute-errors-plugin)])))

Resolve mutations params

On Pathom, when you call a mutation, the params flow without any alteration. The default behavior is meant to give the fastest path possible to invoke mutations.

That said, it's common also to want the params to be "resolved", just like Pathom does with inputs on resolvers.

To make that happen, you can use the mutation-resolve-params built-in plugin. When you add this plugin, Pathom will use the ::pco/params as a query and will run that on the user params, and then deliver the resolved data to the mutation.

Example:

(pco/defmutation foo [{:keys [b]}]
{:res b})
(p.eql/process
(-> (pci/register
[(pbir/single-attr-resolver :a :b inc)
foo])
(p.plugin/register pbip/mutation-resolve-params))
['(foo {:a 1})])
; => {foo {:res 2}}
tip

When using pco/defmutation, ::pco/params is inferred from the argument destructuring.