Skip to content

Commit

Permalink
include researchers in organization graphql
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Fenner committed Jul 22, 2019
1 parent 11aa6a7 commit 456da68
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ class OrganizationDatasetConnectionWithMetaType < BaseConnection
field :total_count, Integer, null: false, cache: true

def total_count
Event.query(nil, obj_id: object.parent[:id], citation_type: "Dataset-Organization").results.total
Event.query(nil, obj_id: object.parent.id, citation_type: "Dataset-Organization").results.total
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ class OrganizationPublicationConnectionWithMetaType < BaseConnection
field :total_count, Integer, null: false, cache: true

def total_count
Event.query(nil, obj_id: object.parent[:id], citation_type: "Organization-ScholarlyArticle").results.total
Event.query(nil, obj_id: object.parent.id, citation_type: "Organization-ScholarlyArticle").results.total
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# frozen_string_literal: true

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

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

def total_count
Event.query(nil, obj_id: object.parent.id, citation_type: "Organization-Person").results.total
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ class OrganizationSoftwareConnectionWithMetaType < BaseConnection
field :total_count, Integer, null: false, cache: true

def total_count
Event.query(nil, obj_id: object.parent[:id], citation_type: "Organization-SoftwareSourceCode").results.total
Event.query(nil, obj_id: object.parent.id, citation_type: "Organization-SoftwareSourceCode").results.total
end
end
23 changes: 17 additions & 6 deletions app/graphql/types/organization_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,38 +16,49 @@ class OrganizationType < BaseObject
field :wikidata, [String], null: true, description: "Wikidata identifiers for organization"
field :grid, String, null: true, description: "GRID identifiers for organization"

field :datasets, OrganizationDatasetConnectionWithMetaType, null: false, description: "Datasets from this organization", connection: true, max_page_size: 100 do
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
end

field :publications, OrganizationPublicationConnectionWithMetaType, null: false, description: "Publications from this organization", connection: true do
field :publications, OrganizationPublicationConnectionWithMetaType, null: false, description: "Publications from this organization", connection: true, max_page_size: 1000 do
argument :query, String, required: false
argument :first, Int, required: false, default_value: 25
end

field :softwares, OrganizationSoftwareConnectionWithMetaType, null: false, description: "Software from this organization", connection: true, max_page_size: 100 do
field :softwares, OrganizationSoftwareConnectionWithMetaType, null: false, description: "Software from 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 datasets(**args)
ids = Event.query(nil, obj_id: object[:id], citation_type: "Dataset-Organization").results.to_a.map do |e|
ids = Event.query(nil, obj_id: object.id, citation_type: "Dataset-Organization").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: object[:id], citation_type: "Organization-ScholarlyArticle").results.to_a.map do |e|
ids = Event.query(nil, obj_id: object.id, citation_type: "Organization-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: object[:id], citation_type: "Organization-SoftwareSourceCode").results.to_a.map do |e|
ids = Event.query(nil, obj_id: object.id, citation_type: "Organization-SoftwareSourceCode").results.to_a.map do |e|
doi_from_url(e.subj_id)
end
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|
e.subj_id
end
ElasticsearchLoader.for(Researcher).load_many(ids)
end
end
2 changes: 1 addition & 1 deletion app/graphql/types/researcher_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def id
end

def name
object.name || object.fetch("name", nil)
object.name
end

def affiliation
Expand Down

0 comments on commit 456da68

Please sign in to comment.