Skip to content

Commit

Permalink
add person fields to graphql
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Fenner committed Oct 4, 2019
1 parent f08f855 commit 995f51e
Show file tree
Hide file tree
Showing 13 changed files with 130 additions and 59 deletions.
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ gem 'json', '~> 1.8', '>= 1.8.5'
gem 'oj', '>= 2.8.3'
gem 'jsonlint', '~> 0.2.0'
gem 'equivalent-xml', '~> 0.6.0'
gem 'nokogiri', '~> 1.8.1'
gem "nokogiri", ">= 1.10.4"
gem 'diffy', '~> 3.2', '>= 3.2.1'
gem 'commonmarker', '~> 0.17.9'
gem 'iso8601', '~> 0.9.0'
Expand Down
40 changes: 20 additions & 20 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ GEM
activerecord (>= 4.2, < 6.1)
aws-eventstream (1.0.3)
aws-partitions (1.220.0)
aws-sdk-core (3.68.0)
aws-sdk-core (3.68.1)
aws-eventstream (~> 1.0, >= 1.0.2)
aws-partitions (~> 1.0)
aws-sigv4 (~> 1.1)
Expand Down Expand Up @@ -109,7 +109,7 @@ GEM
latex-decode (~> 0.0)
binding_of_caller (0.8.0)
debug_inspector (>= 0.0.1)
bolognese (1.3.16)
bolognese (1.3.19)
activesupport (>= 4.2.5, < 6)
benchmark_methods (~> 0.7)
bibtex-ruby (~> 4.1)
Expand All @@ -124,13 +124,13 @@ GEM
json-ld-preloaded (= 3.0.2)
jsonlint (~> 0.2.0)
loofah (~> 2.0, >= 2.0.3)
maremma (>= 3.5.7, < 5)
maremma (>= 4.3, < 5)
namae (~> 1.0)
nokogiri (~> 1.8.1)
nokogiri (~> 1.10.4)
oj (>= 2.8.3)
postrank-uri (~> 1.0, >= 1.0.18)
rdf-rdfxml (~> 2.0)
rdf-turtle (~> 2.2)
rdf-rdfxml (~> 2.2)
rdf-turtle (~> 3.0, >= 3.0.6)
thor (~> 0.19)
bootsnap (1.4.5)
msgpack (~> 1.0)
Expand Down Expand Up @@ -240,7 +240,7 @@ GEM
git (1.5.0)
globalid (0.4.2)
activesupport (>= 4.2.0)
google-protobuf (3.9.2)
google-protobuf (3.10.0-universal-darwin)
graphql (1.9.12)
graphql-batch (0.4.1)
graphql (>= 1.3, < 2)
Expand All @@ -257,7 +257,7 @@ GEM
htmlentities (4.3.4)
http-cookie (1.0.3)
domain_name (~> 0.5)
i18n (1.6.0)
i18n (1.7.0)
concurrent-ruby (~> 1.0)
i18n_data (0.8.0)
iso8601 (0.9.1)
Expand Down Expand Up @@ -311,7 +311,7 @@ GEM
rest-client (~> 2.0.2)
marcel (0.3.3)
mimemagic (~> 0.3.2)
maremma (4.2.6)
maremma (4.3)
activesupport (>= 4.2.5, < 6)
addressable (>= 2.3.6)
builder (~> 3.2, >= 3.2.2)
Expand All @@ -320,7 +320,7 @@ GEM
faraday-encoding (~> 0.0.4)
faraday_middleware (~> 0.12.0)
multi_json (~> 1.12)
nokogiri (~> 1.8.1)
nokogiri (~> 1.10.4)
oj (>= 2.8.3)
method_source (0.9.2)
mime-types (3.3)
Expand All @@ -329,7 +329,7 @@ GEM
mimemagic (0.3.3)
mini_magick (4.9.5)
mini_mime (1.0.2)
mini_portile2 (2.3.0)
mini_portile2 (2.4.0)
minitest (5.12.2)
money (6.13.4)
i18n (>= 0.6.4, <= 2)
Expand All @@ -340,13 +340,13 @@ GEM
namae (1.0.1)
netrc (0.11.0)
nio4r (2.5.2)
nokogiri (1.8.5)
mini_portile2 (~> 2.3.0)
nokogiri (1.10.4)
mini_portile2 (~> 2.4.0)
oj (2.18.5)
oj_mimic_json (1.0.1)
pandoc-ruby (2.0.2)
parallel (1.17.0)
parser (2.6.4.1)
parser (2.6.5.0)
ast (~> 2.4.0)
postrank-uri (1.0.24)
addressable (>= 2.4.0)
Expand Down Expand Up @@ -414,9 +414,9 @@ GEM
rdf (>= 2.2, < 4.0)
rdf-rdfa (>= 2.2, < 4.0)
rdf-xsd (>= 2.2, < 4.0)
rdf-turtle (2.2.2)
rdf-turtle (3.0.6)
ebnf (~> 1.1)
rdf (>= 2.2, < 4.0)
rdf (~> 3.0)
rdf-xsd (3.0.1)
rdf (~> 3.0)
regexp_parser (1.6.0)
Expand All @@ -436,10 +436,10 @@ GEM
rspec (>= 3.0.0, < 4.0.0)
rspec-core (3.8.2)
rspec-support (~> 3.8.0)
rspec-expectations (3.8.4)
rspec-expectations (3.8.5)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.8.0)
rspec-mocks (3.8.1)
rspec-mocks (3.8.2)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.8.0)
rspec-rails (3.8.2)
Expand All @@ -450,7 +450,7 @@ GEM
rspec-expectations (~> 3.8.0)
rspec-mocks (~> 3.8.0)
rspec-support (~> 3.8.0)
rspec-support (3.8.2)
rspec-support (3.8.3)
rubocop (0.68.1)
jaro_winkler (~> 1.5.1)
parallel (~> 1.10)
Expand Down Expand Up @@ -593,7 +593,7 @@ DEPENDENCIES
mini_magick (~> 4.8)
multi_json
mysql2 (~> 0.4.4)
nokogiri (~> 1.8.1)
nokogiri (>= 1.10.4)
oj (>= 2.8.3)
oj_mimic_json (~> 1.0, >= 1.0.1)
premailer (~> 1.11, >= 1.11.1)
Expand Down
4 changes: 2 additions & 2 deletions app/graphql/types/dataset_connection_with_meta_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class DatasetConnectionWithMetaType < BaseConnection
field :dataset_connection_count, Integer, null: false, cache: true
field :publication_connection_count, Integer, null: false, cache: true
field :software_connection_count, Integer, null: false, cache: true
field :researcher_connection_count, Integer, null: false, cache: true
field :person_connection_count, Integer, null: false, cache: true
field :funder_connection_count, Integer, null: false, cache: true
field :organization_connection_count, Integer, null: false, cache: true

Expand All @@ -30,7 +30,7 @@ def software_connection_count
Event.query(nil, citation_type: "Dataset-SoftwareSourceCode").results.total
end

def researcher_connection_count
def person_connection_count
Event.query(nil, citation_type: "Dataset-Person").results.total
end

Expand Down
2 changes: 1 addition & 1 deletion app/graphql/types/doi_item.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module DoiItem
description "Information about DOIs"

field :id, ID, null: false, hash_key: "identifier", description: "The persistent identifier for the resource"
field :creators, [ResearcherType], null: true, description: "The main researchers involved in producing the data, or the authors of the publication, in priority order" do
field :creators, [PersonType], 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/organization_connection_with_meta_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ class OrganizationConnectionWithMetaType < BaseConnection
field_class GraphQL::Cache::Field

field :total_count, Integer, null: false, cache: true
field :researcher_connection_count, Integer, null: false, cache: true
field :person_connection_count, Integer, null: false, cache: true

def total_count
args = object.arguments

Organization.query(args[:query], limit: 0).dig(:meta, "total").to_i
end

def researcher_connection_count
def person_connection_count
Event.query(nil, citation_type: "Organization-Person").results.total
end
end
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

class OrganizationResearcherConnectionWithMetaType < BaseConnection
class OrganizationPersonConnectionWithMetaType < BaseConnection
edge_type(EventDataEdgeType, edge_class: EventDataEdge)
field_class GraphQL::Cache::Field

Expand Down
18 changes: 9 additions & 9 deletions app/graphql/types/organization_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ class OrganizationType < BaseObject
argument :first, Int, required: false, default_value: 25
end

field :researchers, OrganizationResearcherConnectionWithMetaType, null: false, description: "Researchers associated with this organization", connection: true, max_page_size: 1000 do
argument :first, Int, required: false, default_value: 25
end
# field :researchers, OrganizationResearcherConnectionWithMetaType, null: false, description: "Researchers associated with this organization", connection: true, max_page_size: 1000 do
# argument :first, Int, required: false, default_value: 25
# end

def alternate_name
object.aliases + object.acronyms
Expand Down Expand Up @@ -65,10 +65,10 @@ def softwares(**args)
ElasticsearchLoader.for(Doi).load_many(ids)
end

def researchers(**args)
ids = Event.query(nil, obj_id: object.id, citation_type: "Organization-Person").results.to_a.map do |e|
orcid_from_url(e.subj_id)
end
ElasticsearchLoader.for(Researcher).load_many(ids)
end
# def researchers(**args)
# ids = Event.query(nil, obj_id: object.id, citation_type: "Organization-Person").results.to_a.map do |e|
# orcid_from_url(e.subj_id)
# end
# ElasticsearchLoader.for(Researcher).load_many(ids)
# end
end
27 changes: 27 additions & 0 deletions app/graphql/types/person_connection_with_meta_type.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# frozen_string_literal: true

class PersonConnectionWithMetaType < BaseConnection
edge_type(PersonEdgeType)
field_class GraphQL::Cache::Field

field :publication_connection_count, Integer, null: false, cache: true
field :dataset_connection_count, Integer, null: false, cache: true
field :software_connection_count, Integer, null: false, cache: true
field :organization_connection_count, Integer, null: false, cache: true

def publication_connection_count
Event.query(nil, citation_type: "Person-ScholarlyArticle").results.total
end

def dataset_connection_count
Event.query(nil, citation_type: "Dataset-Person").results.total
end

def software_connection_count
Event.query(nil, citation_type: "Person-SoftwareSourceCode").results.total
end

def organization_connection_count
Event.query(nil, citation_type: "Organization-Person").results.total
end
end
5 changes: 5 additions & 0 deletions app/graphql/types/person_edge_type.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# frozen_string_literal: true

class PersonEdgeType < GraphQL::Types::Relay::BaseEdge
node_type(PersonType)
end
58 changes: 58 additions & 0 deletions app/graphql/types/person_type.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# frozen_string_literal: true

class PersonType < BaseObject
description "A person."

field :id, ID, null: true, description: "The ORCID ID of the person."
field :name, String, null: true, description: "The name of the person."
field :given_name, String, null: true, hash_key: "given_names", 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 :datasets, PersonDatasetConnectionWithMetaType, null: true, description: "Authored datasets", connection: true, max_page_size: 100 do
argument :first, Int, required: false, default_value: 25
end

field :publications, PersonPublicationConnectionWithMetaType, null: true, description: "Authored publications", connection: true, max_page_size: 100 do
argument :first, Int, required: false, default_value: 25
end

field :softwares, PersonSoftwareConnectionWithMetaType, null: true, description: "Authored software", connection: true, max_page_size: 100 do
argument :first, Int, required: false, default_value: 25
end

def id
object.uid ? "https://orcid.org/#{object.uid}" : object.id
end

def name
object.name
end

def datasets(**args)
ids = Event.query(nil, obj_id: https_to_http(object.uid || object.id), citation_type: "Dataset-Person").results.to_a.map do |e|
doi_from_url(e.subj_id)
end
ElasticsearchLoader.for(Doi).load_many(ids)
end

def publications(**args)
ids = Event.query(nil, obj_id: https_to_http(object.uid || object.id), citation_type: "Person-ScholarlyArticle").results.to_a.map do |e|
doi_from_url(e.subj_id)
end
ElasticsearchLoader.for(Doi).load_many(ids)
end

def softwares(**args)
ids = Event.query(nil, obj_id: https_to_http(object.uid || object.id), citation_type: "Person-SoftwareSourceCode").results.to_a.map do |e|
doi_from_url(e.subj_id)
end
ElasticsearchLoader.for(Doi).load_many(ids)
end

def https_to_http(url)
orcid = orcid_from_url(url)
return nil unless orcid.present?

"https://orcid.org/#{orcid}"
end
end
4 changes: 2 additions & 2 deletions app/graphql/types/publication_connection_with_meta_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class PublicationConnectionWithMetaType < BaseConnection
field :publication_connection_count, Integer, null: false, cache: true
field :dataset_connection_count, Integer, null: false, cache: true
field :software_connection_count, Integer, null: false, cache: true
field :researcher_connection_count, Integer, null: false, cache: true
field :person_connection_count, Integer, null: false, cache: true
field :funder_connection_count, Integer, null: false, cache: true
field :organization_connection_count, Integer, null: false, cache: true

Expand All @@ -30,7 +30,7 @@ def software_connection_count
Event.query(nil, citation_type: "ScholarlyArticle-SoftwareSourceCode").results.total
end

def researcher_connection_count
def person_connection_count
Event.query(nil, citation_type: "Person-ScholarlyArticle").results.total
end

Expand Down
19 changes: 0 additions & 19 deletions app/graphql/types/researcher_type.rb

This file was deleted.

4 changes: 2 additions & 2 deletions app/graphql/types/software_connection_with_meta_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class SoftwareConnectionWithMetaType < BaseConnection
field :software_connection_count, Integer, null: false, cache: true
field :publication_connection_count, Integer, null: false, cache: true
field :dataset_connection_count, Integer, null: false, cache: true
field :researcher_connection_count, Integer, null: false, cache: true
field :person_connection_count, Integer, null: false, cache: true
field :funder_connection_count, Integer, null: false, cache: true
field :organization_connection_count, Integer, null: false, cache: true

Expand All @@ -30,7 +30,7 @@ def dataset_connection_count
Event.query(nil, citation_type: "Dataset-SoftwareSourceCode").results.total
end

def researcher_connection_count
def person_connection_count
Event.query(nil, citation_type: "Person-SoftwareSourceCode").results.total
end

Expand Down

0 comments on commit 995f51e

Please sign in to comment.