-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Martin Fenner
committed
Jun 16, 2019
1 parent
0902acb
commit 713c0a0
Showing
17 changed files
with
189 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# frozen_string_literal: true | ||
|
||
class ApiType < BaseObject | ||
description "Information" | ||
|
||
field :url, String, null: false, description: "URL" | ||
field :type, String, null: true, description: "Type" | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# frozen_string_literal: true | ||
|
||
class NameType < BaseObject | ||
description "Information" | ||
|
||
field :name, String, null: false, description: "Information" | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# frozen_string_literal: true | ||
|
||
class RepositoryConnectionWithMetaType < BaseConnection | ||
edge_type(RepositoryEdgeType) | ||
field_class GraphQL::Cache::Field | ||
|
||
field :total_count, Integer, null: false, cache: true | ||
|
||
def total_count | ||
args = object.arguments | ||
|
||
Repository.query(args[:query], limit: 0).dig(:meta, "total").to_i | ||
end | ||
end |
14 changes: 14 additions & 0 deletions
14
app/graphql/types/repository_dataset_connection_with_meta_type.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# frozen_string_literal: true | ||
|
||
class RepositoryDatasetConnectionWithMetaType < BaseConnection | ||
edge_type(DatasetEdgeType) | ||
field_class GraphQL::Cache::Field | ||
|
||
field :total_count, Integer, null: false, cache: true | ||
|
||
def total_count | ||
args = object.arguments | ||
|
||
Doi.query(args[:query], repository_id: doi_from_url(object.parent[:id]), resource_type_id: "Dataset", state: "findable", page: { number: 1, size: args[:first] }).results.total | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# frozen_string_literal: true | ||
|
||
class RepositoryEdgeType < GraphQL::Types::Relay::BaseEdge | ||
node_type(RepositoryType) | ||
end |
14 changes: 14 additions & 0 deletions
14
app/graphql/types/repository_publication_connection_with_meta_type.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# frozen_string_literal: true | ||
|
||
class RepositoryPublicationConnectionWithMetaType < BaseConnection | ||
edge_type(DatasetEdgeType) | ||
field_class GraphQL::Cache::Field | ||
|
||
field :total_count, Integer, null: false, cache: true | ||
|
||
def total_count | ||
args = object.arguments | ||
|
||
Doi.query(args[:query], repository_id: doi_from_url(object.parent[:id]), resource_type_id: "Text", state: "findable", page: { number: 1, size: args[:first] }).results.total | ||
end | ||
end |
14 changes: 14 additions & 0 deletions
14
app/graphql/types/repository_software_connection_with_meta_type.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# frozen_string_literal: true | ||
|
||
class RepositorySoftwareConnectionWithMetaType < BaseConnection | ||
edge_type(DatasetEdgeType) | ||
field_class GraphQL::Cache::Field | ||
|
||
field :total_count, Integer, null: false, cache: true | ||
|
||
def total_count | ||
args = object.arguments | ||
|
||
Doi.query(args[:query], repository_id: doi_from_url(object.parent[:id]), resource_type_id: "Software", state: "findable", page: { number: 1, size: args[:first] }).results.total | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
# frozen_string_literal: true | ||
|
||
class RepositoryType < BaseObject | ||
description "Information about repository" | ||
|
||
field :id, ID, null: false, description: "Repository ID" | ||
field :re3data_id, String, null: false, description: "re3data ID" | ||
field :name, String, null: false, description: "Repository name" | ||
field :additional_names, [TextLanguageType], null: false, description: "Additional repository names" | ||
field :url, String, null: true, description: "Repository URL" | ||
field :contacts, [TextType], null: true, description: "Repository contact information" | ||
field :description, String, null: true, description: "Repository description" | ||
field :certificates, [TextType], null: true, description: "Repository certificates" | ||
field :subjects, [SchemeType], null: true, description: "Subjects" | ||
field :content_types, [SchemeType], null: true, description: "Content types" | ||
field :provider_types, [TextType], null: true, description: "Provider types" | ||
field :keywords, [TextType], null: true, description: "Keywords" | ||
field :data_accesses, [TextRestrictionType], null: true, description: "Data accesses" | ||
field :data_uploads, [TextRestrictionType], null: true, description: "Data uploads" | ||
field :pid_systems, [TextType], null: true, description: "PID Systems" | ||
field :apis, [ApiType], null: true, description: "APIs" | ||
field :software, [NameType], null: true, description: "Software" | ||
|
||
field :datasets, RepositoryDatasetConnectionWithMetaType, null: false, connection: true, max_page_size: 100, description: "Datasets hosted by the repository" do | ||
argument :query, String, required: false | ||
argument :first, Int, required: false, default_value: 25 | ||
end | ||
|
||
field :publications, RepositoryPublicationConnectionWithMetaType, null: false, connection: true, max_page_size: 100, description: "Publications hosted by the repository" do | ||
argument :query, String, required: false | ||
argument :first, Int, required: false, default_value: 25 | ||
end | ||
|
||
field :softwares, RepositorySoftwareConnectionWithMetaType, null: false, connection: true, max_page_size: 100, description: "Software hosted by the repository" do | ||
argument :query, String, required: false | ||
argument :first, Int, required: false, default_value: 25 | ||
end | ||
|
||
def datasets(**args) | ||
logger = Logger.new(STDOUT) | ||
logger.info doi_from_url(object[:id]) | ||
Doi.query(args[:query], repository_id: doi_from_url(object[:id]), resource_type_id: "Dataset", page: { number: 1, size: args[:first] }).results.to_a | ||
end | ||
|
||
def publications(**args) | ||
Doi.query(args[:query], repository_id: doi_from_url(object[:id]), resource_type_id: "Text", page: { number: 1, size: args[:first] }).results.to_a | ||
end | ||
|
||
def softwares(**args) | ||
Doi.query(args[:query], repository_id: doi_from_url(object[:id]), resource_type_id: "Software", page: { number: 1, size: args[:first] }).results.to_a | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# frozen_string_literal: true | ||
|
||
class SchemeType < BaseObject | ||
description "Information" | ||
|
||
field :scheme, String, null: false, description: "Schema" | ||
field :text, String, null: false, description: "Information" | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# frozen_string_literal: true | ||
|
||
class TextLanguageType < BaseObject | ||
description "Information" | ||
|
||
field :language, String, null: true, description: "Language" | ||
field :text, String, null: false, description: "Information" | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# frozen_string_literal: true | ||
|
||
class TextRestrictionType < BaseObject | ||
description "Information" | ||
|
||
field :text, String, null: false, description: "Information" | ||
field :restriction, [TextType], null: true, description: "Restriction" | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# frozen_string_literal: true | ||
|
||
class TextType < BaseObject | ||
description "Information" | ||
|
||
field :text, String, null: false, description: "Information" | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters