Skip to content

Commit

Permalink
Add support for ::pc/transform in attribute-resolver (#53)
Browse files Browse the repository at this point in the history
  • Loading branch information
tylernisonoff authored Dec 30, 2020
1 parent 39f7801 commit d81892c
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 8 deletions.
10 changes: 10 additions & 0 deletions src/main/com/fulcrologic/rad/attributes_options.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,16 @@
"
:com.wsscode.pathom.connect/input)

(def pc-transform
"ALIAS to :com.wsscode.pathom.connect/transform.
See the pathom transform docs: https://blog.wsscode.com/pathom/#connect-transform
Allows one to specify a function that receives the full resolver/mutation map and returns the final version.
Generally used to wrap the resolver/mutation function with some generic operation to augment its data or operations.
"
:com.wsscode.pathom.connect/transform)

(def read-only?
"Boolean or `(fn [form-instance attribute] boolean?)`. If true it indicates to the form and db layer that writes
of this value should not be allowed. Enforcement is an optional feature. See you database adapter and rendering
Expand Down
19 changes: 11 additions & 8 deletions src/main/com/fulcrologic/rad/resolvers.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -42,19 +42,22 @@
or nil."
[attr]
[::attr/attribute => (? ::pc/resolver)]
(enc/when-let [resolver (::pc/resolve attr)
(enc/when-let [resolver (::pc/resolve attr)
secure-resolver (fn [env input]
(->>
(resolver env input)
(auth/redact env)))
k (::attr/qualified-key attr)
output [k]]
k (::attr/qualified-key attr)
output [k]]
(log/info "Building attribute resolver for" (::attr/qualified-key attr))
(merge
{::pc/output output}
(just-pc-keys attr)
{::pc/sym (symbol (str k "-resolver"))
::pc/resolve secure-resolver})))
(let [transform (::pc/transform attr)]
(cond-> (merge
{::pc/output output}
(just-pc-keys attr)
{::pc/sym (symbol (str k "-resolver"))
::pc/resolve secure-resolver})
transform transform
))))

(>defn generate-resolvers
"Generate resolvers for attributes that directly define pathom ::pc/resolve keys"
Expand Down

0 comments on commit d81892c

Please sign in to comment.