Skip to content

Commit 4bdafc0

Browse files
Merge pull request #784 from MITLibraries/gdt-134
Update GraphQL to better support Locations
2 parents 3c9db10 + cdf20f7 commit 4bdafc0

File tree

3 files changed

+65
-1
lines changed

3 files changed

+65
-1
lines changed

app/graphql/types/record_type.rb

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,9 +108,14 @@ 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 :geopoint, String, deprecation_reason: 'Use `geoshape`'
112+
field :geoshape, String, description: 'GeoShape data for the location, if applicable'
112113
field :kind, String, description: 'Type of location'
113114
field :value, String, description: 'Name of location'
115+
116+
def geopoint
117+
@object['geoshape']
118+
end
114119
end
115120

116121
class HighlightType < Types::BaseObject

test/controllers/graphql_controller_v2_test.rb

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -454,6 +454,31 @@ 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+
geopoint
464+
geoshape
465+
kind
466+
value
467+
}
468+
}
469+
}
470+
}' }
471+
assert_equal(200, response.status)
472+
json = JSON.parse(response.body)
473+
474+
assert_not json['errors'].present?
475+
assert_equal(
476+
json['data']['search']['records'].first['locations'][0].keys.sort,
477+
["geopoint", "geoshape", "value", "kind"].sort
478+
)
479+
end
480+
end
481+
457482
test 'graphqlv2 retrieve invalid field' do
458483
post '/graphql', params: { query: 'recordId(id: "stuff") {
459484
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)