Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add events to GraphQL endpoint #934

Merged
merged 6 commits into from
Feb 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions app/graphql/types/address_type.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
module Types
class AddressType < Types::BaseObject

description 'An address representing a physical location'

# field :id, ID, null: false
field :street_address, String
field :street_address2, String
field :street_address3, String
ivankocienski marked this conversation as resolved.
Show resolved Hide resolved
field :city, String
field :postcode, String
field :country_code, String
field :full_street_address, String
field :all_address_lines, [String]
end
end

14 changes: 14 additions & 0 deletions app/graphql/types/event_type.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
module Types
class EventType < Types::BaseObject

description 'An Event that is run by a Parter'

field :id, ID, null: false
field :description, String
field :summary, String

field :address, AddressType

end
end

2 changes: 1 addition & 1 deletion app/graphql/types/partner_type.rb
Original file line number Diff line number Diff line change
@@ -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
Expand Down
18 changes: 18 additions & 0 deletions app/graphql/types/query_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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:)
kimadactyl marked this conversation as resolved.
Show resolved Hide resolved
Event.find(id)
end

def all_events
Event.all
end

####

field :ping, String, null: false, description: "Ping server"

def ping
Expand Down
82 changes: 82 additions & 0 deletions test/integration/graphql/event_integration_test.rb
Original file line number Diff line number Diff line change
@@ -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
Loading