-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor detector GraphQL and implement journal detection type
Why these changes are being introduced: We've implemented a journal detection model but not the corresponding GraphQL. As this will be the second of many detectors, it also makes sense to reconsider how the detector GraphQL is modeled. Relevant ticket(s): * [TCO-50](https://mitlibraries.atlassian.net/browse/TCO-50) How this addresses that need: This makes `journals` and `standard_identifiers` fields within a new `DetectorsType`. Much like the `Detector` module, this new type is not to any ActiveRecord models and acts more as a namespace to contain the various detectors. Side effects of this change: * The graphql-ruby docs [advise against overusing JSON](https://graphql-ruby.org/api-doc/2.3.14/GraphQL/Types/JSON.html) as a GraphQL type, but this feels like a good use case for it. * I'm not certain whether my solution to the `detectors` field is idiomatic. It feels particularly odd given that, in the SearchEventType, there is a method for the `phrase` field that returns the same thing. * The gitignore file has been updated to ignore Lando config. This ended up being unrelated to this changeset, but it might be useful during cassette regeneration.
- Loading branch information
Showing
8 changed files
with
92 additions
and
39 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 |
---|---|---|
|
@@ -42,3 +42,4 @@ | |
.DS_Store | ||
.vscode/ | ||
.yardoc | ||
.lando.yml |
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,22 @@ | ||
# frozen_string_literal: true | ||
|
||
module Types | ||
class DetectorsType < Types::BaseObject | ||
description 'Provides all available search term detectors' | ||
|
||
field :journals, [Types::JournalsType], description: 'Information about journals detected in the search term' | ||
field :standard_identifiers, [Types::StandardIdentifiersType], description: 'Currently supported: ISBN, ISSN, PMID, DOI' | ||
|
||
def standard_identifiers | ||
Detector::StandardIdentifiers.new(@object).identifiers.map do |identifier| | ||
{ kind: identifier.first, value: identifier.last } | ||
end | ||
end | ||
|
||
def journals | ||
Detector::Journal.full_term_match(@object).map do |journal| | ||
{ title: journal.name, additional_info: journal.additional_info } | ||
end | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# frozen_string_literal: true | ||
|
||
module Types | ||
class JournalsType < Types::BaseObject | ||
description 'A detector for journal titles in search terms' | ||
|
||
field :additional_info, GraphQL::Types::JSON, description: 'Additional information about the detected journal' | ||
field :title, String, null: false, description: 'Title of the detected journal' | ||
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
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