@@ -45,8 +45,10 @@ defmodule GraphQL.Execution.Executor do
4545 :mutation ->
4646 { context , result } = execute_fields_serially ( context , type , root_value , fields )
4747 { :ok , result , context . errors }
48- :subscription -> { :error , "Subscriptions not currently supported" }
49- _ -> { :error , "Can only execute queries, mutations and subscriptions" }
48+ :subscription ->
49+ { :error , "Subscriptions not currently supported" }
50+ _ ->
51+ { :error , "Can only execute queries, mutations and subscriptions" }
5052 end
5153 end
5254
@@ -107,15 +109,10 @@ defmodule GraphQL.Execution.Executor do
107109 end
108110 end
109111
110- @ spec execute_fields ( ExecutionContext . t , atom | Map , any , any ) :: { ExecutionContext . t , map }
111- defp execute_fields ( context , parent_type , source_value , fields ) when is_atom ( parent_type ) do
112- execute_fields ( context , apply ( parent_type , :type , [ ] ) , source_value , fields )
113- end
114-
115112 @ spec execute_fields ( ExecutionContext . t , atom | Map , any , any ) :: { ExecutionContext . t , map }
116113 defp execute_fields ( context , parent_type , source_value , fields ) do
117114 Enum . reduce fields , { context , % { } } , fn ( { field_name_ast , field_asts } , { context , results } ) ->
118- case resolve_field ( context , parent_type , source_value , field_asts ) do
115+ case resolve_field ( context , unwrap_type ( parent_type ) , source_value , field_asts ) do
119116 { context , :undefined } -> { context , results }
120117 { context , value } -> { context , Map . put ( results , field_name_ast . value , value ) }
121118 end
@@ -130,8 +127,7 @@ defmodule GraphQL.Execution.Executor do
130127
131128 defp resolve_field ( context , parent_type , source , field_asts ) do
132129 field_ast = hd ( field_asts )
133- # FIXME: possible memory leak with atoms
134- field_name = String . to_atom ( field_ast . name . value )
130+ field_name = String . to_existing_atom ( field_ast . name . value )
135131
136132 if field_def = field_definition ( parent_type , field_name ) do
137133 return_type = field_def . type
@@ -156,7 +152,7 @@ defmodule GraphQL.Execution.Executor do
156152
157153 case FieldResolver . resolve ( field_def , source , args , info ) do
158154 { :ok , result } ->
159- complete_value_catching_error ( context , return_type , field_asts , info , result )
155+ complete_value ( return_type , context , field_asts , info , result )
160156 { :error , message } ->
161157 { ExecutionContext . report_error ( context , message ) , nil }
162158 end
@@ -165,65 +161,50 @@ defmodule GraphQL.Execution.Executor do
165161 end
166162 end
167163
168- @ spec complete_value_catching_error ( ExecutionContext . t , any , GraphQL.Document . t , any , map ) :: { ExecutionContext . t , map | nil }
169- defp complete_value_catching_error ( context , return_type , field_asts , info , result ) do
170- # TODO lots of error checking
171- complete_value ( context , return_type , field_asts , info , result )
172- end
173-
174- @ spec complete_value ( ExecutionContext . t , any , any , any , nil ) :: { ExecutionContext . t , nil }
175- defp complete_value ( context , _ , _ , _ , nil ) , do: { context , nil }
164+ @ spec complete_value ( any , ExecutionContext . t , any , any , nil ) :: { ExecutionContext . t , nil }
165+ defp complete_value ( _ , context , _ , _ , nil ) , do: { context , nil }
176166
177- @ spec complete_value ( ExecutionContext . t , % ObjectType { } , GraphQL.Document . t , any , map ) :: { ExecutionContext . t , map }
178- defp complete_value ( context , % ObjectType { } = return_type , field_asts , _info , result ) do
167+ @ spec complete_value ( % ObjectType { } , ExecutionContext . t , GraphQL.Document . t , any , map ) :: { ExecutionContext . t , map }
168+ defp complete_value ( % ObjectType { } = return_type , context , field_asts , _info , result ) do
179169 { context , sub_field_asts } = collect_sub_fields ( context , return_type , field_asts )
180170 execute_fields ( context , return_type , result , sub_field_asts . fields )
181171 end
182172
183- defp complete_value ( context , % NonNull { ofType: inner_type } , field_asts , info , result ) when is_atom ( inner_type ) do
184- complete_value ( context , % NonNull { ofType: apply ( inner_type , :type , [ ] ) } , field_asts , info , result )
185- end
186-
187- @ spec complete_value ( ExecutionContext . t , % NonNull { } , GraphQL.Document . t , any , any ) :: { ExecutionContext . t , map }
188- defp complete_value ( context , % NonNull { ofType: inner_type } , field_asts , info , result ) do
173+ @ spec complete_value ( % NonNull { } , ExecutionContext . t , GraphQL.Document . t , any , any ) :: { ExecutionContext . t , map }
174+ defp complete_value ( % NonNull { ofType: inner_type } , context , field_asts , info , result ) do
189175 # TODO: Null Checking
190- complete_value ( context , inner_type , field_asts , info , result )
176+ complete_value ( unwrap_type ( inner_type ) , context , field_asts , info , result )
191177 end
192178
193- @ spec complete_value ( ExecutionContext . t , % Interface { } , GraphQL.Document . t , any , any ) :: { ExecutionContext . t , map }
194- defp complete_value ( context , % Interface { } = return_type , field_asts , info , result ) do
179+ @ spec complete_value ( % Interface { } , ExecutionContext . t , GraphQL.Document . t , any , any ) :: { ExecutionContext . t , map }
180+ defp complete_value ( % Interface { } = return_type , context , field_asts , info , result ) do
195181 runtime_type = AbstractType . get_object_type ( return_type , result , info . schema )
196182 { context , sub_field_asts } = collect_sub_fields ( context , runtime_type , field_asts )
197183 execute_fields ( context , runtime_type , result , sub_field_asts . fields )
198184 end
199185
200- @ spec complete_value ( ExecutionContext . t , % Union { } , GraphQL.Document . t , any , any ) :: { ExecutionContext . t , map }
201- defp complete_value ( context , % Union { } = return_type , field_asts , info , result ) do
186+ @ spec complete_value ( % Union { } , ExecutionContext . t , GraphQL.Document . t , any , any ) :: { ExecutionContext . t , map }
187+ defp complete_value ( % Union { } = return_type , context , field_asts , info , result ) do
202188 runtime_type = AbstractType . get_object_type ( return_type , result , info . schema )
203189 { context , sub_field_asts } = collect_sub_fields ( context , runtime_type , field_asts )
204190 execute_fields ( context , runtime_type , result , sub_field_asts . fields )
205191 end
206192
207- defp complete_value ( context , % List { ofType: list_type } , field_asts , info , result ) when is_atom ( list_type ) do
208- complete_value ( context , % List { ofType: apply ( list_type , :type , [ ] ) } , field_asts , info , result )
209- end
210-
211- @ spec complete_value ( ExecutionContext . t , % List { } , GraphQL.Document . t , any , any ) :: map
212- defp complete_value ( context , % List { ofType: list_type } , field_asts , info , result ) do
193+ @ spec complete_value ( % List { } , ExecutionContext . t , GraphQL.Document . t , any , any ) :: map
194+ defp complete_value ( % List { ofType: list_type } , context , field_asts , info , result ) do
213195 { context , result } = Enum . reduce result , { context , [ ] } , fn ( item , { context , acc } ) ->
214- { context , value } = complete_value_catching_error ( context , list_type , field_asts , info , item )
196+ { context , value } = complete_value ( unwrap_type ( list_type ) , context , field_asts , info , item )
215197 { context , [ value ] ++ acc }
216198 end
217199 { context , Enum . reverse ( result ) }
218200 end
219201
220- defp complete_value ( context , return_type , field_asts , info , result ) when is_atom ( return_type ) do
221- type = apply ( return_type , :type , [ ] )
222- complete_value ( context , type , field_asts , info , result )
202+ defp complete_value ( return_type , context , field_asts , info , result ) when is_atom ( return_type ) do
203+ complete_value ( unwrap_type ( return_type ) , context , field_asts , info , result )
223204 end
224205
225- defp complete_value ( context , return_type , _field_asts , _info , result ) do
226- { context , GraphQL.Types . serialize ( return_type , result ) }
206+ defp complete_value ( return_type , context , _field_asts , _info , result ) do
207+ { context , GraphQL.Types . serialize ( unwrap_type ( return_type ) , result ) }
227208 end
228209
229210 defp collect_sub_fields ( context , return_type , field_asts ) do
@@ -311,7 +292,7 @@ defmodule GraphQL.Execution.Executor do
311292 def value_from_ast ( nil , _ , _ ) , do: nil # remove once NonNull is actually done..
312293
313294 def value_from_ast ( value_ast , type , variable_values ) when is_atom ( type ) do
314- value_from_ast ( value_ast , apply ( type , : type, [ ] ) , variable_values )
295+ value_from_ast ( value_ast , type . type , variable_values )
315296 end
316297
317298 def value_from_ast ( value_ast , type , _ ) do
@@ -355,4 +336,7 @@ defmodule GraphQL.Execution.Executor do
355336 true -> runtime_type . name == typed_condition . name
356337 end
357338 end
339+
340+ defp unwrap_type ( type ) when is_atom ( type ) , do: type . type
341+ defp unwrap_type ( type ) , do: type
358342end
0 commit comments