Skip to content

Commit

Permalink
include affiliation connections to dois in graphql. #318
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Fenner committed Jul 20, 2019
1 parent fb1e1a7 commit 1c273f6
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# frozen_string_literal: true

class OrganizationDatasetConnectionWithMetaType < BaseConnection
edge_type(EventDataEdgeType, edge_class: EventDataEdge)
field_class GraphQL::Cache::Field

field :total_count, Integer, null: false, cache: true

def total_count
Event.query(nil, obj_id: object.parent[:id], citation_type: "Dataset-Organization").results.total
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# frozen_string_literal: true

class OrganizationPublicationConnectionWithMetaType < BaseConnection
edge_type(EventDataEdgeType, edge_class: EventDataEdge)
field_class GraphQL::Cache::Field

field :total_count, Integer, null: false, cache: true

def total_count
Event.query(nil, obj_id: object.parent[:id], citation_type: "Organization-ScholarlyArticle").results.total
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# frozen_string_literal: true

class OrganizationSoftwareConnectionWithMetaType < BaseConnection
edge_type(EventDataEdgeType, edge_class: EventDataEdge)
field_class GraphQL::Cache::Field

field :total_count, Integer, null: false, cache: true

def total_count
Event.query(nil, obj_id: object.parent[:id], citation_type: "Organization-SoftwareSourceCode").results.total
end
end
35 changes: 35 additions & 0 deletions app/graphql/types/organization_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,39 @@ class OrganizationType < BaseObject
field :fund_ref, [String], null: true, description: "Crossref Funder ID identifiers for organization"
field :wikidata, [String], null: true, description: "Wikidata identifiers for organization"
field :grid, [String], null: true, description: "GRID identifiers for organization"

field :datasets, OrganizationDatasetConnectionWithMetaType, null: false, description: "Funded datasets", connection: true, max_page_size: 100 do
argument :first, Int, required: false, default_value: 25
end

field :publications, OrganizationPublicationConnectionWithMetaType, null: false, description: "Funded publications", connection: true do
argument :query, String, required: false
argument :first, Int, required: false, default_value: 25
end

field :softwares, OrganizationSoftwareConnectionWithMetaType, null: false, description: "Funded software", connection: true, max_page_size: 100 do
argument :first, Int, required: false, default_value: 25
end

def datasets(**args)
ids = Event.query(nil, obj_id: object[:id], citation_type: "Dataset-Organization").results.to_a.map do |e|
doi_from_url(e.subj_id)
end

ElasticsearchLoader.for(Doi).load_many(ids)
end

def publications(**args)
ids = Event.query(nil, obj_id: object[:id], citation_type: "Organization-ScholarlyArticle").results.to_a.map do |e|
doi_from_url(e.subj_id)
end
ElasticsearchLoader.for(Doi).load_many(ids)
end

def softwares(**args)
ids = Event.query(nil, obj_id: object[:id], citation_type: "Organization-SoftwareSourceCode").results.to_a.map do |e|
doi_from_url(e.subj_id)
end
ElasticsearchLoader.for(Doi).load_many(ids)
end
end

0 comments on commit 1c273f6

Please sign in to comment.