(defmutation name docstring? arglist options? & body)
Defines a new Pathom mutation. The syntax of this macro is similar to defresolver,
But where defresolver
takes input, defmutation
uses as ::params.
Defines a new Pathom mutation. The syntax of this macro is similar to defresolver, But where `defresolver` takes input, `defmutation` uses as ::params.
(defresolver name docstring? arglist options? & body)
Defines a new Pathom resolver.
Resolvers are the central abstraction around Pathom, a resolver is a function that contains some annotated information and follow a few rules:
Here are some examples of how you can use the defresolver syntax to define resolvers:
The verbose example:
(pco/defresolver song-by-id [env {:acme.song/keys [id]}]
{::pco/input [:acme.song/id]
::pco/output [:acme.song/title :acme.song/duration :acme.song/tone]
::pco/params []
::pco/transform identity}
(fetch-song env id))
The previous example demonstrates the usage of the most common options in defresolver.
But we don't need to write all of that, for example, instead of manually saying the ::pco/input, we can let the defresolver infer it from the param destructuring, so the following code works the same (::pco/params and ::pco/transform also removed, since they were no-ops in this example):
(pco/defresolver song-by-id [env {:acme.song/keys [id]}]
{::pco/output [:acme.song/title :acme.song/duration :acme.song/tone]}
(fetch-song env id))
This makes for a cleaner write, now lets use this format and write a new example resolver:
(pco/defresolver full-name [env {:acme.user/keys [first-name last-name]}]
{::pco/output [:acme.user/full-name]}
{:acme.user/full-name (str first-name " " last-name)})
The first thing we see is that we don't use env, so we can omit it.
(pco/defresolver full-name [{:acme.user/keys [first-name last-name]}]
{::pco/output [:acme.user/full-name]}
{:acme.user/full-name (str first-name " " last-name)})
Also, when the last expression of the defresolver is a map, it will infer the output shape from it:
(pco/defresolver full-name [{:acme.user/keys [first-name last-name]}]
{:acme.user/full-name (str first-name " " last-name)})
You can always override the implicit input and output by setting on the configuration map.
Standard options:
::pco/output - description of resolver output, in EQL format ::pco/input - description of resolver input, in EQL format ::pco/params - description of resolver parameters, in EQL format ::pco/transform - a function to transform the resolver configuration before instantiating the resolver ::pcr/cache? - true by default, set to false to disable caching for the resolver
Note that any other option that you send to the resolver config will be stored in the index and can be read from it at any time.
The returned value is of the type Resolver, you can test your resolver by calling directly:
(full-name {:acme.user/first-name "Ada"
:acme.user/last-name "Lovelace"})
=> "Ada Lovelace"
Note that similar to the way we define the resolver, we can also omit env
(and even
the input) when calling, the resolvers fns always support arity 0, 1 and 2.
Defines a new Pathom resolver. Resolvers are the central abstraction around Pathom, a resolver is a function that contains some annotated information and follow a few rules: 1. The resolver input must be a map, so the input information is labelled. 2. A resolver must return a map, so the output information is labelled. 3. A resolver also receives a separated map containing the environment information. Here are some examples of how you can use the defresolver syntax to define resolvers: The verbose example: (pco/defresolver song-by-id [env {:acme.song/keys [id]}] {::pco/input [:acme.song/id] ::pco/output [:acme.song/title :acme.song/duration :acme.song/tone] ::pco/params [] ::pco/transform identity} (fetch-song env id)) The previous example demonstrates the usage of the most common options in defresolver. But we don't need to write all of that, for example, instead of manually saying the ::pco/input, we can let the defresolver infer it from the param destructuring, so the following code works the same (::pco/params and ::pco/transform also removed, since they were no-ops in this example): (pco/defresolver song-by-id [env {:acme.song/keys [id]}] {::pco/output [:acme.song/title :acme.song/duration :acme.song/tone]} (fetch-song env id)) This makes for a cleaner write, now lets use this format and write a new example resolver: (pco/defresolver full-name [env {:acme.user/keys [first-name last-name]}] {::pco/output [:acme.user/full-name]} {:acme.user/full-name (str first-name " " last-name)}) The first thing we see is that we don't use env, so we can omit it. (pco/defresolver full-name [{:acme.user/keys [first-name last-name]}] {::pco/output [:acme.user/full-name]} {:acme.user/full-name (str first-name " " last-name)}) Also, when the last expression of the defresolver is a map, it will infer the output shape from it: (pco/defresolver full-name [{:acme.user/keys [first-name last-name]}] {:acme.user/full-name (str first-name " " last-name)}) You can always override the implicit input and output by setting on the configuration map. Standard options: ::pco/output - description of resolver output, in EQL format ::pco/input - description of resolver input, in EQL format ::pco/params - description of resolver parameters, in EQL format ::pco/transform - a function to transform the resolver configuration before instantiating the resolver ::pcr/cache? - true by default, set to false to disable caching for the resolver Note that any other option that you send to the resolver config will be stored in the index and can be read from it at any time. The returned value is of the type Resolver, you can test your resolver by calling directly: (full-name {:acme.user/first-name "Ada" :acme.user/last-name "Lovelace"}) => "Ada Lovelace" Note that similar to the way we define the resolver, we can also omit `env` (and even the input) when calling, the resolvers fns always support arity 0, 1 and 2.
(input-destructure-missing {:com.wsscode.pathom3.connect.operation/keys
[input inferred-input]})
(mutation {:com.wsscode.pathom3.connect.operation/keys [transform] :as config})
(mutation op-name config mutate)
Helper to create a mutation. A mutation must have a name and the mutate function.
You can create a mutation using a map:
(mutation
{::op-name 'foo
::output [:foo]
::mutate (fn [env params] ...)})
Or with the helper syntax:
(mutation 'foo {} (fn [env params] ...))
Returns an instance of the Mutation type.
Helper to create a mutation. A mutation must have a name and the mutate function. You can create a mutation using a map: (mutation {::op-name 'foo ::output [:foo] ::mutate (fn [env params] ...)}) Or with the helper syntax: (mutation 'foo {} (fn [env params] ...)) Returns an instance of the Mutation type.
(normalize-arglist arglist)
Ensures arglist contains two elements.
Ensures arglist contains two elements.
(params env)
Pull parameters from environment. Always returns a map.
Pull parameters from environment. Always returns a map.
(params->mutation-options {:keys [arglist options body docstring]})
(params->resolver-options {:keys [arglist options body docstring]})
(resolver {:com.wsscode.pathom3.connect.operation/keys [transform op-name
inferred-input input]
:as config})
(resolver op-name config)
(resolver op-name config resolve)
Helper to create a resolver. A resolver have at least a name, the output definition and the resolve function.
You can create a resolver using a map:
(resolver
{::op-name 'foo
::output [:foo]
::resolve (fn [env input] ...)})
Or with the helper syntax:
(resolver 'foo {::output [:foo]} (fn [env input] ...))
Returns an instance of the Resolver type.
Helper to create a resolver. A resolver have at least a name, the output definition and the resolve function. You can create a resolver using a map: (resolver {::op-name 'foo ::output [:foo] ::resolve (fn [env input] ...)}) Or with the helper syntax: (resolver 'foo {::output [:foo]} (fn [env input] ...)) Returns an instance of the Resolver type.
(update-config operation f)
(update-config operation f a1)
(update-config operation f a1 a2)
(update-config operation f a1 a2 a3)
(update-config operation f a1 a2 a3 a4)
(update-config operation f a1 a2 a3 a4 a5)
(update-config operation f a1 a2 a3 a4 a5 a6)
(update-config operation f a1 a2 a3 a4 a5 a6 a7)
(update-config operation f a1 a2 a3 a4 a5 a6 a7 a8)
(update-config operation f a1 a2 a3 a4 a5 a6 a7 a8 a9)
(update-config operation f a1 a2 a3 a4 a5 a6 a7 a8 a9 & args)
Returns a new resolver with the modified config. You can use this to change anything in the resolver configuration map. The only thing you can't change from here is the resolver or mutation functions. You can use the wrap-resolve and wrap-mutation helpers to do that.
Returns a new resolver with the modified config. You can use this to change anything in the resolver configuration map. The only thing you can't change from here is the resolver or mutation functions. You can use the wrap-resolve and wrap-mutation helpers to do that.
(with-node-params params)
(with-node-params env params)
Set current node params to params.
Set current node params to params.
(wrap-mutate mutation f)
Return a new mutation with the resolve fn modified. You can use the previous fn or just replace. Here is a noop wrapper example:
(wrap-mutate mutation (fn [mutate] (fn [env params] (mutate env params)))
Return a new mutation with the resolve fn modified. You can use the previous fn or just replace. Here is a noop wrapper example: (wrap-mutate mutation (fn [mutate] (fn [env params] (mutate env params)))
(wrap-resolve resolver f)
Return a new resolver with the resolve fn modified. You can use the previous fn or just replace. Here is a noop wrapper example:
(wrap-resolve resolver (fn [resolve] (fn [env input] (resolve env input)))
Return a new resolver with the resolve fn modified. You can use the previous fn or just replace. Here is a noop wrapper example: (wrap-resolve resolver (fn [resolve] (fn [env input] (resolve env input)))
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close