• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

esl / MongooseIM / 21279388289

23 Jan 2026 08:17AM UTC coverage: 85.732% (-0.006%) from 85.738%
21279388289

push

github

web-flow
Merge pull request #4618 from esl/tomasz/graphql-hosttypes-modules-list

Add GraphQL support for host types and modules

42 of 49 new or added lines in 4 files covered. (85.71%)

8 existing lines in 5 files now uncovered.

29059 of 33895 relevant lines covered (85.73%)

40052.76 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

88.0
/src/graphql/admin/mongoose_graphql_server_admin_query.erl
1
-module(mongoose_graphql_server_admin_query).
2
-behaviour(mongoose_graphql).
3

4
-export([execute/4]).
5

6
-ignore_xref([execute/4]).
7

8
-include("../mongoose_graphql_types.hrl").
9
-include("mongoose.hrl").
10

11
execute(_Ctx, server, <<"status">>, _) ->
12
    {ok, {Status, Message, Version, CommitHash}} = mongoose_server_api:status(),
18✔
13
    {ok, #{<<"statusCode">> => status_code(Status), <<"message">> => Message,
18✔
14
           <<"version">> => Version, <<"commitHash">> => CommitHash}};
15
execute(_Ctx, server, <<"hostTypes">>, _) ->
16
    {ok, [{ok, host_type_info(HostType)} || HostType <- ?ALL_HOST_TYPES]};
36✔
17
execute(_Ctx, server, <<"globalInfo">>, _) ->
18
    Services = get_loaded_services(),
18✔
19
    InternalDatabases = get_internal_databases(),
18✔
20
    {ok, #{<<"services">> => [{ok, #{<<"name">> => atom_to_binary(S, utf8)}} || S <- Services],
18✔
21
           <<"internalDatabases">> => [{ok, atom_to_binary(DB, utf8)} || DB <- InternalDatabases]}};
18✔
22
execute(_Ctx, server, <<"getLoglevel">>, _) ->
23
    mongoose_server_api:get_loglevel();
180✔
24
execute(_Ctx, server, <<"getCookie">>, _) ->
25
    mongoose_server_api:get_cookie().
18✔
26

27
status_code(true) -> <<"RUNNING">>;
18✔
28
status_code(false) -> <<"NOT_RUNNING">>.
×
29

30
host_type_info(HostType) ->
31
    ModulesWithOpts = gen_mod:loaded_modules_with_opts(HostType),
216✔
32
    Modules = lists:keysort(1, maps:to_list(ModulesWithOpts)),
216✔
33
    AuthMethods = get_auth_methods(HostType),
216✔
34
    #{<<"name">> => HostType,
216✔
35
      <<"modules">> => [{ok, module_info(HostType, Module, Opts)} || {Module, Opts} <- Modules],
1,674✔
36
      <<"authMethods">> => [{ok, M} || M <- AuthMethods]}.
216✔
37

38
get_auth_methods(HostType) ->
39
    try mongoose_config:get_opt([{auth, HostType}, methods]) of
216✔
40
        Methods when is_list(Methods) ->
41
            [atom_to_binary(M, utf8) || M <- Methods]
216✔
42
    catch
NEW
43
        _:_ -> []
×
44
    end.
45

46
get_loaded_services() ->
47
    ServicesWithOpts = mongoose_service:loaded_services_with_opts(),
18✔
48
    lists:sort(maps:keys(ServicesWithOpts)).
18✔
49

50
get_internal_databases() ->
51
    InternalDatabasesWithOpts = mongoose_config:get_opt(internal_databases),
18✔
52
    case is_map(InternalDatabasesWithOpts) of
18✔
53
        true -> lists:sort(maps:keys(InternalDatabasesWithOpts));
18✔
NEW
54
        false -> []
×
55
    end.
56

57
module_info(HostType, Module, Opts) ->
58
    Options = module_options(HostType, Module, Opts),
1,674✔
59
    #{<<"name">> => atom_to_binary(Module, utf8),
1,674✔
60
      <<"options">> => [{ok, OptionMap} || OptionMap <- Options]}.
594✔
61

62
module_options(HostType, Module, Opts) ->
63
    RawOptions = module_options_to_report(HostType, Module, Opts),
1,674✔
64
    Formatted = [format_module_option(Entry) || Entry <- RawOptions],
1,674✔
65
    lists:sort(fun compare_module_options/2, Formatted).
1,674✔
66

67
%% Modules can optionally export reported_module_options/2 to control the reported
68
%% configuration keys.
69
module_options_to_report(HostType, Module, Opts) ->
70
    case gen_mod:reported_module_options(Module, HostType, Opts) of
1,674✔
71
        {ok, Options} when is_list(Options) -> Options;
18✔
72
        _ -> default_options_to_report(Opts)
1,656✔
73
    end.
74

75
default_options_to_report(Opts) ->
76
    [{Key, Value} || {Key, Value} <- maps:to_list(Opts), is_backend_option(Key)].
1,656✔
77

78
is_backend_option(Key) when is_atom(Key) ->
79
    lists:suffix("backend", atom_to_list(Key));
4,640✔
80
is_backend_option(_) ->
NEW
81
    false.
×
82

83
format_module_option({Key, Value}) ->
84
    #{<<"key">> => format_option_key(Key),
594✔
85
      <<"value">> => format_option_value(Value)}.
86

87
compare_module_options(#{<<"key">> := Key1}, #{<<"key">> := Key2}) ->
88
    Key1 =< Key2.
360✔
89

90
format_option_key(Key) ->
91
    format_term(Key).
594✔
92

NEW
93
format_option_value(undefined) -> null;
×
NEW
94
format_option_value(null) -> null;
×
95
format_option_value(Value) ->
96
    format_term(Value).
594✔
97

98
format_term(Term) when is_binary(Term) -> Term;
18✔
99
format_term(Term) when is_atom(Term) -> atom_to_binary(Term, utf8);
1,044✔
100
format_term(Term) when is_integer(Term) -> integer_to_binary(Term);
18✔
101
format_term(Term) ->
102
    case io_lib:printable_unicode_list(Term) of
108✔
103
        true -> unicode:characters_to_binary(Term);
36✔
104
        false -> unicode:characters_to_binary(io_lib:format("~tp", [Term]))
72✔
105
    end.
106

STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc