From ca12ae5be27d08f15c72d9d76655848343e514db Mon Sep 17 00:00:00 2001 From: Martin Fenner Date: Sun, 30 Jun 2019 12:57:43 +0200 Subject: [PATCH] show summary connection counts in graphql api. #299 --- .../dataset_connection_with_meta_type.rb | 20 +++++++++++++++++++ .../types/funder_connection_with_meta_type.rb | 17 +++++++++++++++- .../publication_connection_with_meta_type.rb | 20 +++++++++++++++++++ .../researcher_connection_with_meta_type.rb | 17 +++++++++++++++- .../software_connection_with_meta_type.rb | 20 +++++++++++++++++++ 5 files changed, 92 insertions(+), 2 deletions(-) diff --git a/app/graphql/types/dataset_connection_with_meta_type.rb b/app/graphql/types/dataset_connection_with_meta_type.rb index 90e41787f..4dbcc94a8 100644 --- a/app/graphql/types/dataset_connection_with_meta_type.rb +++ b/app/graphql/types/dataset_connection_with_meta_type.rb @@ -5,10 +5,30 @@ class DatasetConnectionWithMetaType < BaseConnection field_class GraphQL::Cache::Field field :total_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 :funder_connection_count, Integer, null: false, cache: true def total_count args = object.arguments Doi.query(args[:query], resource_type_id: "Dataset", state: "findable", page: { number: 1, size: args[:first] }).results.total end + + def publication_connection_count + Event.query(nil, citation_type: "Dataset-ScholarlyArticle").results.total + end + + def software_connection_count + Event.query(nil, citation_type: "Dataset-SoftwareSourceCode").results.total + end + + def researcher_connection_count + Event.query(nil, citation_type: "Dataset-Researcher").results.total + end + + def funder_connection_count + Event.query(nil, citation_type: "Dataset-Funder").results.total + end end diff --git a/app/graphql/types/funder_connection_with_meta_type.rb b/app/graphql/types/funder_connection_with_meta_type.rb index 4f5538cd7..a3fbfcceb 100644 --- a/app/graphql/types/funder_connection_with_meta_type.rb +++ b/app/graphql/types/funder_connection_with_meta_type.rb @@ -5,10 +5,25 @@ class FunderConnectionWithMetaType < BaseConnection field_class GraphQL::Cache::Field field :total_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 :software_connection_count, Integer, null: false, cache: true + def total_count args = object.arguments Funder.query(args[:query], limit: 0).dig(:meta, "total").to_i end + + def publication_connection_count + Event.query(nil, citation_type: "Funder-ScholarlyArticle").results.total + end + + def dataset_connection_count + Event.query(nil, citation_type: "Dataset-Funder").results.total + end + + def software_connection_count + Event.query(nil, citation_type: "Funder-SoftwareSourceCode").results.total + end end diff --git a/app/graphql/types/publication_connection_with_meta_type.rb b/app/graphql/types/publication_connection_with_meta_type.rb index 2309cfefd..c44a57a48 100644 --- a/app/graphql/types/publication_connection_with_meta_type.rb +++ b/app/graphql/types/publication_connection_with_meta_type.rb @@ -5,10 +5,30 @@ class PublicationConnectionWithMetaType < BaseConnection field_class GraphQL::Cache::Field field :total_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 :funder_connection_count, Integer, null: false, cache: true def total_count args = object.arguments Doi.query(args[:query], resource_type_id: "Text", state: "findable", page: { number: 1, size: args[:first] }).results.total end + + def dataset_connection_count + Event.query(nil, citation_type: "Dataset-ScholarlyArticle").results.total + end + + def software_connection_count + Event.query(nil, citation_type: "ScholarlyArticle-SoftwareSourceCode").results.total + end + + def researcher_connection_count + Event.query(nil, citation_type: "Researcher-ScholarlyArticle").results.total + end + + def funder_connection_count + Event.query(nil, citation_type: "Funder-ScholarlyArticle").results.total + end end diff --git a/app/graphql/types/researcher_connection_with_meta_type.rb b/app/graphql/types/researcher_connection_with_meta_type.rb index 71d05ee8b..07a2e28e7 100644 --- a/app/graphql/types/researcher_connection_with_meta_type.rb +++ b/app/graphql/types/researcher_connection_with_meta_type.rb @@ -5,10 +5,25 @@ class ResearcherConnectionWithMetaType < BaseConnection field_class GraphQL::Cache::Field field :total_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 :software_connection_count, Integer, null: false, cache: true + def total_count args = object.arguments Researcher.query(args[:query], page: { number: 1, size: 0 }).results.total end + + def publication_connection_count + Event.query(nil, citation_type: "Researcher-ScholarlyArticle").results.total + end + + def dataset_connection_count + Event.query(nil, citation_type: "Dataset-Researcher").results.total + end + + def software_connection_count + Event.query(nil, citation_type: "Researcher-SoftwareSourceCode").results.total + end end diff --git a/app/graphql/types/software_connection_with_meta_type.rb b/app/graphql/types/software_connection_with_meta_type.rb index a39ae7a37..bca5ddc87 100644 --- a/app/graphql/types/software_connection_with_meta_type.rb +++ b/app/graphql/types/software_connection_with_meta_type.rb @@ -5,10 +5,30 @@ class SoftwareConnectionWithMetaType < BaseConnection field_class GraphQL::Cache::Field field :total_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 :funder_connection_count, Integer, null: false, cache: true def total_count args = object.arguments Doi.query(args[:query], resource_type_id: "Software", state: "findable", page: { number: 1, size: args[:first] }).results.total end + + def publication_connection_count + Event.query(nil, citation_type: "ScholarlyArticle-SoftwareSourceCode").results.total + end + + def dataset_connection_count + Event.query(nil, citation_type: "Dataset-SoftwareSourceCode").results.total + end + + def researcher_connection_count + Event.query(nil, citation_type: "Researcher-SoftwareSourceCode").results.total + end + + def funder_connection_count + Event.query(nil, citation_type: "Funder-SoftwareSourceCode").results.total + end end