artemis.core

Client

added in 0.1.0

client?

added in 0.1.0

(client? x)

Returns true if x is a valid client.

create-client

added in 0.1.0

(create-client & {:keys [store network-chain defaults], :or {store (mgs/create-store), network-chain (http/create-network-step)}})

Returns a new Client specified by :store, :network-chain, and :defaults.

exec

added in 0.1.0

(exec network-chain operation context)

Calls artemis.network-steps.protocols/-exec on a given network chain.

mutate!

added in 0.1.0

(mutate! client document)(mutate! client document & args)

Given a client, document, and optional :variables and :options, returns a channel that will receive the response(s) for a mutation.

The :variables argument is a map of variables for the GraphQL mutation.

The :options argument is a map optionally including:

  • :out-chan The channel to put mutation messages onto. Defaults to (cljs.core.async/channel).
  • :context A map of context to pass along when executing the network chain. Defaults to {}.
  • :before-write A function that gets called before a mutation is written to the client’s store. Will get called with a map containing the current store, the result data, the mutation document, variables, and a boolean representing whether or not the write will be an optimistic write. Should return a result.
  • :after-write A function that gets called after a mutation is written to the client’s store. Will get called with a map containing the updated store, the result data, the mutation document, variables, and a boolean representing whether or not the write was an optimistic write. Should return a store.
  • :optimistic-result A map describing an anticipated/optimistic result. The optimistic result will be put onto the channel before waiting for a successful mutation response.

network-chain

added in 0.1.0

(network-chain client)

Returns the client’s network chain. Returns nil if no network chain exists for the client.

query!

added in 0.1.0

(query! client document)(query! client document & args)

Given a client, document, and optional :variables and :options, returns a channel that will receive the response(s) for a query. Depending on the :fetch-policy option, the channel will receive one or more messages.

The :variables argument is a map of variables for the GraphQL query.

The :options argument is a map optionally including:

  • :out-chan The channel to put query messages onto. Defaults to (cljs.core.async/channel).
  • :context A map of context to pass along when executing the network chain. Defaults to {}.
  • :fetch-policy A keyword specifying the fetch policy (see below). Defaults to the configured default or :local-only.

The available fetch policies and corresponding implications are:

:no-cache

A query will never be read or write to the local store. Instead, it will always execute a remote query without caching the result. This policy is for when you want data coming directly from the remote source and don’t intend for the result to ever be used by other queries.

:local-only

A query will never be executed remotely. Instead, the query will only run against the local store. If the query can’t be satisfied locally, an error message will be put on the return channel. This fetch policy allows you to only interact with data in your local store without making any network requests which keeps your component fast, but means your local data might not be consistent with what is on the server. For this reason, this policy should only be used on data that is highly unlikely to change, or is regularly being refreshed.

:local-first

Will run a query against the local store first. The result of the local query will be put on the return channel. If that result is a non-nil value, then a remote query will not be executed. If the result is nil, meaning the data isn’t available locally, a remote query will be executed. This fetch policy aims to minimize the number of network requests sent. The same cautions around stale data that applied to the :local-only policy do so for this policy as well.

:local-then-remote

Like the :local-first policy, this will run a query against the local store first and put the result on the return channel. However, unlike :local-first, a remote query will always be executed regardless of the value of the local result. This fetch policy optimizes for users getting a quick response while also trying to keep cached data consistent with your remote data at the cost of extra network requests.

:remote-only

This fetch policy will never run against the local store. Instead, it will always execute a remote query. This policy optimizes for data consistency with the server, but at the cost of an instant response.

read

added in 0.1.0

(read store document variables & {:keys [return-partial?], :or {return-partial? false}})

Calls artemis.stores.protocols/-read on a given store.

read-fragment

added in 0.1.0

(read-fragment store document entity-ref & {:keys [return-partial?], :or {return-partial? false}})

Calls artemis.stores.protocols/-read-fragment on a given store.

store

added in 0.1.0

(store client)

Returns the client’s store. Returns nil if no store exists for the client.

subscribe!

added in 0.1.0

(subscribe! client document)(subscribe! client document & args)

Given a client, document, and optional :variables and :options, establishes a GraphQL subscription over a WebSocket connection, returning a channel that will receive a stream of updates from the server. Note that GraphQL subscriptions only listen for updates from the server, they don’t request any data and so won’t receive any when the connection is established. If you need an initial set of data, combine subscribe! with query!, setting an appropriate :fetch-policy.

The :variables argument is a map of variables for the GraphQL subscription.

The :options argument is a map optionally including:

  • :out-chan The channel to put subscription update messages onto. Defaults to (cljs.core.async/channel).
  • :ws-id A unique ID for the subscription. Can be used to unsubscribe from updates. Defaults to a generated unique ID.
  • :context A map of context to pass along when executing the network chain. Defaults to {}.

watch-store

added in 0.1.0

(watch-store client watch-cb)

Given a client and a callback, will call the callback whenever there’s a change to the client’s store with the old store state and the new store state as arguments. Returns an unwatch function.

write

added in 0.1.0

(write store data document variables)

Calls artemis.stores.protocols/-write on a given store.

write-fragment

added in 0.1.0

(write-fragment store data document entity-ref)

Calls artemis.stores.protocols/-write-fragment on a given store.