Skip to content

Commit

Permalink
tweaks to graphql pagination
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Fenner committed May 26, 2020
1 parent 5a5147a commit 1a6be9c
Show file tree
Hide file tree
Showing 13 changed files with 80 additions and 96 deletions.
42 changes: 10 additions & 32 deletions app/graphql/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -4374,7 +4374,7 @@ type JournalArticleEdge {
}

"""
Information about providers
Information about members
"""
type Member {
"""
Expand All @@ -4383,7 +4383,7 @@ type Member {
citationCount: Int

"""
Country where the provider is located
Country where the provmemberider is located
"""
country: Country

Expand All @@ -4392,10 +4392,6 @@ type Member {
"""
datasets(
affiliationId: String

"""
Returns the elements in the list that come after the specified cursor.
"""
after: String

"""
Expand Down Expand Up @@ -4425,12 +4421,12 @@ type Member {
): DatasetConnectionWithTotal

"""
Description of the provider
Description of the member
"""
description: String

"""
Provider display name
Member display name
"""
displayName: String!

Expand All @@ -4440,7 +4436,7 @@ type Member {
downloadCount: Int

"""
Field of science covered by provider
Field of science covered by member
"""
focusArea: String

Expand All @@ -4450,17 +4446,17 @@ type Member {
id: ID!

"""
Date provider joined DataCite
Date member joined DataCite
"""
joined: ISO8601Date

"""
URL for the provider logo
URL for the member logo
"""
logoUrl: Url

"""
Provider name
Member name
"""
name: String!

Expand All @@ -4473,9 +4469,6 @@ type Member {
Prefixes managed by the member
"""
prefixes(
"""
Returns the elements in the list that come after the specified cursor.
"""
after: String

"""
Expand All @@ -4498,10 +4491,6 @@ type Member {
"""
publications(
affiliationId: String

"""
Returns the elements in the list that come after the specified cursor.
"""
after: String

"""
Expand Down Expand Up @@ -4531,17 +4520,14 @@ type Member {
): PublicationConnectionWithTotal

"""
Geographic region where the provider is located
Geographic region where the member is located
"""
region: String

"""
Repositories associated with the member
"""
repositories(
"""
Returns the elements in the list that come after the specified cursor.
"""
after: String

"""
Expand Down Expand Up @@ -4569,10 +4555,6 @@ type Member {
"""
softwares(
affiliationId: String

"""
Returns the elements in the list that come after the specified cursor.
"""
after: String

"""
Expand Down Expand Up @@ -4612,7 +4594,7 @@ type Member {
viewCount: Int

"""
Website of the provider
Website of the member
"""
website: Url

Expand All @@ -4621,10 +4603,6 @@ type Member {
"""
works(
affiliationId: String

"""
Returns the elements in the list that come after the specified cursor.
"""
after: String

"""
Expand Down
58 changes: 33 additions & 25 deletions app/graphql/types/member_type.rb
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
# frozen_string_literal: true

class MemberType < BaseObject
description "Information about providers"
description "Information about members"

field :id, ID, null: false, hash_key: "uid", description: "Unique identifier for each provider"
field :id, ID, null: false, hash_key: "uid", description: "Unique identifier for the member"
field :type, String, null: false, description: "The type of the item."
field :name, String, null: false, description: "Provider name"
field :displayName, String, null: false, description: "Provider display name"
field :name, String, null: false, description: "Member name"
field :displayName, String, null: false, description: "Member display name"
field :ror_id, ID, null: true, description: "Research Organization Registry (ROR) identifier"
field :description, String, null: true, description: "Description of the provider"
field :website, Url, null: true, description: "Website of the provider"
field :logo_url, Url, null: true, description: "URL for the provider logo"
field :region, String, null: true, description: "Geographic region where the provider is located"
field :country, CountryType, null: true, description: "Country where the provider is located"
field :description, String, null: true, description: "Description of the member"
field :website, Url, null: true, description: "Website of the member"
field :logo_url, Url, null: true, description: "URL for the member logo"
field :region, String, null: true, description: "Geographic region where the member is located"
field :country, CountryType, null: true, description: "Country where the member is located"
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, GraphQL::Types::ISO8601Date, null: true, description: "Date provider joined DataCite"
field :focus_area, String, null: true, description: "Field of science covered by member"
field :joined, GraphQL::Types::ISO8601Date, null: true, description: "Date member joined DataCite"
field :view_count, Integer, null: true, description: "The number of views according to the Counter Code of Practice."
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, connection: true, description: "Datasets by this provider." do
field :datasets, DatasetConnectionWithTotalType, null: true, description: "Datasets by this provider." do
argument :query, String, required: false
argument :ids, String, required: false
argument :user_id, String, required: false
Expand All @@ -37,9 +37,10 @@ class MemberType < BaseObject
argument :has_views, Int, required: false
argument :has_downloads, Int, required: false
argument :first, Int, required: false, default_value: 25
argument :after, String, required: false
end

field :publications, PublicationConnectionWithTotalType, null: true, connection: true, description: "Publications by this provider." do
field :publications, PublicationConnectionWithTotalType, null: true, description: "Publications by this provider." do
argument :query, String, required: false
argument :ids, String, required: false
argument :user_id, String, required: false
Expand All @@ -56,9 +57,10 @@ class MemberType < BaseObject
argument :has_views, Int, required: false
argument :has_downloads, Int, required: false
argument :first, Int, required: false, default_value: 25
argument :after, String, required: false
end

field :softwares, SoftwareConnectionWithTotalType, null: true, connection: true, description: "Software by this provider." do
field :softwares, SoftwareConnectionWithTotalType, null: true, description: "Software by this provider." do
argument :query, String, required: false
argument :ids, [String], required: false
argument :user_id, String, required: false
Expand All @@ -75,9 +77,10 @@ class MemberType < BaseObject
argument :has_views, Int, required: false
argument :has_downloads, Int, required: false
argument :first, Int, required: false, default_value: 25
argument :after, String, required: false
end

field :works, WorkConnectionWithTotalType, null: true, connection: true, description: "Works by this provider." do
field :works, WorkConnectionWithTotalType, null: true, description: "Works by this provider." do
argument :query, String, required: false
argument :ids, [String], required: false
argument :user_id, String, required: false
Expand All @@ -94,24 +97,27 @@ class MemberType < BaseObject
argument :has_views, Int, required: false
argument :has_downloads, Int, required: false
argument :first, Int, required: false, default_value: 25
argument :after, String, required: false
end

field :prefixes, MemberPrefixConnectionWithTotalType, null: true, description: "Prefixes managed by the member", connection: true do
field :prefixes, MemberPrefixConnectionWithTotalType, null: true, description: "Prefixes managed by the member" do
argument :query, String, required: false
argument :state, String, required: false
argument :year, String, required: false
argument :first, Int, required: false, default_value: 25
argument :after, String, required: false
end

field :repositories, RepositoryConnectionWithTotalType, null: true, description: "Repositories associated with the member", connection: true do
field :repositories, RepositoryConnectionWithTotalType, null: true, description: "Repositories associated with the member" do
argument :query, String, required: false
argument :year, String, required: false
argument :software, String, required: false
argument :first, Int, required: false, default_value: 25
argument :after, String, required: false
end

def type
"Provider"
"Member"
end

def country
Expand All @@ -124,29 +130,31 @@ def country

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 prefixes(**args)
ProviderPrefix.query(args[:query], provider_id: object.uid, state: args[:state], year: args[:year], page: { number: 1, size: args[:first] })
response = ProviderPrefix.query(args[:query], provider_id: object.uid, state: args[:state], year: args[:year], page: { cursor: args[:after].present? ? Base64.urlsafe_decode64(args[:after]) : nil, size: args[:first] })
ElasticsearchModelResponseConnection.new(response, context: self.context, first: args[:first], after: args[:after])
end

def repositories(**args)
Client.query(args[:query], provider_id: object.uid, year: args[:year], software: args[:software], page: { number: 1, size: args[:first] })
response = Client.query(args[:query], provider_id: object.uid, year: args[:year], software: args[:software], page: { cursor: args[:after].present? ? Base64.urlsafe_decode64(args[:after]) : nil, size: args[:first] })
ElasticsearchModelResponseConnection.new(response, context: self.context, first: args[:first], after: args[:after])
end

def view_count
Expand All @@ -168,6 +176,6 @@ def citation_count
end

def response(**args)
Doi.query(args[:query], ids: args[:ids], user_id: args[:user_id], client_id: args[:repository_id], provider_id: object.uid, funder_id: args[:funder_id], affiliation_id: args[:affiliation_id], resource_type_id: args[:resource_type_id], has_person: args[:has_person], has_funder: args[:has_funder], has_affiliation: args[:has_affiliation], 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: { number: 1, size: args[:first] })
Doi.query(args[:query], ids: args[:ids], user_id: args[:user_id], client_id: args[:repository_id], provider_id: object.member_type == "consortium" ? nil : object.uid, consortium_id: object.member_type == "consortium" ? object.uid : nil, funder_id: args[:funder_id], affiliation_id: args[:affiliation_id], resource_type_id: args[:resource_type_id], has_person: args[:has_person], has_funder: args[:has_funder], has_affiliation: args[:has_affiliation], 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
2 changes: 1 addition & 1 deletion app/models/person.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def self.query(query, options={})
params = {
q: query || "*",
"rows" => options[:limit],
"start" => options[:offset] }.compact
"start" => options[:offset].to_i * options[:limit].to_i }.compact

url = "https://pub.orcid.org/v3.0/expanded-search/?" + URI.encode_www_form(params)

Expand Down
4 changes: 2 additions & 2 deletions spec/fixtures/vcr_cassettes/Person/find_by_id/also_found.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions spec/fixtures/vcr_cassettes/Person/find_by_id/found.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions spec/fixtures/vcr_cassettes/Person/find_by_id/not_found.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 1a6be9c

Please sign in to comment.