claro.data

Main protocols and functions for I/O abstraction.

See Basic Resolution for details and examples.

batched-resolvable?

added in 0.2.7

(batched-resolvable? value)

Check whether the given value implements the Resolvable protocol.

BatchedResolvable

protocol

Interface for values that can be resolved in batches.

Do not use with extend-type or extend-protocol!

collect-errors

added in 0.2.1

(collect-errors value)

Find all errors within the given value.

Cost

protocol

added in 0.2.6

Protocol describing resolution cost for a batch of resolvables. The following default values are produced:

  • 0 for batches of PureResolvable,
  • 1 for batches of BatchedResolvables
  • (count batch) for other batches.

The overall cost can be used when declaring engines by supplying the :max-cost option.

cost

added in 0.2.6

(cost resolvable batch)

Calculate the cost of resolution for the given batch.

error

added in 0.2.1

(error message & [data])

Generate a value representing a resolution error.

error-data

added in 0.2.1

(error-data e)

Retrieve error data from the given error value.

error-message

added in 0.2.1

(error-message e)

Retrieve the message from the given error value.

error?

added in 0.2.1

(error? value)

Check whether the given value represents a resolution error.

extend-list-transform

macro

added in 0.2.7

(extend-list-transform resolvable-class [element-constructor & args])(extend-list-transform resolvable-class element-constructor & more)

Implement the Transform protocol for the given resolvable-class, assuming it returns a seq of elements to-be-processed with element-constructor.

(extend-list-transform
  PeopleByLocation
  [->Person])

This is equivalent to:

(extend-protocol claro.data/Transform
  PeopleByLocation
  (transform [_ results]
    (mapv ->Person results)))

It’s also possible to supply extra parameters to be passed to the element constructor, e.g.:

(extend-list-transform
  PeopleByLocation
  [->Person {:by :location}])

This will call (->Person element {:by :location}) on each element.

extend-transform

macro

added in 0.2.7

(extend-transform resolvable-class fields)(extend-transform resolvable-class fields & more)

Implement the Transform protocol for the given resolvable-class by transforming/renaming fields according to a given field spec.

(extend-transform
  Person
  {:pet      [->Pet :pet-id]
   :location (fn [{:keys [latitude longitude]}]
               (->Location latitude longitude))
   :name     :username})

This will:

  • create :pet as (->Pet (:pet-id result)),
  • create :location as the result of the given function, and
  • copy :username to :name.

All these take the resolution result (!) as input but will not alter nil values.

Mutation

protocol

Marker interface for mutations, applying the following constraints on resolution:

  • only resolve on top-level (i.e. resolve! cannot return a mutation),
  • only resolve one mutation per run,
  • run mutation before any other resolvables.

Do not use with extend-type or extend-protocol.

mutation?

added in 0.2.7

(mutation? value)

Parameters

protocol

Protocol for custom parameter handling for Resolvables.

Partition

protocol

added in 0.2.10

Protocol enhancing batching capabilities by allowing batches to be partitioned using some per-resolvable-class criterion.

This is only used for batched resolvables.

partition-by

(partition-by resolvable)

Calculate a partitioning key for the given resolvable. Resolvables with the same partitioning key will be resolved within the same batch.

pure-resolvable?

added in 0.2.7

(pure-resolvable? value)

Check whether the given value implements the PureResolvable protocol.

PureResolvable

protocol

Interface for values whose resolution is done using a pure function, i.e. there is no I/O or statefulness involved.

Do not use with extend-type or extend-protocol!

Resolvable

protocol

Interface for resolvable values.

Do not use with extend-type or extend-protocol!

resolvable?

(resolvable? value)

Check whether the given value implements the Resolvable protocol.

NOTE: Before version 0.2.7 this did not return true for BatchedResolvable records.

resolve!

(resolve! resolvable env)

Resolve the given value within the given environment, returning a manifold deferrable representing the resolution result. This might yield a structure containing more Resolvables.

resolve-batch!

(resolve-batch! resolvable env all-resolvables)

Resolve all-resolvables (which is a seq including resolvable), returning a manifold deferrable containing a seq with resolved values in-order.

set-parameters

(set-parameters this parameters)

Set the current resolvable’s parameters, returning an updated resolvable.

This is used by the parameters projection for injection.

Transform

protocol

Protocol for post-processing the result of resolve! and the single results of resolve-batch!.

transform

(transform resolvable resolve-result)

Transform the result of resolve! (or a single result of resolve-batch!) for the current Resolvable class..

unless-error->

macro

added in 0.2.9

(unless-error-> value & body)

unless-error->>

macro

added in 0.2.9

(unless-error->> value & body)