From 456da68c172a236a74e8d6bdd6d4481ae3c5a082 Mon Sep 17 00:00:00 2001 From: Martin Fenner Date: Mon, 22 Jul 2019 08:36:08 +0200 Subject: [PATCH] include researchers in organization graphql --- ...ation_dataset_connection_with_meta_type.rb | 2 +- ...n_publication_connection_with_meta_type.rb | 2 +- ...on_researcher_connection_with_meta_type.rb | 12 ++++++++++ ...tion_software_connection_with_meta_type.rb | 2 +- app/graphql/types/organization_type.rb | 23 ++++++++++++++----- app/graphql/types/researcher_type.rb | 2 +- 6 files changed, 33 insertions(+), 10 deletions(-) create mode 100644 app/graphql/types/organization_researcher_connection_with_meta_type.rb diff --git a/app/graphql/types/organization_dataset_connection_with_meta_type.rb b/app/graphql/types/organization_dataset_connection_with_meta_type.rb index ab6394a62..3dce39a0c 100644 --- a/app/graphql/types/organization_dataset_connection_with_meta_type.rb +++ b/app/graphql/types/organization_dataset_connection_with_meta_type.rb @@ -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 \ No newline at end of file diff --git a/app/graphql/types/organization_publication_connection_with_meta_type.rb b/app/graphql/types/organization_publication_connection_with_meta_type.rb index 2f2db5eb9..7eb634efc 100644 --- a/app/graphql/types/organization_publication_connection_with_meta_type.rb +++ b/app/graphql/types/organization_publication_connection_with_meta_type.rb @@ -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 diff --git a/app/graphql/types/organization_researcher_connection_with_meta_type.rb b/app/graphql/types/organization_researcher_connection_with_meta_type.rb new file mode 100644 index 000000000..e82f12616 --- /dev/null +++ b/app/graphql/types/organization_researcher_connection_with_meta_type.rb @@ -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 diff --git a/app/graphql/types/organization_software_connection_with_meta_type.rb b/app/graphql/types/organization_software_connection_with_meta_type.rb index 436868257..3b374f915 100644 --- a/app/graphql/types/organization_software_connection_with_meta_type.rb +++ b/app/graphql/types/organization_software_connection_with_meta_type.rb @@ -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 diff --git a/app/graphql/types/organization_type.rb b/app/graphql/types/organization_type.rb index 3c7b2740e..428bc32e0 100644 --- a/app/graphql/types/organization_type.rb +++ b/app/graphql/types/organization_type.rb @@ -16,21 +16,25 @@ 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 @@ -38,16 +42,23 @@ def datasets(**args) 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 diff --git a/app/graphql/types/researcher_type.rb b/app/graphql/types/researcher_type.rb index 87dd6960b..04a1096b5 100644 --- a/app/graphql/types/researcher_type.rb +++ b/app/graphql/types/researcher_type.rb @@ -26,7 +26,7 @@ def id end def name - object.name || object.fetch("name", nil) + object.name end def affiliation