From d054f332e4058da2e7a2c2b43d9a12633503712d Mon Sep 17 00:00:00 2001 From: Ivan Kocienski Date: Thu, 10 Feb 2022 17:14:14 +0000 Subject: [PATCH 1/6] API endpoint for events - event and allEvents - can include the address on an event --- app/graphql/types/address_type.rb | 15 +++++++++++++++ app/graphql/types/event_type.rb | 14 ++++++++++++++ app/graphql/types/query_type.rb | 18 ++++++++++++++++++ 3 files changed, 47 insertions(+) create mode 100644 app/graphql/types/address_type.rb create mode 100644 app/graphql/types/event_type.rb diff --git a/app/graphql/types/address_type.rb b/app/graphql/types/address_type.rb new file mode 100644 index 000000000..6f506e270 --- /dev/null +++ b/app/graphql/types/address_type.rb @@ -0,0 +1,15 @@ +module Types + class AddressType < Types::BaseObject + + description 'A partner' + + # field :id, ID, null: false + field :street_address, String + field :street_address2, String + field :street_address3, String + field :city, String + field :postcode, String + field :country_code, String + end +end + diff --git a/app/graphql/types/event_type.rb b/app/graphql/types/event_type.rb new file mode 100644 index 000000000..029e204c5 --- /dev/null +++ b/app/graphql/types/event_type.rb @@ -0,0 +1,14 @@ +module Types + class EventType < Types::BaseObject + + description 'An Event' + + field :id, ID, null: false + field :description, String + field :summary, String + + field :address, AddressType + + end +end + diff --git a/app/graphql/types/query_type.rb b/app/graphql/types/query_type.rb index 149dff033..81993d564 100644 --- a/app/graphql/types/query_type.rb +++ b/app/graphql/types/query_type.rb @@ -23,6 +23,24 @@ def all_partners Partner.all end + #### + + field :event, EventType, "Find Event by ID" do + argument :id, ID + end + + field :all_events, [EventType] + + def event(id:) + Event.find(id) + end + + def all_events + Event.all + end + + #### + field :ping, String, null: false, description: "Ping server" def ping From b0628a2939eb54af58af89dc910bcd4f5e5a8255 Mon Sep 17 00:00:00 2001 From: Ivan Kocienski Date: Mon, 14 Feb 2022 11:04:11 +0000 Subject: [PATCH 2/6] Tests covering Event GraphQL endpoints --- .../graphql/event_integration_test.rb | 82 +++++++++++++++++++ 1 file changed, 82 insertions(+) create mode 100644 test/integration/graphql/event_integration_test.rb diff --git a/test/integration/graphql/event_integration_test.rb b/test/integration/graphql/event_integration_test.rb new file mode 100644 index 000000000..899aaca16 --- /dev/null +++ b/test/integration/graphql/event_integration_test.rb @@ -0,0 +1,82 @@ +# frozen_string_literal: true + +require 'test_helper' + +class GraphQLEventTest < ActionDispatch::IntegrationTest + + setup do + @partner = FactoryBot.create(:partner) + + @address = @partner.address + assert @address, 'Failed to create Address from partner' + + @calendar = FactoryBot.create( + :calendar, + partner: @partner, + name: 'Partner Calendar', + source: 'http://example.com' + ) + assert @calendar, 'Failed to create calendar from partner' + end + + test 'can show partners' do + + (0...5).collect do |n| + @partner.events.create!( + dtstart: Time.now, + summary: "An event summary #{n}", + description: 'Longer text covering the event in more detail', + address: @address + ) + end + + query_string = <<-GRAPHQL + query { + allEvents { + id + summary + description + } + } + GRAPHQL + + result = PlaceCalSchema.execute(query_string) + data = result['data'] + assert data.has_key?('allEvents'), 'result is missing key `allEvents`' + + events = data['allEvents'] + assert events.length == 5 + end + + test 'can show specific event' do + event = @partner.events.create!( + dtstart: Time.now, + summary: "An event summary", + description: 'Longer text covering the event in more detail', + address: @address + ) + + query_string = <<-GRAPHQL + query { + event(id: #{event.id}) { + id + summary + description + address { + streetAddress + city + postcode + } + } + } + GRAPHQL + + result = PlaceCalSchema.execute(query_string) + + 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 + end +end From 338fbcef901231e0a9c6ebb7b76ec01f12e914a6 Mon Sep 17 00:00:00 2001 From: Ivan Kocienski Date: Mon, 14 Feb 2022 12:13:47 +0000 Subject: [PATCH 3/6] Slightly better descriptions of GraphQL data responses --- app/graphql/types/address_type.rb | 2 +- app/graphql/types/event_type.rb | 2 +- app/graphql/types/partner_type.rb | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/app/graphql/types/address_type.rb b/app/graphql/types/address_type.rb index 6f506e270..26ad78dd9 100644 --- a/app/graphql/types/address_type.rb +++ b/app/graphql/types/address_type.rb @@ -1,7 +1,7 @@ module Types class AddressType < Types::BaseObject - description 'A partner' + description 'An address representing a physical building' # field :id, ID, null: false field :street_address, String diff --git a/app/graphql/types/event_type.rb b/app/graphql/types/event_type.rb index 029e204c5..622462454 100644 --- a/app/graphql/types/event_type.rb +++ b/app/graphql/types/event_type.rb @@ -1,7 +1,7 @@ module Types class EventType < Types::BaseObject - description 'An Event' + description 'An Event that is run by a Parter on a date at a given Address' field :id, ID, null: false field :description, String diff --git a/app/graphql/types/partner_type.rb b/app/graphql/types/partner_type.rb index 1ce3e8779..d1c384b69 100644 --- a/app/graphql/types/partner_type.rb +++ b/app/graphql/types/partner_type.rb @@ -1,7 +1,7 @@ module Types class PartnerType < Types::BaseObject - description 'A partner' + description 'A Partner who runs Events' field :id, ID, null: false field :name, String, null: false From 6235172bdd91f0892006ce6191c262f416c4ae28 Mon Sep 17 00:00:00 2001 From: Ivan Kocienski Date: Mon, 14 Feb 2022 12:19:00 +0000 Subject: [PATCH 4/6] Added address fields to response Now users can ask for `allAddressLines` or `fullStreetAddress` to their queries --- app/graphql/types/address_type.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/graphql/types/address_type.rb b/app/graphql/types/address_type.rb index 26ad78dd9..675abb8c8 100644 --- a/app/graphql/types/address_type.rb +++ b/app/graphql/types/address_type.rb @@ -10,6 +10,8 @@ class AddressType < Types::BaseObject field :city, String field :postcode, String field :country_code, String + field :full_street_address, String + field :all_address_lines, [String] end end From 376fe494b3671e163cd2fd5ccf81988fc46f0067 Mon Sep 17 00:00:00 2001 From: Dr Kim Foale Date: Mon, 14 Feb 2022 13:04:56 +0000 Subject: [PATCH 5/6] Change event description --- app/graphql/types/event_type.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/graphql/types/event_type.rb b/app/graphql/types/event_type.rb index 622462454..55f16c74c 100644 --- a/app/graphql/types/event_type.rb +++ b/app/graphql/types/event_type.rb @@ -1,7 +1,7 @@ module Types class EventType < Types::BaseObject - description 'An Event that is run by a Parter on a date at a given Address' + description 'An Event that is run by a Parter' field :id, ID, null: false field :description, String From 238e0eded692bfbeb8293ea838f5f3b4f26ca45b Mon Sep 17 00:00:00 2001 From: Dr Kim Foale Date: Mon, 14 Feb 2022 13:05:22 +0000 Subject: [PATCH 6/6] Edit address description --- app/graphql/types/address_type.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/graphql/types/address_type.rb b/app/graphql/types/address_type.rb index 675abb8c8..6c26a8641 100644 --- a/app/graphql/types/address_type.rb +++ b/app/graphql/types/address_type.rb @@ -1,7 +1,7 @@ module Types class AddressType < Types::BaseObject - description 'An address representing a physical building' + description 'An address representing a physical location' # field :id, ID, null: false field :street_address, String