-
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 9, 2019
1 parent
ed77c53
commit 20c4131
Showing
8 changed files
with
81 additions
and
14 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,10 @@ | ||
# frozen_string_literal: true | ||
|
||
class BaseConnection < GraphQL::Types::Relay::BaseConnection | ||
def doi_from_url(url) | ||
if /\A(?:(http|https):\/\/(dx\.)?(doi.org|handle.test.datacite.org)\/)?(doi:)?(10\.\d{4,5}\/.+)\z/.match?(url) | ||
uri = Addressable::URI.parse(url) | ||
uri.path.gsub(/^\//, "").downcase | ||
end | ||
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
12 changes: 12 additions & 0 deletions
12
app/graphql/types/dataset_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,12 @@ | ||
# frozen_string_literal: true | ||
|
||
class DatasetDatasetConnectionWithMetaType < BaseConnection | ||
edge_type(EventDataEdgeType, edge_class: EventDataEdge) | ||
field_class GraphQL::Cache::Field | ||
|
||
field :total_count, Integer, null: false, cache: true | ||
|
||
def total_count | ||
Event.query(nil, doi_id: doi_from_url(object.parent.identifier), citation_type: "Dataset-Dataset").results.total | ||
end | ||
end |
12 changes: 12 additions & 0 deletions
12
app/graphql/types/dataset_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,12 @@ | ||
# frozen_string_literal: true | ||
|
||
class DatasetPublicationConnectionWithMetaType < BaseConnection | ||
edge_type(EventDataEdgeType, edge_class: EventDataEdge) | ||
field_class GraphQL::Cache::Field | ||
|
||
field :total_count, Integer, null: false, cache: true | ||
|
||
def total_count | ||
Event.query(nil, doi_id: doi_from_url(object.parent.identifier), citation_type: "Dataset-JournalArticle").results.total | ||
end | ||
end |
12 changes: 12 additions & 0 deletions
12
app/graphql/types/dataset_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,12 @@ | ||
# frozen_string_literal: true | ||
|
||
class DatasetSoftwareConnectionWithMetaType < BaseConnection | ||
edge_type(EventDataEdgeType, edge_class: EventDataEdge) | ||
field_class GraphQL::Cache::Field | ||
|
||
field :total_count, Integer, null: false, cache: true | ||
|
||
def total_count | ||
Event.query(nil, doi_id: doi_from_url(object.parent.identifier), citation_type: "Dataset-SoftwareSourceCode").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
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