Skip to content

Commit

Permalink
adjust graphql schema. #425
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Fenner committed Feb 23, 2020
1 parent b448aee commit d8cb128
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 10 deletions.
16 changes: 16 additions & 0 deletions app/graphql/types/creator_type.rb
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion app/graphql/types/doi_item.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions app/graphql/types/identifier_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
15 changes: 8 additions & 7 deletions app/graphql/types/organization_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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."

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit d8cb128

Please sign in to comment.