Skip to main content

Built-in Plugins

Here you will find information about built-in plugins.

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

Extend environment

The plugin pbip/env-wrap-plugin provides a simple way to inject dynamic content at the env at the start of each request.

The following example demonstrates how to set an attribute :now in the env that contains the time that the process starts:

(def env
(-> (pci/register (pbir/constantly-fn-resolver :time :now))
(p.plugin/register
[(pbip/env-wrap-plugin #(assoc % :now (java.util.Date.)))])))

(p.eql/process env [:time]) ; => {:time #inst "..."}

The env-wrap-plugin takes a function that will receive the env and should return the modified env.

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.