diff --git a/app/graphql/schema.graphql b/app/graphql/schema.graphql index 61170ae92..a37281ad5 100644 --- a/app/graphql/schema.graphql +++ b/app/graphql/schema.graphql @@ -136,7 +136,13 @@ type Audiovisual implements DoiItem { container: Container """ - The main researchers involved in producing the data, or the authors of the publication, in priority order + The institution or person responsible for collecting, managing, distributing, + or otherwise contributing to the development of the resource. + """ + contributors(first: Int = 20): [Contributor!] + + """ + The main researchers involved in producing the data, or the authors of the publication, in priority order. """ creators(first: Int = 20): [Creator!] @@ -421,7 +427,13 @@ type Book implements DoiItem { container: Container """ - The main researchers involved in producing the data, or the authors of the publication, in priority order + The institution or person responsible for collecting, managing, distributing, + or otherwise contributing to the development of the resource. + """ + contributors(first: Int = 20): [Contributor!] + + """ + The main researchers involved in producing the data, or the authors of the publication, in priority order. """ creators(first: Int = 20): [Creator!] @@ -663,7 +675,13 @@ type BookChapter implements DoiItem { container: Container """ - The main researchers involved in producing the data, or the authors of the publication, in priority order + The institution or person responsible for collecting, managing, distributing, + or otherwise contributing to the development of the resource. + """ + contributors(first: Int = 20): [Contributor!] + + """ + The main researchers involved in producing the data, or the authors of the publication, in priority order. """ creators(first: Int = 20): [Creator!] @@ -991,7 +1009,13 @@ type Collection implements DoiItem { container: Container """ - The main researchers involved in producing the data, or the authors of the publication, in priority order + The institution or person responsible for collecting, managing, distributing, + or otherwise contributing to the development of the resource. + """ + contributors(first: Int = 20): [Contributor!] + + """ + The main researchers involved in producing the data, or the authors of the publication, in priority order. """ creators(first: Int = 20): [Creator!] @@ -1275,7 +1299,13 @@ type ConferencePaper implements DoiItem { container: Container """ - The main researchers involved in producing the data, or the authors of the publication, in priority order + The institution or person responsible for collecting, managing, distributing, + or otherwise contributing to the development of the resource. + """ + contributors(first: Int = 20): [Contributor!] + + """ + The main researchers involved in producing the data, or the authors of the publication, in priority order. """ creators(first: Int = 20): [Creator!] @@ -1579,6 +1609,46 @@ type Container { volume: String } +""" +A contributor. +""" +type Contributor { + """ + The organizational or institutional affiliation of the contributor. + """ + affiliation: [Affiliation!] + + """ + The type of the item. + """ + contributorType: String! + + """ + Family name. In the U.S., the last name of an person. + """ + familyName: String + + """ + Given name. In the U.S., the first name of a person. + """ + givenName: String + + """ + The ID of the contributor. + """ + id: ID + + """ + The name of the contributor. + """ + name: String + + """ + The type of the item. + """ + type: String! +} + """ Information about countries """ @@ -1805,7 +1875,13 @@ type DataPaper implements DoiItem { container: Container """ - The main researchers involved in producing the data, or the authors of the publication, in priority order + The institution or person responsible for collecting, managing, distributing, + or otherwise contributing to the development of the resource. + """ + contributors(first: Int = 20): [Contributor!] + + """ + The main researchers involved in producing the data, or the authors of the publication, in priority order. """ creators(first: Int = 20): [Creator!] @@ -2090,7 +2166,13 @@ type Dataset implements DoiItem { container: Container """ - The main researchers involved in producing the data, or the authors of the publication, in priority order + The institution or person responsible for collecting, managing, distributing, + or otherwise contributing to the development of the resource. + """ + contributors(first: Int = 20): [Contributor!] + + """ + The main researchers involved in producing the data, or the authors of the publication, in priority order. """ creators(first: Int = 20): [Creator!] @@ -2486,7 +2568,13 @@ type Dissertation implements DoiItem { container: Container """ - The main researchers involved in producing the data, or the authors of the publication, in priority order + The institution or person responsible for collecting, managing, distributing, + or otherwise contributing to the development of the resource. + """ + contributors(first: Int = 20): [Contributor!] + + """ + The main researchers involved in producing the data, or the authors of the publication, in priority order. """ creators(first: Int = 20): [Creator!] @@ -2775,7 +2863,13 @@ interface DoiItem { container: Container """ - The main researchers involved in producing the data, or the authors of the publication, in priority order + The institution or person responsible for collecting, managing, distributing, + or otherwise contributing to the development of the resource. + """ + contributors(first: Int = 20): [Contributor!] + + """ + The main researchers involved in producing the data, or the authors of the publication, in priority order. """ creators(first: Int = 20): [Creator!] @@ -3017,7 +3111,13 @@ type Event implements DoiItem { container: Container """ - The main researchers involved in producing the data, or the authors of the publication, in priority order + The institution or person responsible for collecting, managing, distributing, + or otherwise contributing to the development of the resource. + """ + contributors(first: Int = 20): [Contributor!] + + """ + The main researchers involved in producing the data, or the authors of the publication, in priority order. """ creators(first: Int = 20): [Creator!] @@ -3287,7 +3387,13 @@ type EventData implements DoiItem { container: Container """ - The main researchers involved in producing the data, or the authors of the publication, in priority order + The institution or person responsible for collecting, managing, distributing, + or otherwise contributing to the development of the resource. + """ + contributors(first: Int = 20): [Contributor!] + + """ + The main researchers involved in producing the data, or the authors of the publication, in priority order. """ creators(first: Int = 20): [Creator!] @@ -3849,7 +3955,13 @@ type Image implements DoiItem { container: Container """ - The main researchers involved in producing the data, or the authors of the publication, in priority order + The institution or person responsible for collecting, managing, distributing, + or otherwise contributing to the development of the resource. + """ + contributors(first: Int = 20): [Contributor!] + + """ + The main researchers involved in producing the data, or the authors of the publication, in priority order. """ creators(first: Int = 20): [Creator!] @@ -4134,7 +4246,13 @@ type Instrument implements DoiItem { container: Container """ - The main researchers involved in producing the data, or the authors of the publication, in priority order + The institution or person responsible for collecting, managing, distributing, + or otherwise contributing to the development of the resource. + """ + contributors(first: Int = 20): [Contributor!] + + """ + The main researchers involved in producing the data, or the authors of the publication, in priority order. """ creators(first: Int = 20): [Creator!] @@ -4418,7 +4536,13 @@ type InteractiveResource implements DoiItem { container: Container """ - The main researchers involved in producing the data, or the authors of the publication, in priority order + The institution or person responsible for collecting, managing, distributing, + or otherwise contributing to the development of the resource. + """ + contributors(first: Int = 20): [Contributor!] + + """ + The main researchers involved in producing the data, or the authors of the publication, in priority order. """ creators(first: Int = 20): [Creator!] @@ -4728,7 +4852,13 @@ type JournalArticle implements DoiItem { container: Container """ - The main researchers involved in producing the data, or the authors of the publication, in priority order + The institution or person responsible for collecting, managing, distributing, + or otherwise contributing to the development of the resource. + """ + contributors(first: Int = 20): [Contributor!] + + """ + The main researchers involved in producing the data, or the authors of the publication, in priority order. """ creators(first: Int = 20): [Creator!] @@ -5259,7 +5389,13 @@ type Model implements DoiItem { container: Container """ - The main researchers involved in producing the data, or the authors of the publication, in priority order + The institution or person responsible for collecting, managing, distributing, + or otherwise contributing to the development of the resource. + """ + contributors(first: Int = 20): [Contributor!] + + """ + The main researchers involved in producing the data, or the authors of the publication, in priority order. """ creators(first: Int = 20): [Creator!] @@ -5669,7 +5805,13 @@ type Other implements DoiItem { container: Container """ - The main researchers involved in producing the data, or the authors of the publication, in priority order + The institution or person responsible for collecting, managing, distributing, + or otherwise contributing to the development of the resource. + """ + contributors(first: Int = 20): [Contributor!] + + """ + The main researchers involved in producing the data, or the authors of the publication, in priority order. """ creators(first: Int = 20): [Creator!] @@ -5979,7 +6121,13 @@ type PeerReview implements DoiItem { container: Container """ - The main researchers involved in producing the data, or the authors of the publication, in priority order + The institution or person responsible for collecting, managing, distributing, + or otherwise contributing to the development of the resource. + """ + contributors(first: Int = 20): [Contributor!] + + """ + The main researchers involved in producing the data, or the authors of the publication, in priority order. """ creators(first: Int = 20): [Creator!] @@ -6395,7 +6543,13 @@ type PhysicalObject implements DoiItem { container: Container """ - The main researchers involved in producing the data, or the authors of the publication, in priority order + The institution or person responsible for collecting, managing, distributing, + or otherwise contributing to the development of the resource. + """ + contributors(first: Int = 20): [Contributor!] + + """ + The main researchers involved in producing the data, or the authors of the publication, in priority order. """ creators(first: Int = 20): [Creator!] @@ -6733,7 +6887,13 @@ type Preprint implements DoiItem { container: Container """ - The main researchers involved in producing the data, or the authors of the publication, in priority order + The institution or person responsible for collecting, managing, distributing, + or otherwise contributing to the development of the resource. + """ + contributors(first: Int = 20): [Contributor!] + + """ + The main researchers involved in producing the data, or the authors of the publication, in priority order. """ creators(first: Int = 20): [Creator!] @@ -7019,7 +7179,13 @@ type Publication implements DoiItem { container: Container """ - The main researchers involved in producing the data, or the authors of the publication, in priority order + The institution or person responsible for collecting, managing, distributing, + or otherwise contributing to the development of the resource. + """ + contributors(first: Int = 20): [Contributor!] + + """ + The main researchers involved in producing the data, or the authors of the publication, in priority order. """ creators(first: Int = 20): [Creator!] @@ -7747,7 +7913,13 @@ type Service implements DoiItem { container: Container """ - The main researchers involved in producing the data, or the authors of the publication, in priority order + The institution or person responsible for collecting, managing, distributing, + or otherwise contributing to the development of the resource. + """ + contributors(first: Int = 20): [Contributor!] + + """ + The main researchers involved in producing the data, or the authors of the publication, in priority order. """ creators(first: Int = 20): [Creator!] @@ -8034,7 +8206,13 @@ type Software implements DoiItem { container: Container """ - The main researchers involved in producing the data, or the authors of the publication, in priority order + The institution or person responsible for collecting, managing, distributing, + or otherwise contributing to the development of the resource. + """ + contributors(first: Int = 20): [Contributor!] + + """ + The main researchers involved in producing the data, or the authors of the publication, in priority order. """ creators(first: Int = 20): [Creator!] @@ -8351,7 +8529,13 @@ type Sound implements DoiItem { container: Container """ - The main researchers involved in producing the data, or the authors of the publication, in priority order + The institution or person responsible for collecting, managing, distributing, + or otherwise contributing to the development of the resource. + """ + contributors(first: Int = 20): [Contributor!] + + """ + The main researchers involved in producing the data, or the authors of the publication, in priority order. """ creators(first: Int = 20): [Creator!] @@ -8819,7 +9003,13 @@ type Work implements DoiItem { container: Container """ - The main researchers involved in producing the data, or the authors of the publication, in priority order + The institution or person responsible for collecting, managing, distributing, + or otherwise contributing to the development of the resource. + """ + contributors(first: Int = 20): [Contributor!] + + """ + The main researchers involved in producing the data, or the authors of the publication, in priority order. """ creators(first: Int = 20): [Creator!] @@ -9106,7 +9296,13 @@ type Workflow implements DoiItem { container: Container """ - The main researchers involved in producing the data, or the authors of the publication, in priority order + The institution or person responsible for collecting, managing, distributing, + or otherwise contributing to the development of the resource. + """ + contributors(first: Int = 20): [Contributor!] + + """ + The main researchers involved in producing the data, or the authors of the publication, in priority order. """ creators(first: Int = 20): [Creator!] diff --git a/app/graphql/types/contributor_type.rb b/app/graphql/types/contributor_type.rb new file mode 100644 index 000000000..8e54c18ac --- /dev/null +++ b/app/graphql/types/contributor_type.rb @@ -0,0 +1,17 @@ +# frozen_string_literal: true + +class ContributorType < BaseObject + description "A contributor." + + field :id, ID, null: true, description: "The ID of the contributor." + field :type, String, null: false, description: "The type of the item." + field :contributor_type, String, null: false, description: "The type of the item." + field :name, String, null: true, description: "The name of the contributor." + field :given_name, String, null: true, description: "Given name. In the U.S., the first name of a person." + field :family_name, String, null: true, description: "Family name. In the U.S., the last name of an person." + field :affiliation, [AffiliationType], null: true, description: "The organizational or institutional affiliation of the contributor." + + def type + object.name_type == "Organizational" ? "Organization" : "Person" + end +end diff --git a/app/graphql/types/doi_item.rb b/app/graphql/types/doi_item.rb index 7529eac41..8a1e988a8 100644 --- a/app/graphql/types/doi_item.rb +++ b/app/graphql/types/doi_item.rb @@ -21,7 +21,10 @@ module DoiItem field :id, ID, null: false, hash_key: "identifier", description: "The persistent identifier for the resource" field :type, String, null: false, description: "The type of the item." field :doi, String, null: false, hash_key: "uid", description: "The DOI for the resource." - field :creators, [CreatorType], null: true, description: "The main researchers involved in producing the data, or the authors of the publication, in priority order" do + field :creators, [CreatorType], null: true, description: "The main researchers involved in producing the data, or the authors of the publication, in priority order." do + argument :first, Int, required: false, default_value: 20 + end + field :contributors, [ContributorType], null: true, description: "The institution or person responsible for collecting, managing, distributing, or otherwise contributing to the development of the resource." do argument :first, Int, required: false, default_value: 20 end field :titles, [TitleType], null: true, description: "A name or title by which a resource is known" do @@ -279,6 +282,22 @@ def creators(**args) end end + def contributors(**args) + Array.wrap(object.contributors[0...args[:first]]).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), + "name_type" => c.fetch("nameType", nil), + "name" => c.fetch("name", nil), + "given_name" => c.fetch("givenName", nil), + "family_name" => c.fetch("familyName", nil), + "affiliation" => c.fetch("affiliation", []).map do |a| + { "id" => a["affiliationIdentifier"], + "name" => a["name"] }.compact + end) + end + end + def titles(first: nil) Array.wrap(object.titles)[0...first] end diff --git a/spec/graphql/types/contributor_type_spec.rb b/spec/graphql/types/contributor_type_spec.rb new file mode 100644 index 000000000..6313b0fc7 --- /dev/null +++ b/spec/graphql/types/contributor_type_spec.rb @@ -0,0 +1,15 @@ +require "rails_helper" + +describe ContributorType do + describe "fields" do + subject { described_class } + + it { is_expected.to have_field(:id).of_type(types.ID) } + it { is_expected.to have_field(:type).of_type("String!") } + it { is_expected.to have_field(:contributorType).of_type("String!") } + it { is_expected.to have_field(:name).of_type("String") } + it { is_expected.to have_field(:givenName).of_type("String") } + it { is_expected.to have_field(:familyName).of_type("String") } + it { is_expected.to have_field(:affiliation).of_type("[Affiliation!]") } + end +end diff --git a/spec/graphql/types/dissertation_type_spec.rb b/spec/graphql/types/dissertation_type_spec.rb index 69264353a..b3bc2cc08 100644 --- a/spec/graphql/types/dissertation_type_spec.rb +++ b/spec/graphql/types/dissertation_type_spec.rb @@ -162,7 +162,13 @@ end describe "query dissertations by person", elasticsearch: true do - let!(:dissertations) { create_list(:doi, 3, types: { "resourceTypeGeneral" => "Text", "resourceType" => "Dissertation" }, aasm_state: "findable") } + let!(:dissertations) { create_list(:doi, 3, types: { "resourceTypeGeneral" => "Text", "resourceType" => "Dissertation" }, aasm_state: "findable", contributors: + [{ + "name" => "Freie Universität Berlin", + "contributorType" => "HostingInstitution", + "nameIdentifiers" => [{"nameIdentifier"=>"https://ror.org/046ak2485", "nameIdentifierScheme"=>"ROR", "schemeUri"=>"https://ror.org"}], + "nameType" => "Organizational", + }]) } let!(:dissertation) { create(:doi, types: { "resourceTypeGeneral" => "Text", "resourceType" => "Dissertation" }, aasm_state: "findable", creators: [{ "familyName" => "Garza", @@ -189,6 +195,12 @@ } nodes { id + contributors { + id + type + name + contributorType + } } } }) @@ -200,7 +212,7 @@ expect(response.dig("data", "dissertations", "totalCount")).to eq(3) 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, "id")).to eq(@dois.first.identifier) + 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