Skip to content

Commit

Permalink
use connections with datasets for clients. #257
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Fenner committed May 13, 2019
1 parent cf9e602 commit c3d89c4
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 2 deletions.
13 changes: 13 additions & 0 deletions app/graphql/types/client_dataset_connection_with_meta_type.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# frozen_string_literal: true

class ClientDatasetConnectionWithMetaType < GraphQL::Types::Relay::BaseConnection
edge_type(DatasetEdgeType)

field :total_count, Integer, null: false

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
end
end
13 changes: 13 additions & 0 deletions app/graphql/types/client_publication_connection_with_meta_type.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# frozen_string_literal: true

class ClientPublicationConnectionWithMetaType < GraphQL::Types::Relay::BaseConnection
edge_type(DatasetEdgeType)

field :total_count, Integer, null: false

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
end
end
13 changes: 13 additions & 0 deletions app/graphql/types/client_software_connection_with_meta_type.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# frozen_string_literal: true

class ClientSoftwareConnectionWithMetaType < GraphQL::Types::Relay::BaseConnection
edge_type(DatasetEdgeType)

field :total_count, Integer, null: false

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
end
end
13 changes: 11 additions & 2 deletions app/graphql/types/client_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,17 @@ class ClientType < GraphQL::Schema::Object
argument :first, Int, required: false, default_value: 25
end

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

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

field :publications, ClientSoftwareConnectionWithMetaType, null: false, connection: true, max_page_size: 100, null: false, description: "Software managed by the client" do
argument :query, String, required: false
argument :first, Int, required: false, default_value: 25
end
Expand All @@ -41,4 +46,8 @@ def datasets(**args)
def publications(**args)
Doi.query(args[:query], client_id: object.uid, resource_type_id: "Text", page: { number: 1, size: args[:first] }).records.to_a
end

def softwares(**args)
Doi.query(args[:query], client_id: object.uid, resource_type_id: "Software", page: { number: 1, size: args[:first] }).records.to_a
end
end

0 comments on commit c3d89c4

Please sign in to comment.