Skip to content

Commit

Permalink
New response format for Events via GraphQL (#1050)
Browse files Browse the repository at this point in the history
  • Loading branch information
ivankocienski authored Mar 14, 2022
1 parent d90451e commit ab30f1c
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 6 deletions.
10 changes: 7 additions & 3 deletions app/graphql/types/event_type.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
module Types
class EventType < Types::BaseObject

description 'An Event that is run by a Parter'

field :id, ID, null: false
field :description, String
# Summary and name are aliases, this is left as a convenience
# for people used to iCal format
field :name, String, method: :summary
field :summary, String
field :description, String
field :startDate, String, method: :dtstart, null: false
field :endDate, String, method: :dtend

field :address, AddressType
field :organizer, PartnerType, method: :partner

end
end
Expand Down
2 changes: 1 addition & 1 deletion app/graphql/types/query_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def event(id:)
end

def event_connection(**args)
Event.all
Event.sort_by_time.all
end
end

Expand Down
4 changes: 2 additions & 2 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,10 @@

get '/robots.txt' => 'pages#robots'

post '/api/v1', to: 'graphql#execute'
post '/api/v1/graphql', to: 'graphql#execute'

if Rails.env.development?
mount GraphiQL::Rails::Engine, at: '/graphiql', graphql_path: "/api/v1"
mount GraphiQL::Rails::Engine, at: '/graphiql', graphql_path: "/api/v1/graphql"
end

end
17 changes: 17 additions & 0 deletions test/integration/graphql/event_integration_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,24 +68,41 @@ class GraphQLEventTest < ActionDispatch::IntegrationTest
query {
event(id: #{event.id}) {
id
name
summary
description
startDate
endDate
address {
streetAddress
postalCode
addressLocality
addressRegion
}
organizer {
id
name
}
}
}
GRAPHQL

result = PlaceCalSchema.execute(query_string)
assert result.has_key?('errors') == false, 'errors are present'

data = result['data']
assert data.has_key?('event'), 'Data structure does not contain event key'

data_event = data['event']

assert data_event['summary'] == event.summary
assert data_event['name'] == event.summary

assert data_event.has_key?('startDate'), 'missing startDate'
assert data_event['startDate'] =~ /^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2} \+\d{4}$/, 'startDate is not in ISO format'

assert data_event.has_key?('endDate'), 'missing endDate'
assert data_event.has_key?('address'), 'missing address'
assert data_event.has_key?('organizer'), 'missing organizer'
end
end

0 comments on commit ab30f1c

Please sign in to comment.