From d8cb128b57f1eed3bce95a0562f1f1db3f341710 Mon Sep 17 00:00:00 2001 From: Martin Fenner Date: Sun, 23 Feb 2020 16:23:10 +0100 Subject: [PATCH] adjust graphql schema. #425 --- app/graphql/types/creator_type.rb | 16 ++++++++++++++++ app/graphql/types/doi_item.rb | 2 +- app/graphql/types/identifier_type.rb | 4 ++-- app/graphql/types/organization_type.rb | 15 ++++++++------- 4 files changed, 27 insertions(+), 10 deletions(-) create mode 100644 app/graphql/types/creator_type.rb diff --git a/app/graphql/types/creator_type.rb b/app/graphql/types/creator_type.rb new file mode 100644 index 000000000..3625af1ad --- /dev/null +++ b/app/graphql/types/creator_type.rb @@ -0,0 +1,16 @@ +# frozen_string_literal: true + +class CreatorType < BaseObject + description "A creator." + + field :id, ID, null: true, description: "The ID of the creator." + field :type, String, null: false, description: "The type of the item." + field :name, String, null: true, description: "The name of the creator." + 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, [OrganizationType], null: true, description: "The organizational or institutional affiliation of the creator." + + 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 db7d325c9..beb949e5a 100644 --- a/app/graphql/types/doi_item.rb +++ b/app/graphql/types/doi_item.rb @@ -8,7 +8,7 @@ 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 :creators, [PersonType], 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 :titles, [TitleType], null: true, description: "A name or title by which a resource is known" do diff --git a/app/graphql/types/identifier_type.rb b/app/graphql/types/identifier_type.rb index bf24fe0df..2e98a5c0c 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 :name, String, null: true, description: "The name of the identifier." - field :value, String, null: true, description: "The value of the identifier." + field :identifier_type, String, null: true, description: "The type of identifier." + field :identifier, 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 17f2735b4..c9021584a 100644 --- a/app/graphql/types/organization_type.rb +++ b/app/graphql/types/organization_type.rb @@ -3,11 +3,11 @@ class OrganizationType < BaseObject description "Information about organizations" - field :id, ID, null: false, description: "ROR ID" + field :id, ID, null: true, description: "ROR ID" field :type, String, null: false, description: "The type of the item." 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 :identifiers, [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." @@ -36,11 +36,12 @@ 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 } } + 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 } } end def address