From ab30f1c7f28fffecf37d5dcf5773a3fdde1e326f Mon Sep 17 00:00:00 2001 From: Ivan Kocienski Date: Mon, 14 Mar 2022 15:22:47 +0000 Subject: [PATCH] New response format for Events via GraphQL (#1050) --- app/graphql/types/event_type.rb | 10 +++++++--- app/graphql/types/query_type.rb | 2 +- config/routes.rb | 4 ++-- .../graphql/event_integration_test.rb | 17 +++++++++++++++++ 4 files changed, 27 insertions(+), 6 deletions(-) diff --git a/app/graphql/types/event_type.rb b/app/graphql/types/event_type.rb index 55f16c74c..98de8196f 100644 --- a/app/graphql/types/event_type.rb +++ b/app/graphql/types/event_type.rb @@ -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 diff --git a/app/graphql/types/query_type.rb b/app/graphql/types/query_type.rb index 44b3b1408..8a1a41d27 100644 --- a/app/graphql/types/query_type.rb +++ b/app/graphql/types/query_type.rb @@ -33,7 +33,7 @@ def event(id:) end def event_connection(**args) - Event.all + Event.sort_by_time.all end end diff --git a/config/routes.rb b/config/routes.rb index 4f1f41b62..a30798259 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -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 diff --git a/test/integration/graphql/event_integration_test.rb b/test/integration/graphql/event_integration_test.rb index 708224892..80e49fa19 100644 --- a/test/integration/graphql/event_integration_test.rb +++ b/test/integration/graphql/event_integration_test.rb @@ -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