@ -1,16 +1,26 @@
|
||||
%% @doc Public api for Boto.
|
||||
%% {@link boto_server} must be started, properly configured and with set of implementations of {@link boto_resolver} for boto to work.
|
||||
%% @end
|
||||
-module(boto).
|
||||
|
||||
-export([resolves/1, resolves/2, query/2]).
|
||||
|
||||
%% @doc Checks if the provided attribute is available in any resolver registered to boto.
|
||||
%% @end
|
||||
resolves(Output) ->
|
||||
{ok, Graph} = boto_worker:graph(),
|
||||
Vertices = digraph:vertices(Graph),
|
||||
lists:member(Output, Vertices).
|
||||
|
||||
%% @doc Checks if the input attribute can reach the output attribute.
|
||||
%% If output attribute is reacheable through a resolver that doesn't require input attributes, it will return true as well.
|
||||
%% @end
|
||||
resolves(Input, Output) ->
|
||||
{ok, Graph} = boto_worker:graph(),
|
||||
Path = digraph:get_short_path(Graph, Input, Output),
|
||||
lists:member(Input, Path) and lists:member(noarg, Path).
|
||||
|
||||
query(A, Q) when is_map(A), is_list(Q) ->
|
||||
boto_query:query(A, Q).
|
||||
%% @doc Retrieves attributes present in the query using the Input attributes provided.
|
||||
%% @end
|
||||
query(Input, Output) when is_map(Input), is_list(Output) ->
|
||||
boto_query:query(Input, Output).
|
||||
|
@ -1,8 +1,26 @@
|
||||
%% @doc Behaviour that defines a resolver for boto.
|
||||
%% @end
|
||||
-module(boto_resolver).
|
||||
|
||||
-type name() :: atom().
|
||||
-type resolver() :: [{input, [atom()]} | {output, [atom()]}].
|
||||
-type t() :: [{name(), resolver()}].
|
||||
-export_type([name/0, resolver/0, input/0, input_attribute/0, output/0, output_attribute/0, t/0]).
|
||||
|
||||
-callback resolver_init() -> t().
|
||||
-callback resolve(name(), map()) -> map() | [map()].
|
||||
-type name() :: atom(). %% Name of a resolver.
|
||||
|
||||
-type resolver() :: [input() | output()]. %% Resolver settings.
|
||||
%% {@link input()} and {@link output()} must be provided.
|
||||
|
||||
-type input() :: {input, [] | list(input_attribute())}. %% Input option.
|
||||
|
||||
-type input_attribute() :: atom(). %% Input attribute, those will be required to call the resolver.
|
||||
|
||||
-type output() :: {output, list(output_attribute())}.%% Output option.
|
||||
|
||||
-type output_attribute() :: atom() | {atom(), list(output_attribute())}. %% Output attribute, those will be provided by the resolver after it's called.
|
||||
%% A nested attribute shouldn't require another resolver to be called.
|
||||
|
||||
-type t() :: list({name(), resolver()}). %% {@link resolver_init()} return, list all resolvers provided by the module implementing this behaviour.
|
||||
|
||||
-callback resolver_init() -> t(). %% This will be called at {@link boto_server} start to setup and index all available attributes.
|
||||
|
||||
-callback resolve(name(), map()) -> map() | [map()]. %% This function is called when resolving a query.
|
||||
%% This function will be called only when {@link input_attribute()} are available and the query needs one of the {@link output_attribute()} either to finish traversing a required resolver or for the final output of the query.
|
||||
|
Loading…
Reference in New Issue