From c18f8b9772b0f23ba3c9971e8109102ca6ae4676 Mon Sep 17 00:00:00 2001 From: Martin Fenner Date: Sun, 23 Feb 2020 20:37:07 +0100 Subject: [PATCH] fix organization type in graphql. #426 --- app/graphql/schema.graphql | 13 ++++++------- app/graphql/types/address_type.rb | 6 +++--- app/graphql/types/doi_item.rb | 5 ++++- app/graphql/types/funder_type.rb | 2 +- app/graphql/types/organization_type.rb | 12 ++++++------ app/graphql/types/query_type.rb | 8 -------- spec/factories/default.rb | 25 ++++++++++++++++--------- spec/graphql/types/query_type_spec.rb | 23 +++++++++-------------- spec/models/doi_spec.rb | 2 +- 9 files changed, 46 insertions(+), 50 deletions(-) diff --git a/app/graphql/schema.graphql b/app/graphql/schema.graphql index a8f86627b..f613e29fe 100644 --- a/app/graphql/schema.graphql +++ b/app/graphql/schema.graphql @@ -5,22 +5,22 @@ type Address { """ The country. """ - addressCountry: String + country: String """ The locality in which the street address is, and which is in the region. """ - addressLocality: String + locality: String """ - The region. + The postal code. """ - addressRegion: String + postalCode: String """ - The postal code. + The region. """ - postalCode: String + region: String """ The street address. @@ -4423,7 +4423,6 @@ type Query { last: Int query: String ): FunderConnectionWithMeta! - heartbeat: String! image(id: ID!): Image! images(first: Int = 25, query: String): [Image!]! interactiveResource(id: ID!): InteractiveResource! diff --git a/app/graphql/types/address_type.rb b/app/graphql/types/address_type.rb index 3675a8e7f..c1b0324c3 100644 --- a/app/graphql/types/address_type.rb +++ b/app/graphql/types/address_type.rb @@ -6,7 +6,7 @@ class AddressType < BaseObject field :type, String, null: true, description: "The type." field :street_address, String, null: true, description: "The street address." field :postal_code, String, null: true, description: "The postal code." - field :address_locality, String, null: true, description: "The locality in which the street address is, and which is in the region." - field :address_region, String, null: true, description: "The region." - field :address_country, String, null: true, description: "The country." + field :locality, String, null: true, description: "The locality in which the street address is, and which is in the region." + field :region, String, null: true, description: "The region." + field :country, String, null: true, description: "The country." end diff --git a/app/graphql/types/doi_item.rb b/app/graphql/types/doi_item.rb index beb949e5a..1f7f5cb9a 100644 --- a/app/graphql/types/doi_item.rb +++ b/app/graphql/types/doi_item.rb @@ -60,7 +60,10 @@ def creators(first: nil) "name" => c.fetch("name", nil), "given_name" => c.fetch("givenName", nil), "family_name" => c.fetch("familyName", nil), - "affiliation" => c.fetch("affiliation", [])) + "affiliation" => c.fetch("affiliation", []).map do |a| + { "id" => a["affiliationIdentifier"], + "name" => a["name"] }.compact + end) end end diff --git a/app/graphql/types/funder_type.rb b/app/graphql/types/funder_type.rb index cadf02d78..7c7a2bfc6 100644 --- a/app/graphql/types/funder_type.rb +++ b/app/graphql/types/funder_type.rb @@ -27,7 +27,7 @@ def type def address { "type" => "postalAddress", - "address_country" => object.country.to_h.fetch("name", nil) } + "country" => object.country.to_h.fetch("name", nil) } end def datasets(**args) diff --git a/app/graphql/types/organization_type.rb b/app/graphql/types/organization_type.rb index c9021584a..df7e63d9a 100644 --- a/app/graphql/types/organization_type.rb +++ b/app/graphql/types/organization_type.rb @@ -37,16 +37,16 @@ def alternate_name end def identifiers - Array.wrap(object.id).map { |o| { "identifierType" => "ROR", "identifier" => o } } + - Array.wrap(object.fund_ref).map { |o| { "identifierType" => "fundRef", "identifier" => o } } + - Array.wrap(object.wikidata).map { |o| { "identifierType" => "wikidata", "identifier" => o } } + - Array.wrap(object.grid).map { |o| { "identifierType" => "grid", "identifier" => o } } + - Array.wrap(object.wikipedia_url).map { |o| { "identifierType" => "wikipedia", "identifier" => o } } + Array.wrap(object.id).map { |o| { "identifier_type" => "ROR", "identifier" => o } } + + Array.wrap(object.fund_ref).map { |o| { "identifier_type" => "fundRef", "identifier" => o } } + + Array.wrap(object.wikidata).map { |o| { "identifier_type" => "wikidata", "identifier" => o } } + + Array.wrap(object.grid).map { |o| { "identifier_type" => "grid", "identifier" => o } } + + Array.wrap(object.wikipedia_url).map { |o| { "identifier_type" => "wikipedia", "identifier" => o } } end def address { "type" => "postalAddress", - "address_country" => object.country.to_h.fetch("name", nil) } + "country" => object.country.to_h.fetch("name", nil) } end def datasets(**args) diff --git a/app/graphql/types/query_type.rb b/app/graphql/types/query_type.rb index b56a40ca8..4500c8ec4 100644 --- a/app/graphql/types/query_type.rb +++ b/app/graphql/types/query_type.rb @@ -3,14 +3,6 @@ class QueryType < BaseObject extend_type - field :heartbeat, String, null: false do - end - - def heartbeat - heartbeat = Heartbeat.new - heartbeat.string - end - field :providers, ProviderConnectionWithMetaType, null: false, connection: true, max_page_size: 1000 do argument :query, String, required: false argument :first, Int, required: false, default_value: 25 diff --git a/spec/factories/default.rb b/spec/factories/default.rb index dd2dea3d6..9ab62ef75 100644 --- a/spec/factories/default.rb +++ b/spec/factories/default.rb @@ -76,49 +76,49 @@ creators { [ { "nameType": "Personal", - "name": "Benjamin Ollomo", + "name": "Ollomo, Benjamin", "givenName": "Benjamin", "familyName": "Ollomo" }, { "nameType": "Personal", - "name": "Patrick Durand", + "name": "Durand, Patrick", "givenName": "Patrick", "familyName": "Durand" }, { "nameType": "Personal", - "name": "Franck Prugnolle", + "name": "Prugnolle, Franck", "givenName": "Franck", "familyName": "Prugnolle" }, { "nameType": "Personal", - "name": "Emmanuel J. P. Douzery", + "name": "Douzery, Emmanuel J. P.", "givenName": "Emmanuel J. P.", "familyName": "Douzery" }, { "nameType": "Personal", - "name": "Céline Arnathau", + "name": "Arnathau, Céline", "givenName": "Céline", "familyName": "Arnathau" }, { "nameType": "Personal", - "name": "Dieudonné Nkoghe", + "name": "Nkoghe, Dieudonné", "givenName": "Dieudonné", "familyName": "Nkoghe" }, { "nameType": "Personal", - "name": "Eric Leroy", + "name": "Leroy, Eric", "givenName": "Eric", "familyName": "Leroy" }, { "nameType": "Personal", - "name": "François Renaud", + "name": "Renaud, François", "givenName": "François", "familyName": "Renaud", "nameIdentifiers": [ @@ -126,7 +126,14 @@ "nameIdentifier": "https://orcid.org/0000-0003-1419-2405", "nameIdentifierScheme": "ORCID", "schemeUri": "https://orcid.org" - } + }, + ], + "affiliation": [ + { + "name": "DataCite", + "affiliationIdentifier": "https://ror.org/04wxnsj81", + "affiliationIdentifierScheme": "ROR" + }, ] } ] } diff --git a/spec/graphql/types/query_type_spec.rb b/spec/graphql/types/query_type_spec.rb index e35e6ab53..2dcdc7212 100644 --- a/spec/graphql/types/query_type_spec.rb +++ b/spec/graphql/types/query_type_spec.rb @@ -60,6 +60,14 @@ totalCount nodes { id + creators { + id + name + affiliation { + id + name + } + } citationCount citationsOverTime { year @@ -79,6 +87,7 @@ expect(response.dig("data", "datasets", "totalCount")).to eq(3) expect(response.dig("data", "datasets", "nodes").length).to eq(3) + expect(response.dig("data", "datasets", "nodes", 0, "creators").last).to eq("affiliation"=>[{"id"=>"https://ror.org/04wxnsj81", "name"=>"DataCite"}], "id"=>"https://orcid.org/0000-0003-1419-2405", "name"=>"Renaud, François") expect(response.dig("data", "datasets", "nodes", 0, "citationCount")).to eq(2) expect(response.dig("data", "datasets", "nodes", 0, "citationsOverTime")).to eq([{"total"=>1, "year"=>2015}, {"total"=>1, "year"=>2016}]) expect(response.dig("data", "datasets", "nodes", 0, "citations").length).to eq(2) @@ -126,18 +135,4 @@ expect(response.dig("data", "datasets", "nodes", 0, "references").first).to eq("id"=>"https://handle.test.datacite.org/#{target_doi.doi.downcase}", "publicationYear"=>2011) end end - - describe "heartbeat" do - let(:query) do - %(query { - heartbeat - }) - end - - it "returns the heartbeat" do - response = LupoSchema.execute(query).as_json - - expect(response.dig("data", "heartbeat")).to eq("OK") - end - end end diff --git a/spec/models/doi_spec.rb b/spec/models/doi_spec.rb index 33826655e..0d9a5ca98 100644 --- a/spec/models/doi_spec.rb +++ b/spec/models/doi_spec.rb @@ -335,7 +335,7 @@ it "creators" do expect(subject.creators.length).to eq(8) - expect(subject.creators.first).to eq("familyName"=>"Ollomo", "givenName"=>"Benjamin", "name"=>"Benjamin Ollomo", "nameType"=>"Personal") + expect(subject.creators.first).to eq("familyName"=>"Ollomo", "givenName"=>"Benjamin", "name"=>"Ollomo, Benjamin", "nameType"=>"Personal") end it "dates" do