Skip to content

Commit c00a14a

Browse files
Replace GeoPoint with GeoShape as attribute of LocationType
** 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.
1 parent 3c9db10 commit c00a14a

File tree

3 files changed

+59
-1
lines changed

3 files changed

+59
-1
lines changed

app/graphql/types/record_type.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ class AlternateTitleType < Types::BaseObject
108108

109109
# Warning: related_place was supposed to be an array but was incorrectly a string in graphql for v1
110110
class LocationType < Types::BaseObject
111-
field :geopoint, String, description: 'GeoPoint data for the location, if applicable'
111+
field :geoshape, String, description: 'GeoShape data for the location, if applicable'
112112
field :kind, String, description: 'Type of location'
113113
field :value, String, description: 'Name of location'
114114
end

test/controllers/graphql_controller_v2_test.rb

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -454,6 +454,30 @@ def setup
454454
end
455455
end
456456

457+
test 'graphqlv2 can retrieve geolocation information' do
458+
VCR.use_cassette('graphql v2 geolocation') do
459+
post '/graphql', params: { query: '{
460+
search(searchterm: "train stations") {
461+
records {
462+
locations {
463+
geoshape
464+
kind
465+
value
466+
}
467+
}
468+
}
469+
}' }
470+
assert_equal(200, response.status)
471+
json = JSON.parse(response.body)
472+
473+
assert_not json['errors'].present?
474+
assert_equal(
475+
json['data']['search']['records'].first['locations'][0].keys.sort,
476+
["geoshape", "value", "kind"].sort
477+
)
478+
end
479+
end
480+
457481
test 'graphqlv2 retrieve invalid field' do
458482
post '/graphql', params: { query: 'recordId(id: "stuff") {
459483
stuff

test/vcr_cassettes/graphql_v2_geolocation.yml

Lines changed: 34 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)