Skip to content

Commit

Permalink
Merge pull request #3521 from esl/graphql/session-api
Browse files Browse the repository at this point in the history
GraphQL - Implement session api
  • Loading branch information
chrzaszcz authored Feb 3, 2022
2 parents 54590bf + 4412621 commit a957367
Show file tree
Hide file tree
Showing 28 changed files with 1,015 additions and 184 deletions.
1 change: 1 addition & 0 deletions big_tests/default.spec
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
{suites, "tests", graphql_SUITE}.
{suites, "tests", graphql_account_SUITE}.
{suites, "tests", graphql_domain_SUITE}.
{suites, "tests", graphql_session_SUITE}.
{suites, "tests", graphql_stanza_SUITE}.
{suites, "tests", inbox_SUITE}.
{suites, "tests", inbox_extensions_SUITE}.
Expand Down
1 change: 1 addition & 0 deletions big_tests/dynamic_domains.spec
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@

{suites, "tests", graphql_SUITE}.
{suites, "tests", graphql_account_SUITE}.
{suites, "tests", graphql_session_SUITE}.
{suites, "tests", graphql_stanza_SUITE}.

{suites, "tests", graphql_domain_SUITE}.
Expand Down
24 changes: 2 additions & 22 deletions big_tests/tests/graphql_account_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
-compile([export_all, nowarn_export_all]).

-import(distributed_helper, [mim/0, require_rpc_nodes/1, rpc/4]).
-import(graphql_helper, [execute/3, execute_auth/2, get_listener_port/1, get_listener_config/1]).
-import(graphql_helper, [execute/3, execute_auth/2, get_listener_port/1,
get_listener_config/1, get_ok_value/2, get_err_msg/1]).

-define(NOT_EXISTING_JID, <<"unknown987@unknown">>).

Expand Down Expand Up @@ -379,27 +380,6 @@ set_last(User, Domain, TStamp) ->
check_account(Username, Domain) ->
rpc(mim(), mongoose_account_api, check_account, [Username, Domain]).

get_err_msg(Resp) ->
get_ok_value([errors, message], Resp).

get_account_field(Field, Resp) ->
get_ok_value([data, account, Field], Resp).

get_ok_value([errors | Path], {{<<"200">>, <<"OK">>}, #{<<"errors">> := [Error]}}) ->
get_value(Path, Error);
get_ok_value(Path, {{<<"200">>, <<"OK">>}, Data}) ->
get_value(Path, Data).

get_err_value([errors | Path], {{<<"400">>, <<"Bad Request">>}, #{<<"errors">> := [Error]}}) ->
get_value(Path, Error).

% Gets a nested value given a path
get_value([], Data) -> Data;
get_value([Field | Fields], Data) ->
BinField = atom_to_binary(Field),
Data2 = maps:get(BinField, Data),
get_value(Fields, Data2).

%% Request bodies

list_users_body(Domain) ->
Expand Down
18 changes: 18 additions & 0 deletions big_tests/tests/graphql_helper.erl
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

-export([execute/3, execute_auth/2, get_listener_port/1, get_listener_config/1]).
-export([init_admin_handler/1]).
-export([get_ok_value/2, get_err_msg/1]).

-include_lib("common_test/include/ct.hrl").

Expand Down Expand Up @@ -60,8 +61,25 @@ get_listener_opts(EpName) ->
end, Modules),
Opts2.

-spec get_err_msg(#{errors := [#{message := binary()}]}) -> binary().
get_err_msg(Resp) ->
get_ok_value([errors, message], Resp).

-spec get_ok_value([atom()], {tuple(), map()}) -> binary().
get_ok_value([errors | Path], {{<<"200">>, <<"OK">>}, #{<<"errors">> := [Error]}}) ->
get_value(Path, Error);
get_ok_value(Path, {{<<"200">>, <<"OK">>}, Data}) ->
get_value(Path, Data).

%% Internal

% Gets a nested value given a path
get_value([], Data) -> Data;
get_value([Field | Fields], Data) ->
BinField = atom_to_binary(Field),
Data2 = maps:get(BinField, Data),
get_value(Fields, Data2).

is_graphql_config(#{module := ejabberd_cowboy, modules := Modules}, EpName) ->
lists:any(fun({_, _Path, mongoose_graphql_cowboy_handler, Args}) ->
atom_to_binary(EpName) == proplists:get_value(schema_endpoint, Args);
Expand Down
Loading

0 comments on commit a957367

Please sign in to comment.