Skip to content

Commit

Permalink
fix graphql pagination. #370
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Fenner committed Dec 6, 2019
1 parent 336afdc commit eff4ebc
Show file tree
Hide file tree
Showing 23 changed files with 52 additions and 53 deletions.
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ gem 'oj_mimic_json', '~> 1.0', '>= 1.0.1'
gem 'turnout', '~> 2.5'
gem 'audited', '~> 4.8'
gem 'git', '~> 1.5'
gem 'graphql', '~> 1.9', '>= 1.9.15'
gem 'graphql', '~> 1.9', '>= 1.9.15', git: "https://github.com/rmosolgo/graphql-ruby"
gem 'graphql-errors', '~> 0.4.0'
gem 'graphql-batch', '~> 0.4.1'
gem 'batch-loader', '~> 1.4', '>= 1.4.1'
Expand Down
23 changes: 14 additions & 9 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
GIT
remote: https://github.com/rmosolgo/graphql-ruby
revision: 9859534ccbc4fe91ab26b58e7ea9d0e12a47d409
specs:
graphql (1.9.16)

GIT
remote: https://github.com/stackshareio/graphql-cache
revision: 5a6fa5a3316cd267d0829815b122e1e159321e17
Expand Down Expand Up @@ -67,17 +73,17 @@ GEM
audited (4.9.0)
activerecord (>= 4.2, < 6.1)
aws-eventstream (1.0.3)
aws-partitions (1.246.0)
aws-sdk-core (3.82.0)
aws-partitions (1.251.0)
aws-sdk-core (3.84.0)
aws-eventstream (~> 1.0, >= 1.0.2)
aws-partitions (~> 1, >= 1.239.0)
aws-sigv4 (~> 1.1)
jmespath (~> 1.0)
aws-sdk-kms (1.26.0)
aws-sdk-core (~> 3, >= 3.71.0)
aws-sigv4 (~> 1.1)
aws-sdk-s3 (1.57.0)
aws-sdk-core (~> 3, >= 3.77.0)
aws-sdk-s3 (1.59.0)
aws-sdk-core (~> 3, >= 3.83.0)
aws-sdk-kms (~> 1)
aws-sigv4 (~> 1.1)
aws-sdk-sqs (1.23.1)
Expand Down Expand Up @@ -174,7 +180,7 @@ GEM
namae (~> 1.0)
csl-styles (1.0.1.9)
csl (~> 1.0)
css_parser (1.7.0)
css_parser (1.7.1)
addressable
dalli (2.7.10)
database_cleaner (1.7.0)
Expand Down Expand Up @@ -241,7 +247,6 @@ GEM
globalid (0.4.2)
activesupport (>= 4.2.0)
google-protobuf (3.10.0.rc.1)
graphql (1.9.15)
graphql-batch (0.4.1)
graphql (>= 1.3, < 2)
promise.rb (~> 0.7.2)
Expand Down Expand Up @@ -331,7 +336,7 @@ GEM
mini_mime (1.0.2)
mini_portile2 (2.4.0)
minitest (5.13.0)
money (6.13.4)
money (6.13.6)
i18n (>= 0.6.4, <= 2)
msgpack (1.3.1)
multi_json (1.14.1)
Expand All @@ -340,7 +345,7 @@ GEM
namae (1.0.1)
netrc (0.11.0)
nio4r (2.5.2)
nokogiri (1.10.5)
nokogiri (1.10.7)
mini_portile2 (~> 2.4.0)
oj (2.18.5)
oj_mimic_json (1.0.1)
Expand Down Expand Up @@ -576,7 +581,7 @@ DEPENDENCIES
gender_detector (~> 0.1.2)
git (~> 1.5)
google-protobuf (= 3.10.0.rc.1)
graphql (~> 1.9, >= 1.9.15)
graphql (~> 1.9, >= 1.9.15)!
graphql-batch (~> 0.4.1)
graphql-cache (~> 0.6.0)!
graphql-errors (~> 0.4.0)
Expand Down
6 changes: 0 additions & 6 deletions app/controllers/concerns/facetable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,6 @@ module Facetable
}

included do

REGIONS = {
"amer" => "Americas",
"apac" => "Asia Pacific",
"emea" => "EMEA" }

def facet_by_year(arr)
arr.map do |hsh|
{ "id" => hsh["key_as_string"][0..3],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ class ClientDatasetConnectionWithMetaType < BaseConnection
def total_count
args = object.arguments

Doi.query(args[:query], client_id: object.parent.uid, resource_type_id: "Dataset", state: "findable", page: { number: 1, size: args[:first] }).results.total
Doi.query(args[:query], client_id: object.parent.uid, resource_type_id: "Dataset", state: "findable", page: { number: 1, size: 0 }).results.total
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ class ClientPublicationConnectionWithMetaType < BaseConnection
def total_count
args = object.arguments

Doi.query(args[:query], client_id: object.parent.uid, resource_type_id: "Text", state: "findable", page: { number: 1, size: args[:first] }).results.total
Doi.query(args[:query], client_id: object.parent.uid, resource_type_id: "Text", state: "findable", page: { number: 1, size: 0 }).results.total
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ class ClientSoftwareConnectionWithMetaType < BaseConnection
def total_count
args = object.arguments

Doi.query(args[:query], client_id: object.parent.uid, resource_type_id: "Software", state: "findable", page: { number: 1, size: args[:first] }).results.total
Doi.query(args[:query], client_id: object.parent.uid, resource_type_id: "Software", state: "findable", page: { number: 1, size: 0 }).results.total
end
end
8 changes: 4 additions & 4 deletions app/graphql/types/client_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,23 @@ class ClientType < BaseObject
field :url, String, null: true, description: "The homepage of the client"
field :system_email, String, null: true, description: "Client system email"
field :software, String, null: true, description: "The name of the software that is used to run the repository"
field :prefixes, PrefixConnectionWithMetaType, null: false, description: "Prefixes managed by the client", connection: true, max_page_size: 1000 do
field :prefixes, PrefixConnectionWithMetaType, null: false, description: "Prefixes managed by the client", connection: true do
argument :query, String, required: false
argument :year, String, required: false
argument :first, Int, required: false, default_value: 25
end

field :datasets, ClientDatasetConnectionWithMetaType, null: false, connection: true, max_page_size: 1000, description: "Datasets managed by the client" do
field :datasets, ClientDatasetConnectionWithMetaType, null: false, connection: true, description: "Datasets managed by the client" do
argument :query, String, required: false
argument :first, Int, required: false, default_value: 25
end

field :publications, ClientPublicationConnectionWithMetaType, null: false, connection: true, max_page_size: 1000, description: "Publications managed by the client" do
field :publications, ClientPublicationConnectionWithMetaType, null: false, connection: true, description: "Publications managed by the client" do
argument :query, String, required: false
argument :first, Int, required: false, default_value: 25
end

field :software_source_codes, ClientSoftwareConnectionWithMetaType, null: false, connection: true, max_page_size: 1000, description: "Software managed by the client" do
field :software_source_codes, ClientSoftwareConnectionWithMetaType, null: false, connection: true, description: "Software managed by the client" do
argument :query, String, required: false
argument :first, Int, required: false, default_value: 25
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ class CreativeWorkConnectionWithMetaType < BaseConnection
def total_count
args = object.arguments

Doi.query(args[:query], client_id: args[:client_id], provider_id: args[:provider_id], state: "findable", page: { number: 1, size: args[:first] }).results.total
Doi.query(args[:query], client_id: args[:client_id], provider_id: args[:provider_id], state: "findable", page: { number: 1, size: 0 }).results.total
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ class DataCatalogDatasetConnectionWithMetaType < BaseConnection
def total_count
args = object.arguments

Doi.query(args[:query], re3data_id: doi_from_url(object.parent[:id]), resource_type_id: "Dataset", state: "findable", page: { number: 1, size: args[:first] }).results.total
Doi.query(args[:query], re3data_id: doi_from_url(object.parent[:id]), resource_type_id: "Dataset", state: "findable", page: { number: 1, size: 0 }).results.total
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ class DataCatalogPublicationConnectionWithMetaType < BaseConnection
def total_count
args = object.arguments

Doi.query(args[:query], re3data_id: doi_from_url(object.parent[:id]), resource_type_id: "Text", state: "findable", page: { number: 1, size: args[:first] }).results.total
Doi.query(args[:query], re3data_id: doi_from_url(object.parent[:id]), resource_type_id: "Text", state: "findable", page: { number: 1, size: 0 }).results.total
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ class DataCatalogSoftwareConnectionWithMetaType < BaseConnection
def total_count
args = object.arguments

Doi.query(args[:query], re3data_id: doi_from_url(object.parent[:id]), resource_type_id: "Software", state: "findable", page: { number: 1, size: args[:first] }).results.total
Doi.query(args[:query], re3data_id: doi_from_url(object.parent[:id]), resource_type_id: "Software", state: "findable", page: { number: 1, size: 0 }).results.total
end
end
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 @@ -23,17 +23,17 @@ class DataCatalogType < BaseObject
# field :pid_systems, [String], null: true, description: "PID Systems"
# field :apis, [ApiType], null: true, description: "APIs"
field :software_application, [SoftwareApplicationType], null: true, description: "Software"
field :datasets, DataCatalogDatasetConnectionWithMetaType, null: false, connection: true, max_page_size: 1000, description: "Datasets hosted by the repository" do
field :datasets, DataCatalogDatasetConnectionWithMetaType, null: false, connection: true, description: "Datasets hosted by the repository" do
argument :query, String, required: false
argument :first, Int, required: false, default_value: 25
end

field :publications, DataCatalogPublicationConnectionWithMetaType, null: false, connection: true, max_page_size: 1000, description: "Publications hosted by the repository" do
field :publications, DataCatalogPublicationConnectionWithMetaType, null: false, connection: true, description: "Publications hosted by the repository" do
argument :query, String, required: false
argument :first, Int, required: false, default_value: 25
end

field :software_source_codes, DataCatalogSoftwareConnectionWithMetaType, null: false, connection: true, max_page_size: 1000, description: "Software hosted by the repository" do
field :software_source_codes, DataCatalogSoftwareConnectionWithMetaType, null: false, connection: true, description: "Software hosted by the repository" do
argument :query, String, required: false
argument :first, Int, required: false, default_value: 25
end
Expand Down
2 changes: 1 addition & 1 deletion app/graphql/types/dataset_connection_with_meta_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class DatasetConnectionWithMetaType < BaseConnection
def total_count
args = object.arguments

Doi.query(args[:query], client_id: args[:clent_id], provider_id: args[:provider_id], resource_type_id: "Dataset", state: "findable", page: { number: 1, size: args[:first] }).results.total
Doi.query(args[:query], client_id: args[:client_id], provider_id: args[:provider_id], resource_type_id: "Dataset", state: "findable", page: { number: 1, size: 0 }).results.total
end

def dataset_connection_count
Expand Down
6 changes: 3 additions & 3 deletions app/graphql/types/dataset_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@ class DatasetType < BaseObject
implements DoiItem
implements MetricInterface

field :usage_reports, DatasetUsageReportConnectionWithMetaType, null: false, description: "Usage reports for this dataset", connection: true, max_page_size: 1000 do
field :usage_reports, DatasetUsageReportConnectionWithMetaType, null: false, description: "Usage reports for this dataset", connection: true do
argument :first, Int, required: false, default_value: 25
end
field :datasets, DatasetDatasetConnectionWithMetaType, null: false, description: "Referenced datasets", connection: true, max_page_size: 1000 do
field :datasets, DatasetDatasetConnectionWithMetaType, null: false, description: "Referenced datasets", connection: true do
argument :first, Int, required: false, default_value: 25
end
field :publications, DatasetPublicationConnectionWithMetaType, null: false, description: "Referenced publications", connection: true do
argument :query, String, required: false
argument :first, Int, required: false, default_value: 25
end
field :software_source_codes, DatasetSoftwareConnectionWithMetaType, null: false, description: "Referenced software", connection: true, max_page_size: 1000 do
field :software_source_codes, DatasetSoftwareConnectionWithMetaType, null: false, description: "Referenced software", connection: true do
argument :first, Int, required: false, default_value: 25
end

Expand Down
4 changes: 2 additions & 2 deletions app/graphql/types/funder_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class FunderType < BaseObject
field :name, String, null: false, description: "The name of the funder."
field :alternate_name, [String], null: true, description: "An alias for the funder."
field :address, AddressType, null: true, description: "Physical address of the funder."
field :datasets, FunderDatasetConnectionWithMetaType, null: false, description: "Funded datasets", connection: true, max_page_size: 1000 do
field :datasets, FunderDatasetConnectionWithMetaType, null: false, description: "Funded datasets", connection: true do
argument :first, Int, required: false, default_value: 25
end

Expand All @@ -17,7 +17,7 @@ class FunderType < BaseObject
argument :first, Int, required: false, default_value: 25
end

field :software_source_codes, FunderSoftwareConnectionWithMetaType, null: false, description: "Funded software", connection: true, max_page_size: 1000 do
field :software_source_codes, FunderSoftwareConnectionWithMetaType, null: false, description: "Funded software", connection: true do
argument :first, Int, required: false, default_value: 25
end

Expand Down
8 changes: 4 additions & 4 deletions app/graphql/types/organization_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,20 @@ class OrganizationType < BaseObject
field :url, [String], null: true, hash_key: "links", description: "URL of the organization."
field :address, AddressType, null: true, description: "Physical address of the organization."

field :datasets, OrganizationDatasetConnectionWithMetaType, null: false, description: "Datasets from this organization", connection: true, max_page_size: 1000 do
field :datasets, OrganizationDatasetConnectionWithMetaType, null: false, description: "Datasets from this organization", connection: true do
argument :first, Int, required: false, default_value: 25
end

field :publications, OrganizationPublicationConnectionWithMetaType, null: false, description: "Publications from this organization", connection: true, max_page_size: 1000 do
field :publications, OrganizationPublicationConnectionWithMetaType, null: false, description: "Publications from this organization", connection: true do
argument :query, String, required: false
argument :first, Int, required: false, default_value: 25
end

field :software_source_codes, OrganizationSoftwareConnectionWithMetaType, null: false, description: "Software from this organization", connection: true, max_page_size: 1000 do
field :software_source_codes, OrganizationSoftwareConnectionWithMetaType, null: false, description: "Software from this organization", connection: true do
argument :first, Int, required: false, default_value: 25
end

# field :researchers, OrganizationResearcherConnectionWithMetaType, null: false, description: "Researchers associated with this organization", connection: true, max_page_size: 1000 do
# field :researchers, OrganizationResearcherConnectionWithMetaType, null: false, description: "Researchers associated with this organization", connection: true do
# argument :first, Int, required: false, default_value: 25
# end

Expand Down
6 changes: 3 additions & 3 deletions app/graphql/types/person_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ class PersonType < BaseObject
field :given_name, String, null: true, hash_key: "given_names", description: "Given name. In the U.S., the first name of a Person."
field :family_name, String, null: true, description: "Family name. In the U.S., the last name of an Person."

field :datasets, PersonDatasetConnectionWithMetaType, null: true, description: "Authored datasets", connection: true, max_page_size: 1000 do
field :datasets, PersonDatasetConnectionWithMetaType, null: true, description: "Authored datasets", connection: true do
argument :first, Int, required: false, default_value: 25
end

field :publications, PersonPublicationConnectionWithMetaType, null: true, description: "Authored publications", connection: true, max_page_size: 1000 do
field :publications, PersonPublicationConnectionWithMetaType, null: true, description: "Authored publications", connection: true do
argument :first, Int, required: false, default_value: 25
end

field :software_source_codes, PersonSoftwareConnectionWithMetaType, null: true, description: "Authored software", connection: true, max_page_size: 1000 do
field :software_source_codes, PersonSoftwareConnectionWithMetaType, null: true, description: "Authored software", connection: true do
argument :first, Int, required: false, default_value: 25
end

Expand Down
4 changes: 2 additions & 2 deletions app/graphql/types/provider_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ class ProviderType < BaseObject
field :organization_type, String, null: true, description: "Type of organization"
field :focus_area, String, null: true, description: "Field of science covered by provider"
field :joined, String, null: true, description: "Date provider joined DataCite"
field :prefixes, PrefixConnectionWithMetaType, null: false, description: "Prefixes managed by the provider", connection: true, max_page_size: 1000 do
field :prefixes, PrefixConnectionWithMetaType, null: false, description: "Prefixes managed by the provider", connection: true do
argument :query, String, required: false
argument :state, String, required: false
argument :year, String, required: false
argument :first, Int, required: false, default_value: 25
end

field :clients, ClientConnectionWithMetaType, null: false, description: "Clients associated with the provider", connection: true, max_page_size: 1000 do
field :clients, ClientConnectionWithMetaType, null: false, description: "Clients associated with the provider", connection: true do
argument :query, String, required: false
argument :year, String, required: false
argument :software, String, required: false
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 @@ -15,7 +15,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: args[:first] }).results.total
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

def publication_connection_count
Expand Down
4 changes: 2 additions & 2 deletions app/graphql/types/publication_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ class PublicationType < BaseObject
implements DoiItem
implements MetricInterface

field :datasets, PublicationDatasetConnectionWithMetaType, null: false, description: "Referenced datasets", connection: true, max_page_size: 1000 do
field :datasets, PublicationDatasetConnectionWithMetaType, null: false, description: "Referenced datasets", connection: true do
argument :first, Int, required: false, default_value: 25
end
field :publications, PublicationPublicationConnectionWithMetaType, null: false, description: "Referenced publications", connection: true do
argument :query, String, required: false
argument :first, Int, required: false, default_value: 25
end
field :software_source_codes, PublicationSoftwareConnectionWithMetaType, null: false, description: "Referenced software", connection: true, max_page_size: 1000 do
field :software_source_codes, PublicationSoftwareConnectionWithMetaType, null: false, description: "Referenced software", connection: true do
argument :first, Int, required: false, default_value: 25
end

Expand Down
2 changes: 1 addition & 1 deletion app/graphql/types/software_connection_with_meta_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class SoftwareConnectionWithMetaType < BaseConnection
def total_count
args = object.arguments

Doi.query(args[:query], client_id: args[:client_id], provider_id: args[:provider_id], resource_type_id: "Software", state: "findable", page: { number: 1, size: args[:first] }).results.total
Doi.query(args[:query], client_id: args[:client_id], provider_id: args[:provider_id], resource_type_id: "Software", state: "findable", page: { number: 1, size: 0 }).results.total
end

def software_connection_count
Expand Down
Loading

0 comments on commit eff4ebc

Please sign in to comment.