Skip to content

Commit

Permalink
Version 1.0.6 (2024-04-27)
Browse files Browse the repository at this point in the history
  • Loading branch information
potatosalad committed Apr 27, 2024
1 parent 5f72041 commit b2ad49a
Show file tree
Hide file tree
Showing 7 changed files with 534 additions and 212 deletions.
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
# Changelog

## 1.0.6 (2024-04-27)

* Enhancements
* Add new functions to `argo_index_map`:
* `argo_index_map:groups_from_list/2`
* `argo_index_map:groups_from_list/3`
* Add new function to `argo_graphql_field`:
* `argo_graphql_field:get_response_key/1`
* Reorganize `argo_typer` to better match upstream.
* Fixes
* Minor correction to "Field Selection Merging" from [GraphQL Spec: 5.3.2 Field Selection Merging](https://spec.graphql.org/draft/#sec-Field-Selection-Merging) (see [msolomon/argo#19](https://github.com/msolomon/argo/pull/19)).

## 1.0.5 (2024-04-23)

* Enhancements
Expand Down
26 changes: 26 additions & 0 deletions apps/argo/include/argo_typer.hrl
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
%%%-----------------------------------------------------------------------------
%%% Copyright (c) Meta Platforms, Inc. and affiliates.
%%% Copyright (c) WhatsApp LLC
%%%
%%% This source code is licensed under the MIT license found in the
%%% LICENSE.md file in the root directory of this source tree.
%%%
%%% @author Andrew Bennett <potatosaladx@meta.com>
%%% @copyright (c) Meta Platforms, Inc. and affiliates.
%%% @doc
%%%
%%% @end
%%% Created : 26 Apr 2024 by Andrew Bennett <potatosaladx@meta.com>
%%%-----------------------------------------------------------------------------
%%% % @format
%% @oncall whatsapp_clr
-ifndef(ARGO_TYPER_HRL).
-define(ARGO_TYPER_HRL, 1).

-record(argo_typer, {
service_document :: argo_graphql_service_document:t(),
executable_document :: argo_graphql_executable_document:t(),
options :: argo_typer:options()
}).

-endif.
2 changes: 1 addition & 1 deletion apps/argo/src/argo.app.src
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
%%% % @format
{application, argo, [
{description, "argo: Erlang implementation of Argo for GraphQL"},
{vsn, "1.0.5"},
{vsn, "1.0.6"},
{modules, []},
{registered, []},
%% NOTE: Remember to sync changes to `applications` to
Expand Down
62 changes: 62 additions & 0 deletions apps/argo/src/argo_index_map.erl
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
get_full/2,
get_index/2,
get_index_of/2,
groups_from_list/2,
groups_from_list/3,
is_index/2,
is_key/2,
iterator/1,
Expand Down Expand Up @@ -66,6 +68,10 @@
-type filter_func(Index, Key, Value) :: fun((Index, Key, Value) -> boolean()).
-type filtermap_func() :: filtermap_func(index(), key(), value(), value()).
-type filtermap_func(Index, Key, Value1, Value2) :: fun((Index, Key, Value1) -> boolean() | {true, Value2}).
-type groups_from_list_key_fun() :: groups_from_list_key_fun(dynamic(), key()).
-type groups_from_list_key_fun(Elem, Key) :: fun((Elem) -> Key).
-type groups_from_list_value_fun() :: groups_from_list_value_fun(dynamic(), value()).
-type groups_from_list_value_fun(Elem, Value) :: fun((Elem) -> Value).
-type index() :: non_neg_integer().
-type key() :: dynamic().
-type value() :: dynamic().
Expand All @@ -88,6 +94,10 @@
filter_func/3,
filtermap_func/0,
filtermap_func/4,
groups_from_list_key_fun/0,
groups_from_list_key_fun/2,
groups_from_list_value_fun/0,
groups_from_list_value_fun/2,
index/0,
iterator/0,
iterator/2,
Expand Down Expand Up @@ -293,6 +303,29 @@ get_index_of(Key, IndexMap = #argo_index_map{}) ->
erlang:error({badkey, Key}, [Key, IndexMap], [{error_info, #{module => ?MODULE}}])
end.

-spec groups_from_list(KeyFun, List) -> IndexMap when
KeyFun :: groups_from_list_key_fun(Elem, Key),
List :: [Elem],
Elem :: dynamic(),
Key :: key(),
Value :: value(),
IndexMap :: t(Key, Value).
groups_from_list(KeyFun, List) when is_function(KeyFun, 1) andalso (is_list(List) andalso length(List) >= 0) ->
groups_from_list(KeyFun, fun identity/1, List).

-spec groups_from_list(KeyFun, ValueFun, List) -> IndexMap when
KeyFun :: groups_from_list_key_fun(Elem, Key),
ValueFun :: groups_from_list_value_fun(Elem, Value),
List :: [Elem],
Elem :: dynamic(),
Key :: key(),
Value :: value(),
IndexMap :: t(Key, Value).
groups_from_list(KeyFun, ValueFun, List) when
is_function(KeyFun, 1) andalso is_function(ValueFun, 1) andalso (is_list(List) andalso length(List) >= 0)
->
groups_from_list_internal(KeyFun, ValueFun, List, new()).

-spec is_index(Index, IndexMap) -> boolean() when Index :: index(), IndexMap :: t().
is_index(Index, IndexMap = #argo_index_map{}) ->
Index < ?MODULE:size(IndexMap).
Expand Down Expand Up @@ -707,6 +740,35 @@ foldr_iterator(Iterator, Function, Acc1, Entries1) ->
from_list({Key, Value}, IndexMap) ->
?MODULE:put(Key, Value, IndexMap).

%% @private
-spec groups_from_list_internal(KeyFun, ValueFun, List, IndexMap1) -> IndexMap2 when
KeyFun :: groups_from_list_key_fun(Elem, Key),
ValueFun :: groups_from_list_value_fun(Elem, Value),
List :: [Elem],
Elem :: dynamic(),
Key :: key(),
Value :: value(),
IndexMap1 :: t(Key, Value),
IndexMap2 :: t(Key, Value).
groups_from_list_internal(_KeyFun, _ValueFun, [], IndexMap1) ->
IndexMap1;
groups_from_list_internal(KeyFun, ValueFun, [Elem | List], IndexMap1) ->
Key = KeyFun(Elem),
Value = ValueFun(Elem),
IndexMap2 = update_with(
Key,
fun(_Index, Values) ->
Values ++ [Value]
end,
[Value],
IndexMap1
),
groups_from_list_internal(KeyFun, ValueFun, List, IndexMap2).

%% @private
-spec identity(T) -> T when T :: dynamic().
identity(T) -> T.

%% @private
-spec repair(Index, undefined | {Key, Value}, Acc) -> Acc when
Index :: index(),
Expand Down
Loading

0 comments on commit b2ad49a

Please sign in to comment.