From 14798deab0686f3948e0c19089bee2405b21f19c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alberto=20Miedes=20Garc=C3=A9s?= Date: Thu, 26 Jan 2017 12:00:01 +0100 Subject: [PATCH] Fix bug in singular_association resolver --- lib/graph_ql/api_types_creator.rb | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/graph_ql/api_types_creator.rb b/lib/graph_ql/api_types_creator.rb index 4cb3b18c4..2142a9b1e 100644 --- a/lib/graph_ql/api_types_creator.rb +++ b/lib/graph_ql/api_types_creator.rb @@ -49,7 +49,14 @@ module GraphQL field(field_name, SCALAR_TYPES[field_type]) when :singular_association field(field_name, -> { api_types_creator.created_types[field_type] }) do - resolve -> (object, arguments, context) { field_type.public_for_api.find_by(id: object.id) } + resolve -> (object, arguments, context) do + association_target = object.send(field_name) + if association_target.nil? + nil + else + field_type.public_for_api.find_by(id: association_target.id) + end + end end when :multiple_association field_type = field_type.first