diff --git a/app/graphql/types/doi_item.rb b/app/graphql/types/doi_item.rb index dbe3f0ec8..223f1358d 100644 --- a/app/graphql/types/doi_item.rb +++ b/app/graphql/types/doi_item.rb @@ -297,7 +297,9 @@ def creators(**args) end def contributors(**args) - Array.wrap(object.contributors[0...args[:first]]).select { |c| c["contributorType"] == args[:contributor_type] }.map do |c| + contrib = Array.wrap(object.contributors[0...args[:first]]) + contrib = contrib.select { |c| c["contributorType"] == args[:contributor_type] } if args[:contributor_type].present? + contrib.map do |c| Hashie::Mash.new( "id" => c.fetch("nameIdentifiers", []).find { |n| %w(ORCID ROR).include?(n.fetch("nameIdentifierScheme", nil)) }.to_h.fetch("nameIdentifier", nil), "contributor_type" => c.fetch("contributorType", nil), diff --git a/spec/graphql/types/dissertation_type_spec.rb b/spec/graphql/types/dissertation_type_spec.rb index d0e47de60..d80416940 100644 --- a/spec/graphql/types/dissertation_type_spec.rb +++ b/spec/graphql/types/dissertation_type_spec.rb @@ -201,6 +201,18 @@ name contributorType } + hostingInstitution: contributors(contributorType: "HostingInstitution") { + id + type + name + contributorType + } + contributors { + id + type + name + contributorType + } } } }) @@ -213,6 +225,14 @@ expect(response.dig("data", "dissertations", "published")).to eq([{"count"=>3, "id"=>"2011", "title"=>"2011"}]) expect(response.dig("data", "dissertations", "nodes").length).to eq(3) expect(response.dig("data", "dissertations", "nodes", 0, "dataManagers")).to eq([]) + expect(response.dig("data", "dissertations", "nodes", 0, "hostingInstitution")).to eq([{"contributorType"=>"HostingInstitution", + "id"=>"https://ror.org/046ak2485", + "name"=>"Freie Universität Berlin", + "type"=>"Organization"}]) + expect(response.dig("data", "dissertations", "nodes", 0, "contributors")).to eq([{"contributorType"=>"HostingInstitution", + "id"=>"https://ror.org/046ak2485", + "name"=>"Freie Universität Berlin", + "type"=>"Organization"}]) end end end