Skip to content

Commit

Permalink
Merge pull request #620 from datacite/add-unpaywall
Browse files Browse the repository at this point in the history
Add contentUrl to GraphQL API, using information from Unpaywall for Crossref DOIs
  • Loading branch information
Martin Fenner authored Aug 31, 2020
2 parents 87636ac + 40f927e commit b6c3346
Show file tree
Hide file tree
Showing 7 changed files with 367 additions and 0 deletions.
5 changes: 5 additions & 0 deletions app/graphql/resolvers/base.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module Resolvers
class Base < GraphQL::Schema::Resolver

end
end
17 changes: 17 additions & 0 deletions app/graphql/resolvers/content_url.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# frozen_string_literal: true

class ContentUrl < Resolvers::Base
type Url, null: false

def resolve
# Use Unpaywall API if DOI is from Crossref
# This will be a future feature in the DataCite metadata schema
return nil if object.agency != "crossref"

url = "https://api.unpaywall.org/v2/#{object.doi}[email protected]"
response = Maremma.get(url)
return nil if response.status != 200

response.body.dig("data", "best_oa_location", "url")
end
end
135 changes: 135 additions & 0 deletions app/graphql/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,11 @@ type Audiovisual implements DoiItem {
"""
container: Container

"""
Url to download the content directly, if available
"""
contentUrl: Url!

"""
The institution or person responsible for collecting, managing, distributing,
or otherwise contributing to the development of the resource.
Expand Down Expand Up @@ -426,6 +431,11 @@ type Book implements DoiItem {
"""
container: Container

"""
Url to download the content directly, if available
"""
contentUrl: Url!

"""
The institution or person responsible for collecting, managing, distributing,
or otherwise contributing to the development of the resource.
Expand Down Expand Up @@ -674,6 +684,11 @@ type BookChapter implements DoiItem {
"""
container: Container

"""
Url to download the content directly, if available
"""
contentUrl: Url!

"""
The institution or person responsible for collecting, managing, distributing,
or otherwise contributing to the development of the resource.
Expand Down Expand Up @@ -1008,6 +1023,11 @@ type Collection implements DoiItem {
"""
container: Container

"""
Url to download the content directly, if available
"""
contentUrl: Url!

"""
The institution or person responsible for collecting, managing, distributing,
or otherwise contributing to the development of the resource.
Expand Down Expand Up @@ -1298,6 +1318,11 @@ type ConferencePaper implements DoiItem {
"""
container: Container

"""
Url to download the content directly, if available
"""
contentUrl: Url!

"""
The institution or person responsible for collecting, managing, distributing,
or otherwise contributing to the development of the resource.
Expand Down Expand Up @@ -1874,6 +1899,11 @@ type DataManagementPlan implements DoiItem {
"""
container: Container

"""
Url to download the content directly, if available
"""
contentUrl: Url!

"""
The institution or person responsible for collecting, managing, distributing,
or otherwise contributing to the development of the resource.
Expand Down Expand Up @@ -2166,6 +2196,11 @@ type DataPaper implements DoiItem {
"""
container: Container

"""
Url to download the content directly, if available
"""
contentUrl: Url!

"""
The institution or person responsible for collecting, managing, distributing,
or otherwise contributing to the development of the resource.
Expand Down Expand Up @@ -2457,6 +2492,11 @@ type Dataset implements DoiItem {
"""
container: Container

"""
Url to download the content directly, if available
"""
contentUrl: Url!

"""
The institution or person responsible for collecting, managing, distributing,
or otherwise contributing to the development of the resource.
Expand Down Expand Up @@ -2859,6 +2899,11 @@ type Dissertation implements DoiItem {
"""
container: Container

"""
Url to download the content directly, if available
"""
contentUrl: Url!

"""
The institution or person responsible for collecting, managing, distributing,
or otherwise contributing to the development of the resource.
Expand Down Expand Up @@ -3154,6 +3199,11 @@ interface DoiItem {
"""
container: Container

"""
Url to download the content directly, if available
"""
contentUrl: Url!

"""
The institution or person responsible for collecting, managing, distributing,
or otherwise contributing to the development of the resource.
Expand Down Expand Up @@ -3402,6 +3452,11 @@ type Event implements DoiItem {
"""
container: Container

"""
Url to download the content directly, if available
"""
contentUrl: Url!

"""
The institution or person responsible for collecting, managing, distributing,
or otherwise contributing to the development of the resource.
Expand Down Expand Up @@ -3678,6 +3733,11 @@ type EventData implements DoiItem {
"""
container: Container

"""
Url to download the content directly, if available
"""
contentUrl: Url!

"""
The institution or person responsible for collecting, managing, distributing,
or otherwise contributing to the development of the resource.
Expand Down Expand Up @@ -4246,6 +4306,11 @@ type Image implements DoiItem {
"""
container: Container

"""
Url to download the content directly, if available
"""
contentUrl: Url!

"""
The institution or person responsible for collecting, managing, distributing,
or otherwise contributing to the development of the resource.
Expand Down Expand Up @@ -4537,6 +4602,11 @@ type Instrument implements DoiItem {
"""
container: Container

"""
Url to download the content directly, if available
"""
contentUrl: Url!

"""
The institution or person responsible for collecting, managing, distributing,
or otherwise contributing to the development of the resource.
Expand Down Expand Up @@ -4827,6 +4897,11 @@ type InteractiveResource implements DoiItem {
"""
container: Container

"""
Url to download the content directly, if available
"""
contentUrl: Url!

"""
The institution or person responsible for collecting, managing, distributing,
or otherwise contributing to the development of the resource.
Expand Down Expand Up @@ -5143,6 +5218,11 @@ type JournalArticle implements DoiItem {
"""
container: Container

"""
Url to download the content directly, if available
"""
contentUrl: Url!

"""
The institution or person responsible for collecting, managing, distributing,
or otherwise contributing to the development of the resource.
Expand Down Expand Up @@ -5680,6 +5760,11 @@ type Model implements DoiItem {
"""
container: Container

"""
Url to download the content directly, if available
"""
contentUrl: Url!

"""
The institution or person responsible for collecting, managing, distributing,
or otherwise contributing to the development of the resource.
Expand Down Expand Up @@ -6096,6 +6181,11 @@ type Other implements DoiItem {
"""
container: Container

"""
Url to download the content directly, if available
"""
contentUrl: Url!

"""
The institution or person responsible for collecting, managing, distributing,
or otherwise contributing to the development of the resource.
Expand Down Expand Up @@ -6412,6 +6502,11 @@ type PeerReview implements DoiItem {
"""
container: Container

"""
Url to download the content directly, if available
"""
contentUrl: Url!

"""
The institution or person responsible for collecting, managing, distributing,
or otherwise contributing to the development of the resource.
Expand Down Expand Up @@ -6834,6 +6929,11 @@ type PhysicalObject implements DoiItem {
"""
container: Container

"""
Url to download the content directly, if available
"""
contentUrl: Url!

"""
The institution or person responsible for collecting, managing, distributing,
or otherwise contributing to the development of the resource.
Expand Down Expand Up @@ -7178,6 +7278,11 @@ type Preprint implements DoiItem {
"""
container: Container

"""
Url to download the content directly, if available
"""
contentUrl: Url!

"""
The institution or person responsible for collecting, managing, distributing,
or otherwise contributing to the development of the resource.
Expand Down Expand Up @@ -7470,6 +7575,11 @@ type Publication implements DoiItem {
"""
container: Container

"""
Url to download the content directly, if available
"""
contentUrl: Url!

"""
The institution or person responsible for collecting, managing, distributing,
or otherwise contributing to the development of the resource.
Expand Down Expand Up @@ -8206,6 +8316,11 @@ type Service implements DoiItem {
"""
container: Container

"""
Url to download the content directly, if available
"""
contentUrl: Url!

"""
The institution or person responsible for collecting, managing, distributing,
or otherwise contributing to the development of the resource.
Expand Down Expand Up @@ -8499,6 +8614,11 @@ type Software implements DoiItem {
"""
container: Container

"""
Url to download the content directly, if available
"""
contentUrl: Url!

"""
The institution or person responsible for collecting, managing, distributing,
or otherwise contributing to the development of the resource.
Expand Down Expand Up @@ -8822,6 +8942,11 @@ type Sound implements DoiItem {
"""
container: Container

"""
Url to download the content directly, if available
"""
contentUrl: Url!

"""
The institution or person responsible for collecting, managing, distributing,
or otherwise contributing to the development of the resource.
Expand Down Expand Up @@ -9296,6 +9421,11 @@ type Work implements DoiItem {
"""
container: Container

"""
Url to download the content directly, if available
"""
contentUrl: Url!

"""
The institution or person responsible for collecting, managing, distributing,
or otherwise contributing to the development of the resource.
Expand Down Expand Up @@ -9589,6 +9719,11 @@ type Workflow implements DoiItem {
"""
container: Container

"""
Url to download the content directly, if available
"""
contentUrl: Url!

"""
The institution or person responsible for collecting, managing, distributing,
or otherwise contributing to the development of the resource.
Expand Down
1 change: 1 addition & 0 deletions app/graphql/types/doi_item.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ module DoiItem
field :geolocations, [GeolocationType], null: true, hash_key: "geo_locations", description: "Spatial region or named place where the data was gathered or about which the data is focused."
field :funding_references, [FundingType], null: true, description: "Information about financial support (funding) for the resource being registered"
field :url, Url, null: true, description: "The URL registered for the resource"
field :content_url,resolver: ContentUrl, null: true, description: "Url to download the content directly, if available"
field :repository, RepositoryType, null: true, hash_key: "client", description: "The repository account managing this resource"
field :member, MemberType, null: true, hash_key: "provider", description: "The member account managing this resource"
field :registration_agency, RegistrationAgencyType, hash_key: "agency", null: true, description: "The DOI registration agency for the resource"
Expand Down
1 change: 1 addition & 0 deletions config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ class Application < Rails::Application
config.paths.add Rails.root.join('app', 'graphql', 'types').to_s, eager_load: true
config.paths.add Rails.root.join('app', 'graphql', 'mutations').to_s, eager_load: true
config.paths.add Rails.root.join('app', 'graphql', 'connections').to_s, eager_load: true
config.paths.add Rails.root.join('app', 'graphql', 'resolvers').to_s, eager_load: true

# Settings in config/environments/* take precedence over those specified here.
# Application configuration should go into files in config/initializers
Expand Down
Loading

0 comments on commit b6c3346

Please sign in to comment.