Fix bug in singular_association resolver

This commit is contained in:
Alberto Miedes Garcés
2017-01-26 12:00:01 +01:00
parent 0c00b53765
commit 14798deab0

View File

@@ -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