From 026d8defb49efeb2efad7dee013e32cfc2b10df0 Mon Sep 17 00:00:00 2001 From: Martin Fenner Date: Sun, 30 Jun 2019 16:15:30 +0200 Subject: [PATCH] show connection counts within one type. #299 --- app/graphql/types/dataset_connection_with_meta_type.rb | 5 +++++ app/graphql/types/publication_connection_with_meta_type.rb | 5 +++++ app/graphql/types/software_connection_with_meta_type.rb | 5 +++++ 3 files changed, 15 insertions(+) diff --git a/app/graphql/types/dataset_connection_with_meta_type.rb b/app/graphql/types/dataset_connection_with_meta_type.rb index 3b4230efb..3ff3812b4 100644 --- a/app/graphql/types/dataset_connection_with_meta_type.rb +++ b/app/graphql/types/dataset_connection_with_meta_type.rb @@ -5,6 +5,7 @@ class DatasetConnectionWithMetaType < BaseConnection field_class GraphQL::Cache::Field field :total_count, Integer, null: false, cache: true + 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 @@ -16,6 +17,10 @@ def total_count Doi.query(args[:query], resource_type_id: "Dataset", state: "findable", page: { number: 1, size: args[:first] }).results.total end + def dataset_connection_count + Event.query(nil, citation_type: "Dataset-Dataset").results.total + end + def publication_connection_count Event.query(nil, citation_type: "Dataset-ScholarlyArticle").results.total end diff --git a/app/graphql/types/publication_connection_with_meta_type.rb b/app/graphql/types/publication_connection_with_meta_type.rb index d1de6c710..0abae12c1 100644 --- a/app/graphql/types/publication_connection_with_meta_type.rb +++ b/app/graphql/types/publication_connection_with_meta_type.rb @@ -5,6 +5,7 @@ class PublicationConnectionWithMetaType < 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 field :researcher_connection_count, Integer, null: false, cache: true @@ -16,6 +17,10 @@ def total_count Doi.query(args[:query], resource_type_id: "Text", state: "findable", page: { number: 1, size: args[:first] }).results.total end + def publication_connection_count + Event.query(nil, citation_type: "ScholarlyArticle-ScholarlyArticle").results.total + end + def dataset_connection_count Event.query(nil, citation_type: "Dataset-ScholarlyArticle").results.total end diff --git a/app/graphql/types/software_connection_with_meta_type.rb b/app/graphql/types/software_connection_with_meta_type.rb index 6b2c66d6f..07c545fdb 100644 --- a/app/graphql/types/software_connection_with_meta_type.rb +++ b/app/graphql/types/software_connection_with_meta_type.rb @@ -5,6 +5,7 @@ class SoftwareConnectionWithMetaType < BaseConnection field_class GraphQL::Cache::Field field :total_count, Integer, null: false, cache: true + 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 @@ -16,6 +17,10 @@ def total_count Doi.query(args[:query], resource_type_id: "Software", state: "findable", page: { number: 1, size: args[:first] }).results.total end + def software_connection_count + Event.query(nil, citation_type: "SoftwareSourceCode-SoftwareSourceCode").results.total + end + def publication_connection_count Event.query(nil, citation_type: "ScholarlyArticle-SoftwareSourceCode").results.total end