Skip to content

Commit

Permalink
explicitly use custom graphql connections. #511
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Fenner committed May 26, 2020
1 parent d03e790 commit 58a3f18
Show file tree
Hide file tree
Showing 13 changed files with 502 additions and 6,044 deletions.
6,063 changes: 255 additions & 5,808 deletions app/graphql/schema.graphql

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions app/graphql/types/data_catalog_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class DataCatalogType < BaseObject
field :download_count, Integer, null: true, description: "The number of downloads according to the Counter Code of Practice."
field :citation_count, Integer, null: true, description: "The number of citations."

field :datasets, DatasetConnectionWithTotalType, null: true, description: "Funded datasets", connection: true do
field :datasets, DatasetConnectionWithTotalType, null: true, description: "Funded datasets" do
argument :query, String, required: false
argument :user_id, String, required: false
argument :repository_id, String, required: false
Expand All @@ -37,8 +37,8 @@ class DataCatalogType < BaseObject
argument :has_versions, Int, required: false
argument :has_views, Int, required: false
argument :has_downloads, Int, required: false
argument :first, Int, required: false, default_value: 25, as: :size
argument :after, String, required: false, as: :cursor
argument :first, Int, required: false, default_value: 25
argument :after, String, required: false
end

def identifier
Expand Down
46 changes: 23 additions & 23 deletions app/graphql/types/doi_item.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ module DoiItem
field :views_over_time, [YearMonthTotalType], null: true, description: "Views by month"
field :downloads_over_time, [YearMonthTotalType], null: true, description: "Downloads by month"

field :references, WorkConnectionWithTotalType, null: true, connection: true, max_page_size: 100, description: "References for this DOI" do
field :references, WorkConnectionWithTotalType, null: true, max_page_size: 100, description: "References for this DOI" do
argument :query, String, required: false
argument :ids, [String], required: false
argument :user_id, String, required: false
Expand All @@ -72,7 +72,7 @@ module DoiItem
argument :after, String, required: false
end

field :citations, WorkConnectionWithTotalType, null: true, connection: true, max_page_size: 100, description: "Citations for this DOI." do
field :citations, WorkConnectionWithTotalType, null: true, max_page_size: 100, description: "Citations for this DOI." do
argument :query, String, required: false
argument :ids, [String], required: false
argument :user_id, String, required: false
Expand All @@ -88,11 +88,11 @@ module DoiItem
argument :has_versions, Int, required: false
argument :has_views, Int, required: false
argument :has_downloads, Int, required: false
argument :first, Int, required: false, default_value: 25, as: :size
argument :after, String, required: false, as: :cursor
argument :first, Int, required: false, default_value: 25
argument :after, String, required: false
end

field :parts, WorkConnectionWithTotalType, null: true, connection: true, max_page_size: 100, description: "Parts of this DOI." do
field :parts, WorkConnectionWithTotalType, null: true, max_page_size: 100, description: "Parts of this DOI." do
argument :query, String, required: false
argument :ids, [String], required: false
argument :user_id, String, required: false
Expand All @@ -108,11 +108,11 @@ module DoiItem
argument :has_versions, Int, required: false
argument :has_views, Int, required: false
argument :has_downloads, Int, required: false
argument :first, Int, required: false, default_value: 25, as: :size
argument :after, String, required: false, as: :cursor
argument :first, Int, required: false, default_value: 25
argument :after, String, required: false
end

field :part_of, WorkConnectionWithTotalType, null: true, connection: true, max_page_size: 100, description: "The DOI is a part of this DOI." do
field :part_of, WorkConnectionWithTotalType, null: true, max_page_size: 100, description: "The DOI is a part of this DOI." do
argument :query, String, required: false
argument :ids, [String], required: false
argument :user_id, String, required: false
Expand All @@ -128,11 +128,11 @@ module DoiItem
argument :has_versions, Int, required: false
argument :has_views, Int, required: false
argument :has_downloads, Int, required: false
argument :first, Int, required: false, default_value: 25, as: :size
argument :after, String, required: false, as: :cursor
argument :first, Int, required: false, default_value: 25
argument :after, String, required: false
end

field :versions, WorkConnectionWithTotalType, null: true, connection: true, max_page_size: 100, description: "Versions of this DOI." do
field :versions, WorkConnectionWithTotalType, null: true, max_page_size: 100, description: "Versions of this DOI." do
argument :query, String, required: false
argument :ids, [String], required: false
argument :user_id, String, required: false
Expand All @@ -148,11 +148,11 @@ module DoiItem
argument :has_versions, Int, required: false
argument :has_views, Int, required: false
argument :has_downloads, Int, required: false
argument :first, Int, required: false, default_value: 25, as: :size
argument :after, String, required: false, as: :cursor
argument :first, Int, required: false, default_value: 25
argument :after, String, required: false
end

field :version_of, WorkConnectionWithTotalType, null: true, connection: true, max_page_size: 100, description: "The DOI is a version of this DOI." do
field :version_of, WorkConnectionWithTotalType, null: true, max_page_size: 100, description: "The DOI is a version of this DOI." do
argument :query, String, required: false
argument :ids, [String], required: false
argument :user_id, String, required: false
Expand All @@ -168,8 +168,8 @@ module DoiItem
argument :has_versions, Int, required: false
argument :has_views, Int, required: false
argument :has_downloads, Int, required: false
argument :first, Int, required: false, default_value: 25, as: :size
argument :after, String, required: false, as: :cursor
argument :first, Int, required: false, default_value: 25
argument :after, String, required: false
end

def type
Expand Down Expand Up @@ -235,39 +235,39 @@ def formatted_citation(style: nil, locale: nil)

def references(**args)
args[:ids] = object.reference_ids
response(args)
ElasticsearchModelResponseConnection.new(response(args), context: self.context, first: args[:first], after: args[:after])
end

def citations(**args)
args[:ids] = object.citation_ids
response(args)
ElasticsearchModelResponseConnection.new(response(args), context: self.context, first: args[:first], after: args[:after])
end

def parts(**args)
args[:ids] = object.part_ids
response(args)
ElasticsearchModelResponseConnection.new(response(args), context: self.context, first: args[:first], after: args[:after])
end

def part_of(**args)
args[:ids] = object.part_of_ids
response(args)
ElasticsearchModelResponseConnection.new(response(args), context: self.context, first: args[:first], after: args[:after])
end

def versions(**args)
args[:ids] = object.version_ids
response(args)
ElasticsearchModelResponseConnection.new(response(args), context: self.context, first: args[:first], after: args[:after])
end

def version_of(**args)
args[:ids] = object.version_of_ids
response(args)
ElasticsearchModelResponseConnection.new(response(args), context: self.context, first: args[:first], after: args[:after])
end

def response(**args)
# make sure no dois are returnded if there are no :ids
args[:ids] = "999" if args[:ids].blank?

Doi.query(args[:query], ids: args[:ids], funder_id: args[:funder_id], user_id: args[:user_id], client_id: args[:repository_id], provider_id: args[:member_id], affiliation_id: args[:affiliation_id], has_person: args[:has_person], has_funder: args[:has_funder], has_organization: args[:has_organization], has_citations: args[:has_citations], has_parts: args[:has_parts], has_versions: args[:has_versions], has_views: args[:has_views], has_downloads: args[:has_downloads], state: "findable", page: { cursor: args[:cursor].present? ? Base64.urlsafe_decode64(args[:cursor]) : nil, size: args[:size] })
Doi.query(args[:query], ids: args[:ids], funder_id: args[:funder_id], user_id: args[:user_id], client_id: args[:repository_id], provider_id: args[:member_id], affiliation_id: args[:affiliation_id], has_person: args[:has_person], has_funder: args[:has_funder], has_organization: args[:has_organization], has_citations: args[:has_citations], has_parts: args[:has_parts], has_versions: args[:has_versions], has_views: args[:has_views], has_downloads: args[:has_downloads], state: "findable", page: { cursor: args[:after].present? ? Base64.urlsafe_decode64(args[:after]) : nil, size: args[:first] })
end

def doi_link(url)
Expand Down
34 changes: 17 additions & 17 deletions app/graphql/types/funder_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class FunderType < BaseObject
field :download_count, Integer, null: true, description: "The number of downloads according to the Counter Code of Practice."
field :citation_count, Integer, null: true, description: "The number of citations."

field :datasets, DatasetConnectionWithTotalType, null: true, description: "Funded datasets", connection: true do
field :datasets, DatasetConnectionWithTotalType, null: true, description: "Funded datasets" do
argument :query, String, required: false
argument :ids, [String], required: false
argument :user_id, String, required: false
Expand All @@ -23,11 +23,11 @@ class FunderType < BaseObject
argument :has_versions, Int, required: false
argument :has_views, Int, required: false
argument :has_downloads, Int, required: false
argument :first, Int, required: false, default_value: 25, as: :size
argument :after, String, required: false, as: :cursor
argument :first, Int, required: false, default_value: 25
argument :after, String, required: false
end

field :publications, PublicationConnectionWithTotalType, null: true, description: "Funded publications", connection: true do
field :publications, PublicationConnectionWithTotalType, null: true, description: "Funded publications" do
argument :query, String, required: false
argument :ids, [String], required: false
argument :user_id, String, required: false
Expand All @@ -40,11 +40,11 @@ class FunderType < BaseObject
argument :has_versions, Int, required: false
argument :has_views, Int, required: false
argument :has_downloads, Int, required: false
argument :first, Int, required: false, default_value: 25, as: :size
argument :after, String, required: false, as: :cursor
argument :first, Int, required: false, default_value: 25
argument :after, String, required: false
end

field :softwares, SoftwareConnectionWithTotalType, null: true, description: "Funded software", connection: true do
field :softwares, SoftwareConnectionWithTotalType, null: true, description: "Funded software" do
argument :query, String, required: false
argument :ids, [String], required: false
argument :user_id, String, required: false
Expand All @@ -57,11 +57,11 @@ class FunderType < BaseObject
argument :has_versions, Int, required: false
argument :has_views, Int, required: false
argument :has_downloads, Int, required: false
argument :first, Int, required: false, default_value: 25, as: :size
argument :after, String, required: false, as: :cursor
argument :first, Int, required: false, default_value: 25
argument :after, String, required: false
end

field :works, WorkConnectionWithTotalType, null: true, description: "Funded works", connection: true do
field :works, WorkConnectionWithTotalType, null: true, description: "Funded works" do
argument :query, String, required: false
argument :ids, [String], required: false
argument :user_id, String, required: false
Expand All @@ -76,8 +76,8 @@ class FunderType < BaseObject
argument :has_versions, Int, required: false
argument :has_views, Int, required: false
argument :has_downloads, Int, required: false
argument :first, Int, required: false, default_value: 25, as: :size
argument :after, String, required: false, as: :cursor
argument :first, Int, required: false, default_value: 25
argument :after, String, required: false
end

def address
Expand All @@ -87,21 +87,21 @@ def address

def publications(**args)
args[:resource_type_id] = "Text"
response(args)
ElasticsearchModelResponseConnection.new(response(args), context: self.context, first: args[:first], after: args[:after])
end

def datasets(**args)
args[:resource_type_id] = "Dataset"
response(args)
ElasticsearchModelResponseConnection.new(response(args), context: self.context, first: args[:first], after: args[:after])
end

def softwares(**args)
args[:resource_type_id] = "Software"
response(args)
ElasticsearchModelResponseConnection.new(response(args), context: self.context, first: args[:first], after: args[:after])
end

def works(**args)
response(args)
ElasticsearchModelResponseConnection.new(response(args), context: self.context, first: args[:first], after: args[:after])
end

def view_count
Expand All @@ -123,6 +123,6 @@ def citation_count
end

def response(**args)
Doi.query(args[:query], ids: args[:ids], funder_id: object.id, user_id: args[:user_id], client_id: args[:repository_id], provider_id: args[:member_id], affiliation_id: args[:affiliation_id], resource_type_id: args[:resource_type_id], has_person: args[:has_person], has_organization: args[:has_organization], has_citations: args[:has_citations], has_parts: args[:has_parts], has_versions: args[:has_versions], has_views: args[:has_views], has_downloads: args[:has_downloads], state: "findable", page: { cursor: args[:cursor].present? ? Base64.urlsafe_decode64(args[:cursor]) : nil, size: args[:size] })
Doi.query(args[:query], ids: args[:ids], funder_id: object.id, user_id: args[:user_id], client_id: args[:repository_id], provider_id: args[:member_id], affiliation_id: args[:affiliation_id], resource_type_id: args[:resource_type_id], has_person: args[:has_person], has_organization: args[:has_organization], has_citations: args[:has_citations], has_parts: args[:has_parts], has_versions: args[:has_versions], has_views: args[:has_views], has_downloads: args[:has_downloads], state: "findable", page: { cursor: args[:after].present? ? Base64.urlsafe_decode64(args[:after]) : nil, size: args[:first] })
end
end
34 changes: 17 additions & 17 deletions app/graphql/types/organization_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class OrganizationType < BaseObject
field :download_count, Integer, null: true, description: "The number of downloads according to the Counter Code of Practice."
field :citation_count, Integer, null: true, description: "The number of citations."

field :datasets, DatasetConnectionWithTotalType, null: true, description: "Datasets from this organization", connection: true do
field :datasets, DatasetConnectionWithTotalType, null: true, description: "Datasets from this organization" do
argument :query, String, required: false
argument :ids, [String], required: false
argument :user_id, String, required: false
Expand All @@ -24,11 +24,11 @@ class OrganizationType < BaseObject
argument :has_versions, Int, required: false
argument :has_views, Int, required: false
argument :has_downloads, Int, required: false
argument :first, Int, required: false, default_value: 25, as: :size
argument :after, String, required: false, as: :cursor
argument :first, Int, required: false, default_value: 25
argument :after, String, required: false
end

field :publications, PublicationConnectionWithTotalType, null: true, description: "Publications from this organization", connection: true do
field :publications, PublicationConnectionWithTotalType, null: true, description: "Publications from this organization" do
argument :query, String, required: false
argument :ids, [String], required: false
argument :user_id, String, required: false
Expand All @@ -40,11 +40,11 @@ class OrganizationType < BaseObject
argument :has_versions, Int, required: false
argument :has_views, Int, required: false
argument :has_downloads, Int, required: false
argument :first, Int, required: false, default_value: 25, as: :size
argument :after, String, required: false, as: :cursor
argument :first, Int, required: false, default_value: 25
argument :after, String, required: false
end

field :softwares, SoftwareConnectionWithTotalType, null: true, description: "Software from this organization", connection: true do
field :softwares, SoftwareConnectionWithTotalType, null: true, description: "Software from this organization" do
argument :query, String, required: false
argument :ids, [String], required: false
argument :user_id, String, required: false
Expand All @@ -56,11 +56,11 @@ class OrganizationType < BaseObject
argument :has_versions, Int, required: false
argument :has_views, Int, required: false
argument :has_downloads, Int, required: false
argument :first, Int, required: false, default_value: 25, as: :size
argument :after, String, required: false, as: :cursor
argument :first, Int, required: false, default_value: 25
argument :after, String, required: false
end

field :works, WorkConnectionWithTotalType, null: true, description: "Works from this organization", connection: true do
field :works, WorkConnectionWithTotalType, null: true, description: "Works from this organization" do
argument :query, String, required: false
argument :ids, [String], required: false
argument :user_id, String, required: false
Expand All @@ -72,8 +72,8 @@ class OrganizationType < BaseObject
argument :has_versions, Int, required: false
argument :has_views, Int, required: false
argument :has_downloads, Int, required: false
argument :first, Int, required: false, default_value: 25, as: :size
argument :after, String, required: false, as: :cursor
argument :first, Int, required: false, default_value: 2
argument :after, String, required: false
end

def alternate_name
Expand All @@ -95,21 +95,21 @@ def address

def publications(**args)
args[:resource_type_id] = "Text"
response(args)
ElasticsearchModelResponseConnection.new(response(args), context: self.context, first: args[:first], after: args[:after])
end

def datasets(**args)
args[:resource_type_id] = "Dataset"
response(args)
ElasticsearchModelResponseConnection.new(response(args), context: self.context, first: args[:first], after: args[:after])
end

def softwares(**args)
args[:resource_type_id] = "Software"
response(args)
ElasticsearchModelResponseConnection.new(response(args), context: self.context, first: args[:first], after: args[:after])
end

def works(**args)
response(args)
ElasticsearchModelResponseConnection.new(response(args), context: self.context, first: args[:first], after: args[:after])
end

def view_count
Expand All @@ -131,6 +131,6 @@ def citation_count
end

def response(**args)
Doi.query(args[:query], ids: args[:ids], affiliation_id: object.id, user_id: args[:user_id], client_id: args[:repository_id], provider_id: args[:member_id], funder_id: args[:funder_id], resource_type_id: args[:resource_type_id], has_person: args[:has_person], has_funder: args[:has_funder], has_citations: args[:has_citations], has_parts: args[:has_parts], has_versions: args[:has_versions], has_views: args[:has_views], has_downloads: args[:has_downloads], state: "findable", page: { cursor: args[:cursor].present? ? Base64.urlsafe_decode64(args[:cursor]) : nil, size: args[:size] })
Doi.query(args[:query], ids: args[:ids], affiliation_id: object.id, user_id: args[:user_id], client_id: args[:repository_id], provider_id: args[:member_id], funder_id: args[:funder_id], resource_type_id: args[:resource_type_id], has_person: args[:has_person], has_funder: args[:has_funder], has_citations: args[:has_citations], has_parts: args[:has_parts], has_versions: args[:has_versions], has_views: args[:has_views], has_downloads: args[:has_downloads], state: "findable", page: { cursor: args[:after].present? ? Base64.urlsafe_decode64(args[:after]) : nil, size: args[:first] })
end
end
Loading

0 comments on commit 58a3f18

Please sign in to comment.