1-
2- # ArrayMap is used for representing lists in intermediate results.
3- # This means the entire intermediate Executor result representation can
4- # be manipulated with the Access protocol which will allow for patching
5- # the entire structure in an ad-hoc manner. This is key to implementing
6- # deferred resolvers.
71defmodule GraphQL.Util.ArrayMap do
2+ @ moduledoc """
3+ ArrayMap is used for representing lists in intermediate results.
4+ This means the entire intermediate Executor result representation can
5+ be manipulated with the Access protocol which will allow for patching
6+ the entire structure in an ad-hoc manner. This is key to implementing
7+ deferred resolvers.
8+ """
89
910 @ behaviour Access
1011
@@ -44,8 +45,10 @@ defmodule GraphQL.Util.ArrayMap do
4445 { value , % __MODULE__ { map: map } }
4546 end
4647
47- # Converts an intermediate executor result that contains ArrayMaps into one
48- # where the array maps are converted into lists.
48+ @ doc """
49+ Converts an intermediate executor result that contains ArrayMaps into one
50+ where the array maps are converted into lists.
51+ """
4952 def expand_result ( result ) when is_list ( result ) do
5053 Enum . map ( result , & expand_result / 1 )
5154 end
@@ -54,6 +57,11 @@ defmodule GraphQL.Util.ArrayMap do
5457 [ expand_result ( Map . get ( result . map , index ) ) ] ++ acc
5558 end ) |> Enum . reverse
5659 end
60+ # Without the following we run into an issue when attempting to process
61+ # structs because they are not enumerable.
62+ #
63+ # FIXME: We need a better way of detecting scalars (Eg: DateTime)
64+ def expand_result ( % { __struct__: _ } = result ) , do: result
5765 def expand_result ( result ) when is_map ( result ) do
5866 Enum . reduce ( result , % { } , fn ( { k , v } , acc ) ->
5967 Map . put ( acc , expand_result ( k ) , expand_result ( v ) )
0 commit comments