(api-mutate this)
Returns a Fulcro mutate emitter for parsing mutations, ie: (fn [env k params] ...)
.
The emitter can return an untruthy value (nil
or false
),
which tells the fulcro api-handler to try the next Module
in the :modules
chain.
Returns a Fulcro mutate emitter for parsing mutations, ie: `(fn [env k params] ...)`. The emitter can return an untruthy value (`nil` or `false`), which tells the fulcro api-handler to try the next `Module` in the `:modules` chain.
(api-read this)
Returns a Fulcro read emitter for parsing read queries, ie: (fn [env k params] ...)
.
The emitter can return an untruthy value (nil
or false
),
which tells the fulcro api-handler to try the next Module
in the :modules
chain.
Returns a Fulcro read emitter for parsing read queries, ie: `(fn [env k params] ...)`. The emitter can return an untruthy value (`nil` or `false`), which tells the fulcro api-handler to try the next `Module` in the `:modules` chain.
(augment-map response)
Fulcro queries and mutations can wrap their responses with augment-response
to indicate they need access to
the raw Ring response. This function processes those into the response.
IMPORTANT: This function expects that the parser results have already been raised via the raise-response function.
Fulcro queries and mutations can wrap their responses with `augment-response` to indicate they need access to the raw Ring response. This function processes those into the response. IMPORTANT: This function expects that the parser results have already been raised via the raise-response function.
(augment-response core-response ring-response-fn)
Augments the Ring response that's returned from the handler.
Use this function when you need to add information into the handler response, for example when you need to add cookies or session data. Example:
(defmethod my-mutate 'user/sign-in [_ _ _]
{:action
(fn []
(augment-response
{:uid 42} ; your regular response
#(assoc-in % [:session :user-id] 42) ; a function resp -> resp
))})
If your parser has multiple responses with augment-response
, they will be applied
in order, the first one will receive an empty map as input. Only top level values
of your response will be checked for augmented response.
Augments the Ring response that's returned from the handler. Use this function when you need to add information into the handler response, for example when you need to add cookies or session data. Example: (defmethod my-mutate 'user/sign-in [_ _ _] {:action (fn [] (augment-response {:uid 42} ; your regular response #(assoc-in % [:session :user-id] 42) ; a function resp -> resp ))}) If your parser has multiple responses with `augment-response`, they will be applied in order, the first one will receive an empty map as input. Only top level values of your response will be checked for augmented response.
The default response to return when a Transit request is malformed.
The default response to return when a Transit request is malformed.
(defmutation & args)
Define a server-side Fulcro mutation.
The given symbol will be prefixed with the namespace of the current namespace UNLESS it is fully qualified already. If you're using cljc files in order to get server-side rendering, you can also include your server mutations in the same namespace as your client ones using alternate namespace aliasing:
#?(:clj (server/defmutation boo ...server...)
:cljs (m/defmutation boo ...client...))
The client-side mutation is never needed for server-side rendering, so it is ok that the mutation isn't installed when rendering on the server.
This macro expands just like the client defmutation (though it uses server multimethod and only
support action
).
NOTE: It will only work if you're using the fulcro-parser
as your server's parser.
There is special support for placing the action as a var in the namespace. This support
only work when using a plain symbol. Simple add :intern
metadata to the symbol. If
the metadata is true, it will intern the symbol as-is. It it is a string, it will suffix
the symbol with that string. If it is a symbol, it will use that symbol. The interned
symbol will act like the action side of the mutation, and has the signature:
(fn [env params])
. This is also useful in devcards for using mkdn-pprint-source on mutations,
and should give you docstring and navigation support from nREPL.
Define a server-side Fulcro mutation. The given symbol will be prefixed with the namespace of the current namespace UNLESS it is fully qualified already. If you're using cljc files in order to get server-side rendering, you can also include your server mutations in the same namespace as your client ones using alternate namespace aliasing: ``` #?(:clj (server/defmutation boo ...server...) :cljs (m/defmutation boo ...client...)) ``` The client-side mutation is never needed for server-side rendering, so it is ok that the mutation isn't installed when rendering on the server. This macro expands just like the client defmutation (though it uses server multimethod and only support `action`). NOTE: It will only work if you're using the `fulcro-parser` as your server's parser. There is special support for placing the action as a var in the namespace. This support only work when using a plain symbol. Simple add `:intern` metadata to the symbol. If the metadata is true, it will intern the symbol as-is. It it is a string, it will suffix the symbol with that string. If it is a symbol, it will use that symbol. The interned symbol will act like the action side of the mutation, and has the signature: `(fn [env params])`. This is also useful in devcards for using mkdn-pprint-source on mutations, and should give you docstring and navigation support from nREPL.
(defquery-entity & args)
Define a server-side query handler for a given entity type.
(defentity-query :person/by-id "Optional doc string" (value [env id params] {:db/id id :person/name "Joe"}))
The env
argument will be the server parser environment, which will include all of your component injections, the AST for
this query, along with the subquery. id
will be the ID of the entity to load. params
will be any additional
params that were sent via the client load
(i.e. (load this [:person/by-id 1] Person {:params {:auth 1223555}})
).
Define a server-side query handler for a given entity type. (defentity-query :person/by-id "Optional doc string" (value [env id params] {:db/id id :person/name "Joe"})) The `env` argument will be the server parser environment, which will include all of your component injections, the AST for this query, along with the subquery. `id` will be the ID of the entity to load. `params` will be any additional params that were sent via the client `load` (i.e. `(load this [:person/by-id 1] Person {:params {:auth 1223555}})`).
(defquery-root & args)
Define a server-side query handler for queries joined at the root.
The value
method you define will receive the full Om parser environment (server-side, with your
component injections) as env
and any params the server sent with the specific top-level query. Note that the subquery and
AST for the query will be available in env
.
For example: (load app :questions Question {:params {:list 1}})
on the client would result in params being set to {:list 1}
on the server.
The return value of value
will be sent to the client.
(defquery-root :questions "Optional doc string" (value [{:keys [ast query] :as env} {:keys [list]}] [{:db/id 1 :question/value "How are you?"} {:db/id 2 :question/value "What time is it?"} {:db/id 3 :question/value "How old are you?"}]))
Define a server-side query handler for queries joined at the root. The `value` method you define will receive the full Om parser environment (server-side, with your component injections) as `env` and any params the server sent with the specific top-level query. Note that the subquery and AST for the query will be available in `env`. For example: `(load app :questions Question {:params {:list 1}})` on the client would result in params being set to `{:list 1}` on the server. The return value of `value` will be sent to the client. (defquery-root :questions "Optional doc string" (value [{:keys [ast query] :as env} {:keys [list]}] [{:db/id 1 :question/value "How are you?"} {:db/id 2 :question/value "What time is it?"} {:db/id 3 :question/value "How old are you?"}]))
(dispatch _ key _)
Helper function for implementing :read and :mutate as multimethods. Use this as the dispatch-fn.
Helper function for implementing :read and :mutate as multimethods. Use this as the dispatch-fn.
(fulcro-parser)
Builds and returns a parser that uses Fulcro's query and mutation handling. See defquery-entity
, defquery-root
,
and defmutation
in the fulcro.server
namespace.
Builds and returns a parser that uses Fulcro's query and mutation handling. See `defquery-entity`, `defquery-root`, and `defmutation` in the `fulcro.server` namespace.
(fulcro-system {:keys [api-handler-key modules] :as opts})
DEPRECATED. Do not use in new code. Library composition is better accomplished using the standard parser hooks.
More powerful variant of make-fulcro-server
that allows for libraries to provide
components and api methods (by implementing components
and APIHandler
respectively).
However note that fulcro-system
does not include any components for you,
so you'll have to include things like a web-server (eg: make-web-server
), middleware,
config, etc...
Takes a map with keys:
:api-handler-key
- OPTIONAL, Where to place the generated (composed from modules) api-handler in the system-map. The
generated component will be injectable, and will contain the key :middleware
whose value
is a (fn [h] (fn [req] resp)) that handles /api
requests.
Defaults to :fulcro.server/api-handler
.:app-name
- OPTIONAL, a string that will turn "/api" into "/<app-name>/api".:components
- A com.stuartsierra.component/system-map
of components that this module wants to ADD to the overall system. Libraries should namespace their components.:modules
- A vector of implementations of Module (& optionally APIHandler),
that will be composed in the order they were passed in.
Eg: [mod1 mod2 ...] => mod1 will be tried first, mod2 next, etc...
This should be used to compose libraries api methods with your own,
with full control over execution order.NOTE: Stores the key api-handler is located in the meta data under ::api-handler-key
.
Currently used by protocol support to test your api methods without needing networking.
DEPRECATED. Do not use in new code. Library composition is better accomplished using the standard parser hooks. More powerful variant of `make-fulcro-server` that allows for libraries to provide components and api methods (by implementing `components` and `APIHandler` respectively). However note that `fulcro-system` does not include any components for you, so you'll have to include things like a web-server (eg: `make-web-server`), middleware, config, etc... Takes a map with keys: * `:api-handler-key` - OPTIONAL, Where to place the generated (composed from modules) api-handler in the system-map. The generated component will be injectable, and will contain the key `:middleware` whose value is a (fn [h] (fn [req] resp)) that handles `/api` requests. Defaults to `:fulcro.server/api-handler`. * `:app-name` - OPTIONAL, a string that will turn "/api" into "/<app-name>/api". * `:components` - A `com.stuartsierra.component/system-map` of components that this module wants to ADD to the overall system. Libraries should namespace their components. * `:modules` - A vector of implementations of Module (& optionally APIHandler), that will be composed in the order they were passed in. Eg: [mod1 mod2 ...] => mod1 will be tried first, mod2 next, etc... This should be used to compose libraries api methods with your own, with full control over execution order. NOTE: Stores the key api-handler is located in the meta data under `::api-handler-key`. Currently used by protocol support to test your api methods without needing networking.
(generate-response
{:keys [status body headers] :or {status 200} :as input-response})
Generate a Fulcro-compatible response containing at least a status code, headers, and body. You should pre-populate at least the body of the input-response. The content type of the returned response will always be pegged to 'application/transit+json'.
Generate a Fulcro-compatible response containing at least a status code, headers, and body. You should pre-populate at least the body of the input-response. The content type of the returned response will always be pegged to 'application/transit+json'.
(handle-api-request parser env query)
Given a parser, a parser environment, and a query: Runs the parser on the query, and generates a standard Fulcro-compatible response.
Given a parser, a parser environment, and a query: Runs the parser on the query, and generates a standard Fulcro-compatible response.
(load-config)
(load-config {:keys [config-path]})
Entry point for config loading, pass it a map with k-v pairs indicating where it should look for configuration in case things are not found. Eg:
Entry point for config loading, pass it a map with k-v pairs indicating where it should look for configuration in case things are not found. Eg: - config-path is the location of the config file in case there was no system property
(load-edn file-path)
If given a relative path, looks on classpath (via class loader) for the file, reads the content as EDN, and returns it. If the path is an absolute path, it reads it as EDN and returns that. If the resource is not found, returns nil.
If given a relative path, looks on classpath (via class loader) for the file, reads the content as EDN, and returns it. If the path is an absolute path, it reads it as EDN and returns that. If the resource is not found, returns nil.
(components this)
Should return a map of components that this Module wants to build. Note that this does not cause them to be injected into this module. You still need to do that by wrapping an instance of the module in component/using! Unique-ness of the keywords is checked and will be asserted, so it pays to namespace them.
Should return a map of components that this Module wants to build. Note that this does *not* cause them to be injected into this module. You still need to do that by wrapping an instance of the module in component/using! Unique-ness of the keywords is checked and will be asserted, so it pays to namespace them.
(system-key this)
Should return the key under which the module will be located in the system map. Unique-ness is checked and will be asserted.
Should return the key under which the module will be located in the system map. Unique-ness is checked and will be asserted.
(new-config config-path)
Create a new configuration component. It will load the application defaults from config/defaults.edn (using the classpath), then look for an override file in either:
config
system propertyconfig-path
and merge anything it finds there over top of the defaults.This function can override a number of the above defaults with the parameters:
config-path
: The location of the disk-based configuration file.Create a new configuration component. It will load the application defaults from config/defaults.edn (using the classpath), then look for an override file in either: 1) the file specified via the `config` system property 2) the file at `config-path` and merge anything it finds there over top of the defaults. This function can override a number of the above defaults with the parameters: - `config-path`: The location of the disk-based configuration file.
(new-server-emulator)
(new-server-emulator parser delay)
Create a server emulator that can be installed as client-side networking. If you do not supply a parser, then it will create one that works with the normal server-side macros.
Create a server emulator that can be installed as client-side networking. If you do not supply a parser, then it will create one that works with the normal server-side macros.
(parser opts)
Create a parser. The argument is a map of two keys, :read and :mutate. Both functions should have the signature (Env -> Key -> Params -> ParseResult).
Create a parser. The argument is a map of two keys, :read and :mutate. Both functions should have the signature (Env -> Key -> Params -> ParseResult).
(parser-read-error->response ex)
Determines if ex-data from ExceptionInfo has headers matching the Fulcro Server API. Returns ex-map if the ex-data matches the API, otherwise returns the whole exception.
Determines if ex-data from ExceptionInfo has headers matching the Fulcro Server API. Returns ex-map if the ex-data matches the API, otherwise returns the whole exception.
(raise-response resp)
Mutations running through a parser all come back in a map like this {'my/mutation {:result {...}}}. This function converts that to {'my/mutation {...}}.
Mutations running through a parser all come back in a map like this {'my/mutation {:result {...}}}. This function converts that to {'my/mutation {...}}.
(raw-config value)
Creates a configuration component using the value passed in, it will NOT look for any config files.
Creates a configuration component using the value passed in, it will NOT look for any config files.
The multimethod for Fulcro's built-in support for reading an entity.
The multimethod for Fulcro's built-in support for reading an entity.
The multimethod for Fulcro's built-in support for querying with a keyword
The multimethod for Fulcro's built-in support for querying with a keyword
(reader in)
(reader in opts)
Create a transit reader. This reader can handler the tempid type. Can pass transit reader customization opts map.
Create a transit reader. This reader can handler the tempid type. Can pass transit reader customization opts map.
(serialize-exception ex)
Convert exception data to string form for network transit.
Convert exception data to string form for network transit.
(server-read env k params)
A built-in read method for Fulcro's built-in server parser.
A built-in read method for Fulcro's built-in server parser.
(transitive-join a->b b->c)
Takes a map from a->b and a map from b->c and returns a map a->c.
Takes a map from a->b and a map from b->c and returns a map a->c.
(wrap-transit-body handler)
(wrap-transit-body handler options)
Middleware that parses the body of Transit request maps, and replaces the :body key with the parsed data structure. Requests without a Transit content type are unaffected. Accepts the following options: :keywords? - true if the keys of maps should be turned into keywords :opts - a map of options to be passed to the transit reader :malformed-response - a response map to return when the JSON is malformed
Middleware that parses the body of Transit request maps, and replaces the :body key with the parsed data structure. Requests without a Transit content type are unaffected. Accepts the following options: :keywords? - true if the keys of maps should be turned into keywords :opts - a map of options to be passed to the transit reader :malformed-response - a response map to return when the JSON is malformed
(wrap-transit-params handler)
(wrap-transit-params handler options)
Middleware that parses the body of Transit requests into a map of parameters, which are added to the request map on the :transit-params and :params keys. Accepts the following options: :malformed-response - a response map to return when the JSON is malformed :opts - a map of options to be passed to the transit reader Use the standard Ring middleware, ring.middleware.keyword-params, to convert the parameters into keywords.
Middleware that parses the body of Transit requests into a map of parameters, which are added to the request map on the :transit-params and :params keys. Accepts the following options: :malformed-response - a response map to return when the JSON is malformed :opts - a map of options to be passed to the transit reader Use the standard Ring middleware, ring.middleware.keyword-params, to convert the parameters into keywords.
(wrap-transit-response handler)
(wrap-transit-response handler options)
Middleware that converts responses with a map or a vector for a body into a Transit response. Accepts the following options: :encoding - one of #{:json :json-verbose :msgpack} :opts - a map of options to be passed to the transit writer
Middleware that converts responses with a map or a vector for a body into a Transit response. Accepts the following options: :encoding - one of #{:json :json-verbose :msgpack} :opts - a map of options to be passed to the transit writer
(writer out)
(writer out opts)
Create a transit reader. This writer can handler the tempid type. Can pass transit writer customization opts map.
Create a transit reader. This writer can handler the tempid type. Can pass transit writer customization opts map.
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close