Skip to content

Commit

Permalink
show summary connection counts in graphql api. #299
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Fenner committed Jun 30, 2019
1 parent f71a0b6 commit ca12ae5
Show file tree
Hide file tree
Showing 5 changed files with 92 additions and 2 deletions.
20 changes: 20 additions & 0 deletions app/graphql/types/dataset_connection_with_meta_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
17 changes: 16 additions & 1 deletion app/graphql/types/funder_connection_with_meta_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
20 changes: 20 additions & 0 deletions app/graphql/types/publication_connection_with_meta_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
17 changes: 16 additions & 1 deletion app/graphql/types/researcher_connection_with_meta_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
20 changes: 20 additions & 0 deletions app/graphql/types/software_connection_with_meta_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit ca12ae5

Please sign in to comment.