has_one_resolver.rb 494 B

12345678910111213141516171819
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. class Gql::Resolvers::HasOneResolver < GraphQL::Schema::Resolver
  3. include Gql::Types::Concerns::HasPunditAuthorization
  4. description "resolver for Rails' has_one relationship"
  5. def resolve
  6. Gql::RecordLoader
  7. .for(rails_definition.klass, column: rails_definition.foreign_key)
  8. .load(object.id)
  9. end
  10. private
  11. def rails_definition
  12. object.class.reflections[field.original_name.to_s]
  13. end
  14. end