Skip to content

Commit

Permalink
fix organization type in graphql. #426
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Fenner committed Feb 23, 2020
1 parent 48b36c6 commit c18f8b9
Show file tree
Hide file tree
Showing 9 changed files with 46 additions and 50 deletions.
13 changes: 6 additions & 7 deletions app/graphql/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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!
Expand Down
6 changes: 3 additions & 3 deletions app/graphql/types/address_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
5 changes: 4 additions & 1 deletion app/graphql/types/doi_item.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion app/graphql/types/funder_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
12 changes: 6 additions & 6 deletions app/graphql/types/organization_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 0 additions & 8 deletions app/graphql/types/query_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
25 changes: 16 additions & 9 deletions spec/factories/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,57 +76,64 @@
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": [
{
"nameIdentifier": "https://orcid.org/0000-0003-1419-2405",
"nameIdentifierScheme": "ORCID",
"schemeUri": "https://orcid.org"
}
},
],
"affiliation": [
{
"name": "DataCite",
"affiliationIdentifier": "https://ror.org/04wxnsj81",
"affiliationIdentifierScheme": "ROR"
},
]
}
] }
Expand Down
23 changes: 9 additions & 14 deletions spec/graphql/types/query_type_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,14 @@
totalCount
nodes {
id
creators {
id
name
affiliation {
id
name
}
}
citationCount
citationsOverTime {
year
Expand All @@ -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)
Expand Down Expand Up @@ -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
2 changes: 1 addition & 1 deletion spec/models/doi_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit c18f8b9

Please sign in to comment.