Skip to content

Commit

Permalink
schema.org for graphql types. #343
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Fenner committed Oct 3, 2019
1 parent dc2d85a commit d353c0e
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 13 deletions.
12 changes: 12 additions & 0 deletions app/graphql/types/address_type.rb
Original file line number Diff line number Diff line change
@@ -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
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 :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
32 changes: 21 additions & 11 deletions app/graphql/types/organization_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down

0 comments on commit d353c0e

Please sign in to comment.