Skip to content

Commit

Permalink
Added support for new publisher object in graphql
Browse files Browse the repository at this point in the history
  • Loading branch information
bklaing2 committed Dec 19, 2023
1 parent 496f91c commit 3083f3d
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 18 deletions.
13 changes: 3 additions & 10 deletions app/graphql/types/doi_item.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,10 @@ class CitationFormat < GraphQL::Schema::Enum
description:
"The year when the data was or will be made publicly available"
field :publisher,
String,
PublisherType,
null: true,
description:
"The name of the entity that holds, archives, publishes prints, distributes, releases, issues, or produces the resource"
"The entity that holds, archives, publishes prints, distributes, releases, issues, or produces the resource"
field :subjects,
[SubjectType],
null: true,
Expand Down Expand Up @@ -580,14 +580,7 @@ def identifiers
end

def publisher
case object.publisher
when Hash
object.publisher["name"]
when String
object.publisher
else
object.publisher
end
publisher = object.try(:publisher_obj) || object.try(:publisher)
end

def bibtex
Expand Down
26 changes: 26 additions & 0 deletions app/graphql/types/publisher_type.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# frozen_string_literal: true

class PublisherType < BaseObject
description "Publisher information"

field :name,
String,
null: true,
description: "The name of the publisher"
field :publisher_identifier,
String,
null: true,
hash_key: "publisherIdentifier",
description: "Uniquely identifies the publisher, according to various schemes"
field :publisher_identifier_scheme,
String,
null: true,
hash_key: "publisherIdentifierScheme",
description: "The name of the publisher identifier scheme"
field :scheme_uri,
String,
null: true,
hash_key: "schemeUri",
description: "The URI of the publisher identifier scheme"
field :lang, String, null: true, description: "Language"
end
2 changes: 1 addition & 1 deletion spec/graphql/types/doi_item_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
it { is_expected.to have_field(:creators).of_type("[Creator!]") }
it { is_expected.to have_field(:titles).of_type("[Title!]") }
it { is_expected.to have_field(:publicationYear).of_type("Int") }
it { is_expected.to have_field(:publisher).of_type("String") }
it { is_expected.to have_field(:publisher).of_type("Publisher") }
it { is_expected.to have_field(:subjects).of_type("[Subject!]") }
it { is_expected.to have_field(:fieldsOfScience).of_type("[FieldOfScience!]") }
it { is_expected.to have_field(:fieldsOfScienceRepository).of_type("[FieldOfScience!]") }
Expand Down
36 changes: 29 additions & 7 deletions spec/graphql/types/work_type_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,13 @@
identifierType
title
}
publisher
publisher {
name
publisherIdentifier
publisherIdentifierScheme
schemeUri
lang
}
bibtex
xml
schemaOrg
Expand Down Expand Up @@ -91,9 +97,13 @@
expect(response.dig("data", "work", "id")).to eq(
"https://handle.stage.datacite.org/#{work.doi.downcase}",
)
expect(response.dig("data", "work", "publisher")).to eq(
"Dryad Digital Repository",
)
expect(response.dig("data", "work", "publisher")).to eq({
"name" => "Dryad Digital Repository",
"publisherIdentifier" => "https://ror.org/00x6h5n95",
"publisherIdentifierScheme" => "ROR",
"schemeUri" => "https://ror.org/",
"lang" => "en"
})

bibtex =
BibTeX.parse(response.dig("data", "work", "bibtex")).to_a(quotes: "").
Expand Down Expand Up @@ -335,8 +345,14 @@
nodes {
id
doi
publisher
creators{
publisher {
name
publisherIdentifier
publisherIdentifierScheme
schemeUri
lang
}
creators {
type
}
}
Expand Down Expand Up @@ -521,7 +537,13 @@
).to be nil
expect(
response.dig("data", "works", "nodes", 0, "publisher"),
).to eq("Dryad Digital Repository")
).to eq({
"name" => "Dryad Digital Repository",
"publisherIdentifier" => "https://ror.org/00x6h5n95",
"publisherIdentifierScheme" => "ROR",
"schemeUri" => "https://ror.org/",
"lang" => "en"
})
end_cursor = response.dig("data", "works", "pageInfo", "endCursor")

response =
Expand Down

0 comments on commit 3083f3d

Please sign in to comment.