Skip to content

Instantly share code, notes, and snippets.

@loliveira
Last active September 30, 2021 11:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save loliveira/5c907135b5a40be747aeb527666b7b7c to your computer and use it in GitHub Desktop.
Save loliveira/5c907135b5a40be747aeb527666b7b7c to your computer and use it in GitHub Desktop.
(p.plugin/defplugin mutation-resolve-params-with-entity
"Remove the run stats from the result meta. Use this in production to avoid sending
the stats. This is important for performance and security.
TODO: error story is not complete, still up to decide what to do when params can't
get fulfilled."
{::pcr/wrap-mutate
(fn mutation-resolve-params-external [mutate]
(fn mutation-resolve-params-internal [env {:keys [key] :as ast}]
(let [{::pco/keys [params]} (pci/mutation-config env key)
entity (p.ent/entity env)
entity-params (merge entity (:params ast))]
(clet [params' (if params
(if (::pcra/async-runner? env)
(p.a.eql/process env entity-params params)
(p.eql/process env entity-params params))
(:params ast))]
(mutate env (assoc ast :params params'))))))})
@wilkerlucio
Copy link

a suggestion: I think params should have higher precedence than inputs (since they are closest to the mutation, the last point), so changing (merge (:params ast) entity) to (merge entity (:params ast)) might be better

@loliveira
Copy link
Author

Done! Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment