diff --git a/app/graphql/types/address_type.rb b/app/graphql/types/address_type.rb new file mode 100644 index 000000000..3675a8e7f --- /dev/null +++ b/app/graphql/types/address_type.rb @@ -0,0 +1,12 @@ +# frozen_string_literal: true + +class AddressType < BaseObject + description "Information about addresses" + + 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." +end diff --git a/app/graphql/types/identifier_type.rb b/app/graphql/types/identifier_type.rb index 4c60c6bfa..bf24fe0df 100644 --- a/app/graphql/types/identifier_type.rb +++ b/app/graphql/types/identifier_type.rb @@ -3,6 +3,6 @@ class IdentifierType < BaseObject description "Information about identifiers" - field :identifier, String, null: true, description: "Identifier" - field :identifier_type, String, null: true, hash_key: "identifierType", description: "Identifier type" + field :name, String, null: true, description: "The name of the identifier." + field :value, String, null: true, description: "The value of the identifier." end diff --git a/app/graphql/types/organization_type.rb b/app/graphql/types/organization_type.rb index 70442d75f..70ea67456 100644 --- a/app/graphql/types/organization_type.rb +++ b/app/graphql/types/organization_type.rb @@ -4,17 +4,11 @@ class OrganizationType < BaseObject description "Information about organizations" field :id, ID, null: true, description: "ROR ID" - field :name, String, null: false, description: "Organization name" - field :aliases, [String], null: true, description: "Aliases for organization name" - field :acronyms, [String], null: true, description: "Acronyms for organization name" - field :labels, [LabelType], null: true, description: "Labels for organization name" - field :links, [String], null: true, description: "Links for organization" - field :wikipedia_url, String, null: true, description: "Wikipedia URL for organization" - field :country, CountryType, null: true, description: "Country where organization is located" - field :isni, [String], null: true, description: "ISNI identifiers for organization" - field :fund_ref, [String], null: true, description: "Crossref Funder ID identifiers for organization" - field :wikidata, [String], null: true, description: "Wikidata identifiers for organization" - field :grid, String, null: true, description: "GRID identifiers for organization" + field :name, String, null: false, description: "The name of the organization." + field :alternate_name, [String], null: true, description: "An alias for the organization." + field :identifier, [IdentifierType], null: true, description: "The identifier(s) for the organization." + field :url, [String], null: true, hash_key: "links", description: "URL of the organization." + field :address, AddressType, null: true, description: "Physical address of the organization." field :datasets, OrganizationDatasetConnectionWithMetaType, null: false, description: "Datasets from this organization", connection: true, max_page_size: 1000 do argument :first, Int, required: false, default_value: 25 @@ -33,6 +27,22 @@ class OrganizationType < BaseObject argument :first, Int, required: false, default_value: 25 end + def alternate_name + object.aliases + object.acronyms + end + + def identifier + Array.wrap(object.fund_ref).map { |o| { "name" => "fundRef", "value" => o } } + + Array.wrap(object.wikidata).map { |o| { "name" => "wikidata", "value" => o } } + + Array.wrap(object.grid).map { |o| { "name" => "grid", "value" => o } } + + Array.wrap(object.wikipedia_url).map { |o| { "name" => "wikipedia", "value" => o } } + end + + def address + { "type" => "postalAddress", + "address_country" => object.country.fetch("name", nil) } + end + def datasets(**args) ids = Event.query(nil, obj_id: object.id, citation_type: "Dataset-Organization").results.to_a.map do |e| doi_from_url(e.subj_id)