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

Update GraphQL to better support Locations #784

Merged
merged 2 commits into from
Feb 13, 2024
Merged

Update GraphQL to better support Locations #784

merged 2 commits into from
Feb 13, 2024

Conversation

matt-bernhardt
Copy link
Member

@matt-bernhardt matt-bernhardt commented Feb 6, 2024

This replaces the GeoPoint field in LocationType with a GeoShape. I also take a crack at writing a test for this, but I'm honestly still not sure it is needed. I don't think we have any similar tests like this for the other types defined in record_type.rb.

Developer

  • All new ENV is documented in README
  • All new ENV has been added to Heroku Pipeline, Staging and Prod
  • 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)
  • Stakeholder approval has been confirmed (or is not needed)

Code Reviewer

  • The commit message is clear and follows our guidelines
    (not just this pull request message)
  • There are appropriate tests covering any new functionality
  • The documentation has been updated or is unnecessary
  • The changes have been verified
  • New dependencies are appropriate or there were no changes

Requires database migrations?

NO

Includes new or updated dependencies?

NO

@mitlib mitlib temporarily deployed to timdex-pr-784 February 6, 2024 19:47 Inactive
@matt-bernhardt matt-bernhardt force-pushed the gdt-134 branch 2 times, most recently from f26fff7 to 3241148 Compare February 8, 2024 21:14
@matt-bernhardt matt-bernhardt marked this pull request as ready for review February 8, 2024 21:14
@JPrevost JPrevost self-assigned this Feb 9, 2024
@@ -108,7 +108,7 @@ class AlternateTitleType < Types::BaseObject

# Warning: related_place was supposed to be an array but was incorrectly a string in graphql for v1
class LocationType < Types::BaseObject
field :geopoint, String, description: 'GeoPoint data for the location, if applicable'
Copy link
Member

Choose a reason for hiding this comment

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

As we discussed on zoom, let's try to deprecate geopoint as a matter of best practice even though it is very unlikely anyone is using it.

So the we'd mark the field as deprecated and suggest using the new field while still mapping the new field value to the old field so people still get what they asked for either way. See https://github.com/MITLibraries/timdex/blob/main/app/graphql/types/record_type.rb#L34-L36 for an example of how we have done that on other fields that got renamed.

Copy link
Member Author

Choose a reason for hiding this comment

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

Sure thing - I've switched from a replacement to a deprecation for geopoint now. The test has been updated to include it as well. I see the deprecation announcement in the help docs, but don't see it in the actual API response, so I don't yet have a way to test for the deprecation itself.

Copy link
Member

Choose a reason for hiding this comment

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

I don't think we need an explicit test for the deprecation at this point. Manually confirm it is flagged as deprecated along with the tests that both fields return the expected data should be solid. I'll finish up the review on this now thanks!

Copy link
Member

@JPrevost JPrevost left a comment

Choose a reason for hiding this comment

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

I think this is good now but I am not approving until we coordinate with DataEng on when they would like to update production TIMDEX data to use the new field (i.e. I want to keep main deployable and I'm pretty sure this would break things if someone requested either Locations.geopoint or locations.geoshape once we merge until the index mappings are updated. I don't know if this will require a full reharvest or just an update to the mappings on the existing indexes since there is currently no data in the changing field.

@@ -108,9 +108,14 @@ class AlternateTitleType < Types::BaseObject

# Warning: related_place was supposed to be an array but was incorrectly a string in graphql for v1
class LocationType < Types::BaseObject
field :geopoint, String, deprecation_reason: 'Use `geoshape`'
field :geoshape, String, description: 'GeoShape data for the location, if applicable'
Copy link
Member

Choose a reason for hiding this comment

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

We may want to provide more details on what is in this field. I believe dataeng is consistently (we should confirm) using the BBOX option for the envelope as described here:
https://opensearch.org/docs/latest/field-types/supported-field-types/geo-shape/#envelope

If that turns out to be true, noting something like this for description would probably be helpful.
'GeoShape data for the location when available in WKT format. i.e. BBOX (minLon, maxLon, maxLat, minLat)'

@matt-bernhardt
Copy link
Member Author

I'd love to write a more helpful description field for geoshape, definitely.

@matt-bernhardt matt-bernhardt force-pushed the gdt-134 branch 2 times, most recently from 6c1035e to a059699 Compare February 12, 2024 21:18
@JPrevost JPrevost self-requested a review February 13, 2024 19:26
Copy link
Member

@JPrevost JPrevost left a comment

Choose a reason for hiding this comment

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

@matt-bernhardt I realize now that we have a bunch of other things that aren't really ready for prod right now until the indexes are updated so holding this one back doesn't make sense. We can merge, and we'll need to carefully plan a release with all of the new geospatial features soon in conjunction with data being released or at least indexes being updated to support the data.

** Why are these changes being introduced:

* Now that we're adding geospatial records to TIMDEX, we have changed
  the data model slightly. Initially we had wanted to use a GeoPoint
  field in the LocationType construct, but that is now ending up as
  GeoShape. As a result, we need to update the application code to
  match our actual use of these records.

** Relevant ticket(s):

* https://mitlibraries.atlassian.net/browse/gdt-134

** How does this address that need:

* This replaces the GeoPoint field with a GeoShape field.

* In parallel to the data model change, we also add a test to confirm
  that all three fields are coming back from the GraphQL endpoint.

** Document any side effects to this change:

* I'm not sure whether it is a problem to be testing the extents of the
  data model in this way, but I'm also not sure whether there's a
  better way to confirm this change in code. It feels worse to do a test
  of a specific record, because then our tests are fragile to changes
  in library holdings - which feels worse.
** Why are these changes being introduced:

* Rather than simply replacing geopoint with geoshape, we are going to
  keep geopoint in the code, but mark it as deprecated. This is the
  recommended workflow for making changes in GraphQL (which we are
  following here to reinforce the practice, even though this particular
  field has never been populated)

** How does this address that need:

* This brings back the geopoint field in the LocationType definition,
  but markes it deprecated in the schema.

* We add a method to the Location type that populates the geopoint
  field with the contents of the geoshape field. Ironically, this is
  likely the first time that the geopoint field has been able to respond
  with any values at all.

* We also update the test to include reference to this now-deprecated
  field.

** Document any side effects to this change:

* Is it a side effect to be, effectively, adding content to the geopoint
  field only as we mark it deprecated?
@matt-bernhardt matt-bernhardt merged commit 4bdafc0 into main Feb 13, 2024
4 checks passed
@matt-bernhardt matt-bernhardt deleted the gdt-134 branch February 13, 2024 22:11
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