Skip to content

Commit

Permalink
support service count in graphql
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Fenner committed Jan 25, 2020
1 parent 60cdbfd commit f26f57d
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 4 deletions.
4 changes: 2 additions & 2 deletions app/graphql/types/dataset_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion app/graphql/types/publication_connection_with_meta_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion app/graphql/types/publication_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
14 changes: 14 additions & 0 deletions app/graphql/types/service_connection_with_meta_type.rb
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit f26f57d

Please sign in to comment.