From f26f57d927470736fb4d20c480d18f43c561599d Mon Sep 17 00:00:00 2001 From: Martin Fenner Date: Sat, 25 Jan 2020 11:52:34 +0100 Subject: [PATCH] support service count in graphql --- app/graphql/types/dataset_type.rb | 4 ++-- .../types/publication_connection_with_meta_type.rb | 2 +- app/graphql/types/publication_type.rb | 2 +- .../types/service_connection_with_meta_type.rb | 14 ++++++++++++++ 4 files changed, 18 insertions(+), 4 deletions(-) create mode 100644 app/graphql/types/service_connection_with_meta_type.rb diff --git a/app/graphql/types/dataset_type.rb b/app/graphql/types/dataset_type.rb index 766276efb..c97a4638b 100644 --- a/app/graphql/types/dataset_type.rb +++ b/app/graphql/types/dataset_type.rb @@ -29,7 +29,7 @@ def datasets(**args) ids = Event.query(nil, doi: doi_from_url(object.identifier), citation_type: "Dataset-Dataset").results.to_a.map do |e| object.identifier == e.subj_id ? doi_from_url(e.obj_id) : doi_from_url(e.subj_id) end - + ElasticsearchLoader.for(Doi).load_many(ids) end @@ -40,7 +40,7 @@ def publications(**args) ElasticsearchLoader.for(Doi).load_many(ids) end - def softwsoftware_source_codesares(**args) + def software_source_codes(**args) ids = Event.query(nil, doi: doi_from_url(object.identifier), citation_type: "Dataset-SoftwareSourceCode").results.to_a.map do |e| object.identifier == e.subj_id ? doi_from_url(e.obj_id) : doi_from_url(e.subj_id) end diff --git a/app/graphql/types/publication_connection_with_meta_type.rb b/app/graphql/types/publication_connection_with_meta_type.rb index 891efa41d..639411104 100644 --- a/app/graphql/types/publication_connection_with_meta_type.rb +++ b/app/graphql/types/publication_connection_with_meta_type.rb @@ -14,7 +14,7 @@ class PublicationConnectionWithMetaType < BaseConnection def total_count args = object.arguments - + Doi.query(args[:query], client_id: args[:client_id], provider_id: args[:provider_id], resource_type_id: "Text", state: "findable", page: { number: 1, size: 0 }).results.total end diff --git a/app/graphql/types/publication_type.rb b/app/graphql/types/publication_type.rb index 746fb81b9..03266d96b 100644 --- a/app/graphql/types/publication_type.rb +++ b/app/graphql/types/publication_type.rb @@ -19,7 +19,7 @@ def datasets(**args) ids = Event.query(nil, doi: doi_from_url(object.identifier), citation_type: "Dataset-ScholarlyArticle").results.to_a.map do |e| object.identifier == e.subj_id ? doi_from_url(e.obj_id) : doi_from_url(e.subj_id) end - + ElasticsearchLoader.for(Doi).load_many(ids) end diff --git a/app/graphql/types/service_connection_with_meta_type.rb b/app/graphql/types/service_connection_with_meta_type.rb new file mode 100644 index 000000000..f50587af9 --- /dev/null +++ b/app/graphql/types/service_connection_with_meta_type.rb @@ -0,0 +1,14 @@ +# frozen_string_literal: true + +class ServiceConnectionWithMetaType < BaseConnection + edge_type(DatasetEdgeType) + field_class GraphQL::Cache::Field + + field :total_count, Integer, null: false, cache: true + + def total_count + args = object.arguments + + Doi.query(args[:query], client_id: args[:client_id], provider_id: args[:provider_id], resource_type_id: "Service", state: "findable", page: { number: 1, size: 0 }).results.total + end +end