Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor detector GraphQL and implement journal detection type #92

Merged
merged 2 commits into from
Aug 26, 2024

Conversation

jazairi
Copy link
Contributor

@jazairi jazairi commented Aug 23, 2024

This changeset refactors the GraphQL for detectors while adding a journal detector type. There is now a DetectorsType, which has the standardIdentifers and journals fields. Previously, standardIdentifiers (our only detector implemented as GraphQL) was a field on TermType and SearchEventType. This worked well for a single detector, but it will become unwieldy as we add more.

This design also mirrors our models, which are namespaced in a Detector module. To that point, a separate commit moves the StandardIdentifiers model, which was introduced before the Detector module, into that namespace.

Please read the commit messages accompanying this PR, as there are some quirks and side effects that I noted there.

Developer

Ticket(s)

TCO-50

Accessibility

  • ANDI or Wave has been run in accordance to our guide and
    all issues introduced by these changes have been resolved or opened
    as new issues (link to those issues in the Pull Request details above)
  • There are no accessibility implications to this change

Documentation

  • Project documentation has been updated, and yard output previewed (new GraphQL fields and types have been documented)
  • No documentation changes are needed

ENV

  • All new ENV is documented in README.
  • All new ENV has been added to Heroku Pipeline, Staging and Prod.
  • ENV has not changed.

Stakeholders

  • Stakeholder approval has been confirmed
  • Stakeholder approval is not needed

Dependencies and migrations

NO dependencies are updated

NO migrations are included

Reviewer

Code

  • I have confirmed that the code works as intended.
  • Any CodeClimate issues have been fixed or confirmed as
    added technical debt.

Documentation

  • The commit message is clear and follows our guidelines
    (not just this pull request message).
  • The documentation has been updated or is unnecessary.
  • New dependencies are appropriate or there were no changes.

Testing

  • There are appropriate tests covering any new functionality.
  • No additional test coverage is required.

Why these changes are being introduced:

Since we created the `StandardIdentifiers` model, we started
namespacing our detection models.

Relevant ticket(s):

Tangentially related to [TCO-50](https://mitlibraries.atlassian.net/browse/TCO-50)

How this addresses that need:

This adds the `Detectors` namespace to `StandardIdentifiers` to
match our other detection models (`Journal` and `SuggestedResource`).

Side effects of this change:

Some cascading changes were made in Metrics::Algorithms and
the SearchEventType GraphQL.
@mitlib mitlib temporarily deployed to tacos-api-pipeline-pr-92 August 23, 2024 19:20 Inactive
@jazairi jazairi temporarily deployed to tacos-api-pipeline-pr-92 August 23, 2024 19:35 Inactive
@jazairi jazairi force-pushed the tco-50-journal-detection-graphql branch from b28f37a to 5fd7b4d Compare August 23, 2024 19:46
@jazairi jazairi temporarily deployed to tacos-api-pipeline-pr-92 August 23, 2024 19:46 Inactive
@jazairi jazairi force-pushed the tco-50-journal-detection-graphql branch from 5fd7b4d to f0979b6 Compare August 23, 2024 19:48
@jazairi jazairi temporarily deployed to tacos-api-pipeline-pr-92 August 23, 2024 19:49 Inactive
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.
@jazairi jazairi force-pushed the tco-50-journal-detection-graphql branch from f0979b6 to 7083502 Compare August 23, 2024 19:49
@jazairi jazairi temporarily deployed to tacos-api-pipeline-pr-92 August 23, 2024 19:50 Inactive
@matt-bernhardt matt-bernhardt self-assigned this Aug 26, 2024
Copy link
Member

@matt-bernhardt matt-bernhardt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good to me. I confess that I'm still working through the best practices for designing GraphQL types, so I'm not sure whether there's things here that I'm missing, but seeing this implementation get much more standardized feels right. It also points to a place where maybe our model implementations might need more consistent approaches (using "new" in some cases while others have "full_term_match") - but this isn't the PR to worry about that.

Thanks for taking this on!

field :standard_identifiers, [Types::StandardIdentifiersType], description: 'Currently supported: ISBN, ISSN, PMID, DOI'

def standard_identifiers
Detector::StandardIdentifiers.new(@object).identifiers.map do |identifier|
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know that this is correct, and I don't think that this work is where any changes should be made, but I'm starting to wonder whether a new method is the right thing to be calling in this type of context. Comparing Detector::StandardIdentifiers.new() here with Detector::Journal.full_term_match() below forces me to remember that our "new" doesn't actually create new records and pollute our dataset as a side effect.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, that's a good point. Putting an initialize method on a non-ActiveRecord model is a bit confusing. Looking at the code, I think we did it that way to make use of an instance variable, but there could yet be a way to refactor it using singleton methods. I opened this spike ticket to investigate.

{ kind: identifier.first, value: identifier.last }
end
def detectors
@object.term.phrase
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking at the set of changes, both here and within the Detectors type, I appreciate the work you've done to standardize how they're implemented.

@jazairi jazairi merged commit dbcd565 into main Aug 26, 2024
3 checks passed
@jazairi jazairi deleted the tco-50-journal-detection-graphql branch August 26, 2024 17:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants