Skip to content

Commit

Permalink
Merge pull request #784 from MITLibraries/gdt-134
Browse files Browse the repository at this point in the history
Update GraphQL to better support Locations
  • Loading branch information
matt-bernhardt committed Feb 13, 2024
2 parents 3c9db10 + cdf20f7 commit 4bdafc0
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 1 deletion.
7 changes: 6 additions & 1 deletion app/graphql/types/record_type.rb
Expand Up @@ -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, description: 'GeoPoint data for the location, if applicable'
field :geopoint, String, deprecation_reason: 'Use `geoshape`'
field :geoshape, String, description: 'GeoShape data for the location, if applicable'
field :kind, String, description: 'Type of location'
field :value, String, description: 'Name of location'

def geopoint
@object['geoshape']
end
end

class HighlightType < Types::BaseObject
Expand Down
25 changes: 25 additions & 0 deletions test/controllers/graphql_controller_v2_test.rb
Expand Up @@ -454,6 +454,31 @@ def setup
end
end

test 'graphqlv2 can retrieve geolocation information' do
VCR.use_cassette('graphql v2 geolocation') do
post '/graphql', params: { query: '{
search(searchterm: "train stations") {
records {
locations {
geopoint
geoshape
kind
value
}
}
}
}' }
assert_equal(200, response.status)
json = JSON.parse(response.body)

assert_not json['errors'].present?
assert_equal(
json['data']['search']['records'].first['locations'][0].keys.sort,
["geopoint", "geoshape", "value", "kind"].sort
)
end
end

test 'graphqlv2 retrieve invalid field' do
post '/graphql', params: { query: 'recordId(id: "stuff") {
stuff
Expand Down
34 changes: 34 additions & 0 deletions test/vcr_cassettes/graphql_v2_geolocation.yml

Large diffs are not rendered by default.

0 comments on commit 4bdafc0

Please sign in to comment.