nulogy_message_bus_producer 3.3.0 → 3.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (48) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +67 -17
  3. data/Rakefile +2 -4
  4. data/db/migrate/20200611150212_create_public_subscriptions_and_events_tables.rb +2 -2
  5. data/lib/nulogy_message_bus_producer.rb +8 -4
  6. data/lib/nulogy_message_bus_producer/base_subscription.rb +1 -1
  7. data/lib/nulogy_message_bus_producer/config.rb +25 -1
  8. data/lib/nulogy_message_bus_producer/configuration/query_parser.rb +71 -0
  9. data/lib/nulogy_message_bus_producer/subscription.rb +3 -1
  10. data/lib/nulogy_message_bus_producer/subscriptions/finder.rb +40 -0
  11. data/lib/nulogy_message_bus_producer/subscriptions/postgres_transport.rb +9 -2
  12. data/lib/nulogy_message_bus_producer/subscriptions/query_validator.rb +47 -0
  13. data/lib/nulogy_message_bus_producer/version.rb +1 -1
  14. data/spec/dummy/Rakefile +1 -1
  15. data/spec/dummy/app/mailers/application_mailer.rb +2 -2
  16. data/spec/dummy/bin/bundle +2 -2
  17. data/spec/dummy/bin/rails +3 -3
  18. data/spec/dummy/bin/rake +2 -2
  19. data/spec/dummy/bin/setup +10 -11
  20. data/spec/dummy/bin/update +10 -10
  21. data/spec/dummy/bin/yarn +6 -8
  22. data/spec/dummy/config.ru +1 -1
  23. data/spec/dummy/config/boot.rb +3 -3
  24. data/spec/dummy/config/environment.rb +1 -1
  25. data/spec/dummy/config/environments/development.rb +2 -2
  26. data/spec/dummy/config/environments/production.rb +5 -5
  27. data/spec/dummy/config/environments/test.rb +2 -2
  28. data/spec/dummy/config/initializers/assets.rb +2 -2
  29. data/spec/dummy/config/puma.rb +3 -3
  30. data/spec/dummy/config/spring.rb +2 -2
  31. data/spec/dummy/db/schema.rb +0 -2
  32. data/spec/dummy/log/development.log +2333 -0
  33. data/spec/dummy/log/test.log +44636 -0
  34. data/spec/integration/lib/nulogy_message_bus_producer/config_spec.rb +37 -0
  35. data/spec/integration/lib/nulogy_message_bus_producer/repopulate_replication_slots_spec.rb +2 -2
  36. data/spec/integration/lib/nulogy_message_bus_producer/subscription_spec.rb +20 -2
  37. data/spec/integration/lib/nulogy_message_bus_producer/subscriptions/finder_spec.rb +54 -0
  38. data/spec/integration/lib/nulogy_message_bus_producer/subscriptions/no_variables_spec.rb +1 -1
  39. data/spec/integration/lib/nulogy_message_bus_producer/subscriptions/postgres_transport_spec.rb +100 -54
  40. data/spec/integration/lib/nulogy_message_bus_producer/{subscriber_graphql_schema_validator_spec.rb → subscriptions/query_validator_spec.rb} +3 -3
  41. data/spec/integration/lib/nulogy_message_bus_producer/subscriptions/risky_subscription_blocker_spec.rb +0 -16
  42. data/spec/nulogy_message_bus_producer/configuration/query_parser_spec.rb +58 -0
  43. data/spec/spec_helper.rb +21 -1
  44. data/spec/support/kafka_connect.rb +1 -1
  45. data/spec/support/subscription_helpers.rb +21 -3
  46. data/spec/support/test_graphql_schema.rb +6 -0
  47. metadata +23 -25
  48. data/lib/nulogy_message_bus_producer/subscriber_graphql_schema_validator.rb +0 -45
data/spec/spec_helper.rb CHANGED
@@ -1,4 +1,6 @@
1
- # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
1
+ require "rails/all"
2
+ require "nulogy_message_bus_producer"
3
+
2
4
  RSpec.configure do |config|
3
5
  config.expect_with(:rspec) do |expectations|
4
6
  # This is generally recommended, and will default to `true` in RSpec 4.
@@ -32,4 +34,22 @@ RSpec.configure do |config|
32
34
  # test failures related to randomization by passing the same `--seed` value
33
35
  # as the one that triggered the failure.
34
36
  Kernel.srand(config.seed)
37
+
38
+ config.around do |example|
39
+ if example.metadata[:subscriptions]
40
+ old_config = NulogyMessageBusProducer.config
41
+
42
+ NulogyMessageBusProducer.config = NulogyMessageBusProducer::Config.new
43
+ NulogyMessageBusProducer.config.register_schema(
44
+ schema: "NulogyMessageBusProducer::Specs::TestSchema",
45
+ key: "test"
46
+ )
47
+
48
+ example.run
49
+
50
+ NulogyMessageBusProducer.config = old_config
51
+ else
52
+ example.run
53
+ end
54
+ end
35
55
  end
@@ -28,4 +28,4 @@ class KafkaConnect
28
28
  response = @http.request(request)
29
29
  JSON.parse(response.body, symbolize_names: true)
30
30
  end
31
- end
31
+ end
@@ -1,19 +1,37 @@
1
1
  module SubscriptionHelpers
2
- def subscribe_to(
2
+ def self_serve_subscription(
3
3
  schema: NulogyMessageBusProducer::Specs::TestSchema,
4
4
  subscription_id: SecureRandom.uuid,
5
5
  **query_args
6
6
  )
7
7
  gql = subscription_query(subscription_id: subscription_id, **query_args)
8
8
 
9
- expect do
9
+ expect {
10
10
  gql_response = execute_graphql(gql, schema)
11
11
  expect(gql_response).to eq(data: {})
12
- end.to change(NulogyMessageBusProducer::Subscription, :count).by(1)
12
+ }.to change(NulogyMessageBusProducer::Subscription, :count).by(1)
13
13
 
14
14
  NulogyMessageBusProducer::Subscription.find(subscription_id)
15
15
  end
16
16
 
17
+ def configured_subscription(
18
+ schema: NulogyMessageBusProducer::Specs::TestSchema,
19
+ subscription_id: SecureRandom.uuid,
20
+ subscription_group_id: SecureRandom.uuid,
21
+ **query_args
22
+ )
23
+ gql = subscription_query(
24
+ subscription_id: subscription_id,
25
+ subscription_group_id: subscription_group_id,
26
+ **query_args
27
+ )
28
+
29
+ NulogyMessageBusProducer.config.add_subscription!(
30
+ schema: schema.name,
31
+ query: gql
32
+ )
33
+ end
34
+
17
35
  def subscription_query(
18
36
  event_type: "testCreated",
19
37
  query: "foo { id }",
@@ -29,8 +29,14 @@ module NulogyMessageBusProducer
29
29
  field :foo_list, [TestObject], null: false
30
30
  end
31
31
 
32
+ class TestUpdated < NulogyMessageBusProducer::BaseSubscription
33
+ field :foo, TestObject, null: false
34
+ field :foo_list, [TestObject], null: false
35
+ end
36
+
32
37
  class TestSubscription < GraphQL::Schema::Object
33
38
  field :test_created, subscription: TestCreated
39
+ field :test_updated, subscription: TestCreated
34
40
  end
35
41
 
36
42
  class TestSchema < GraphQL::Schema
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nulogy_message_bus_producer
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.3.0
4
+ version: 3.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nulogy
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-11-19 00:00:00.000000000 Z
11
+ date: 2021-03-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: graphql
@@ -114,14 +114,14 @@ dependencies:
114
114
  requirements:
115
115
  - - '='
116
116
  - !ruby/object:Gem::Version
117
- version: 1.2.1
117
+ version: 1.3.0
118
118
  type: :development
119
119
  prerelease: false
120
120
  version_requirements: !ruby/object:Gem::Requirement
121
121
  requirements:
122
122
  - - '='
123
123
  - !ruby/object:Gem::Version
124
- version: 1.2.1
124
+ version: 1.3.0
125
125
  - !ruby/object:Gem::Dependency
126
126
  name: rdkafka
127
127
  requirement: !ruby/object:Gem::Requirement
@@ -165,33 +165,19 @@ dependencies:
165
165
  - !ruby/object:Gem::Version
166
166
  version: 4.0.1
167
167
  - !ruby/object:Gem::Dependency
168
- name: rubocop
168
+ name: standard
169
169
  requirement: !ruby/object:Gem::Requirement
170
170
  requirements:
171
171
  - - '='
172
172
  - !ruby/object:Gem::Version
173
- version: 0.85.1
173
+ version: 0.11.0
174
174
  type: :development
175
175
  prerelease: false
176
176
  version_requirements: !ruby/object:Gem::Requirement
177
177
  requirements:
178
178
  - - '='
179
179
  - !ruby/object:Gem::Version
180
- version: 0.85.1
181
- - !ruby/object:Gem::Dependency
182
- name: rubocop-performance
183
- requirement: !ruby/object:Gem::Requirement
184
- requirements:
185
- - - '='
186
- - !ruby/object:Gem::Version
187
- version: 1.6.1
188
- type: :development
189
- prerelease: false
190
- version_requirements: !ruby/object:Gem::Requirement
191
- requirements:
192
- - - '='
193
- - !ruby/object:Gem::Version
194
- version: 1.6.1
180
+ version: 0.11.0
195
181
  - !ruby/object:Gem::Dependency
196
182
  name: rubocop-rails
197
183
  requirement: !ruby/object:Gem::Requirement
@@ -235,13 +221,15 @@ files:
235
221
  - lib/nulogy_message_bus_producer/application_record.rb
236
222
  - lib/nulogy_message_bus_producer/base_subscription.rb
237
223
  - lib/nulogy_message_bus_producer/config.rb
224
+ - lib/nulogy_message_bus_producer/configuration/query_parser.rb
238
225
  - lib/nulogy_message_bus_producer/engine.rb
239
226
  - lib/nulogy_message_bus_producer/repopulate_replication_slots.rb
240
- - lib/nulogy_message_bus_producer/subscriber_graphql_schema_validator.rb
241
227
  - lib/nulogy_message_bus_producer/subscription.rb
242
228
  - lib/nulogy_message_bus_producer/subscription_event.rb
229
+ - lib/nulogy_message_bus_producer/subscriptions/finder.rb
243
230
  - lib/nulogy_message_bus_producer/subscriptions/no_variables.rb
244
231
  - lib/nulogy_message_bus_producer/subscriptions/postgres_transport.rb
232
+ - lib/nulogy_message_bus_producer/subscriptions/query_validator.rb
245
233
  - lib/nulogy_message_bus_producer/subscriptions/risky_subscription_blocker.rb
246
234
  - lib/nulogy_message_bus_producer/version.rb
247
235
  - lib/tasks/engine/message_bus_producer.rake
@@ -291,6 +279,8 @@ files:
291
279
  - spec/dummy/config/spring.rb
292
280
  - spec/dummy/db/migrate/20201005164116_create_active_storage_tables.active_storage.rb
293
281
  - spec/dummy/db/schema.rb
282
+ - spec/dummy/log/development.log
283
+ - spec/dummy/log/test.log
294
284
  - spec/dummy/package.json
295
285
  - spec/dummy/public/404.html
296
286
  - spec/dummy/public/422.html
@@ -298,13 +288,16 @@ files:
298
288
  - spec/dummy/public/apple-touch-icon-precomposed.png
299
289
  - spec/dummy/public/apple-touch-icon.png
300
290
  - spec/dummy/public/favicon.ico
291
+ - spec/integration/lib/nulogy_message_bus_producer/config_spec.rb
301
292
  - spec/integration/lib/nulogy_message_bus_producer/repopulate_replication_slots_spec.rb
302
- - spec/integration/lib/nulogy_message_bus_producer/subscriber_graphql_schema_validator_spec.rb
303
293
  - spec/integration/lib/nulogy_message_bus_producer/subscription_spec.rb
294
+ - spec/integration/lib/nulogy_message_bus_producer/subscriptions/finder_spec.rb
304
295
  - spec/integration/lib/nulogy_message_bus_producer/subscriptions/no_variables_spec.rb
305
296
  - spec/integration/lib/nulogy_message_bus_producer/subscriptions/postgres_transport_spec.rb
297
+ - spec/integration/lib/nulogy_message_bus_producer/subscriptions/query_validator_spec.rb
306
298
  - spec/integration/lib/nulogy_message_bus_producer/subscriptions/risky_subscription_blocker_spec.rb
307
299
  - spec/integration_spec_helper.rb
300
+ - spec/nulogy_message_bus_producer/configuration/query_parser_spec.rb
308
301
  - spec/spec_helper.rb
309
302
  - spec/support/kafka.rb
310
303
  - spec/support/kafka_connect.rb
@@ -330,7 +323,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
330
323
  - !ruby/object:Gem::Version
331
324
  version: '0'
332
325
  requirements: []
333
- rubygems_version: 3.0.8
326
+ rubygems_version: 3.0.3
334
327
  signing_key:
335
328
  specification_version: 4
336
329
  summary: Nulogy's code for producing to the Message Bus
@@ -389,16 +382,21 @@ test_files:
389
382
  - spec/dummy/package.json
390
383
  - spec/dummy/db/schema.rb
391
384
  - spec/dummy/db/migrate/20201005164116_create_active_storage_tables.active_storage.rb
385
+ - spec/dummy/log/test.log
386
+ - spec/dummy/log/development.log
392
387
  - spec/integration_spec_helper.rb
393
388
  - spec/integration/lib/nulogy_message_bus_producer/repopulate_replication_slots_spec.rb
389
+ - spec/integration/lib/nulogy_message_bus_producer/config_spec.rb
394
390
  - spec/integration/lib/nulogy_message_bus_producer/subscriptions/risky_subscription_blocker_spec.rb
391
+ - spec/integration/lib/nulogy_message_bus_producer/subscriptions/finder_spec.rb
395
392
  - spec/integration/lib/nulogy_message_bus_producer/subscriptions/postgres_transport_spec.rb
393
+ - spec/integration/lib/nulogy_message_bus_producer/subscriptions/query_validator_spec.rb
396
394
  - spec/integration/lib/nulogy_message_bus_producer/subscriptions/no_variables_spec.rb
397
395
  - spec/integration/lib/nulogy_message_bus_producer/subscription_spec.rb
398
- - spec/integration/lib/nulogy_message_bus_producer/subscriber_graphql_schema_validator_spec.rb
399
396
  - spec/support/kafka_connect.rb
400
397
  - spec/support/subscription_helpers.rb
401
398
  - spec/support/kafka.rb
402
399
  - spec/support/spec_utils.rb
403
400
  - spec/support/sql_helpers.rb
404
401
  - spec/support/test_graphql_schema.rb
402
+ - spec/nulogy_message_bus_producer/configuration/query_parser_spec.rb
@@ -1,45 +0,0 @@
1
- module NulogyMessageBusProducer
2
- # A custom validator that checks that the provided (or all) subscriptions have a query that is valid for its
3
- # configured schema. Schemas must be registered with a `schema_key`, that is persisted in the database.
4
- # It ties the subscription to a particular schema.
5
- #
6
- # This validator is run as part of an initializer as a last ditch effort to verify that the stored queries in the
7
- # database are valid against the deployed schema, so that when events are generated in the system, they are always
8
- # sucessfully created.
9
- class SubscriberGraphqlSchemaValidator
10
- attr_reader :errors
11
-
12
- def initialize
13
- @errors = []
14
- end
15
-
16
- def validate(subscription_or_subscriptions = NulogyMessageBusProducer::Subscription.all)
17
- Array(subscription_or_subscriptions).each do |subscription|
18
- schema = find_schema(subscription)
19
- next unless schema
20
-
21
- gql_errors = schema.validate(subscription.query)
22
- errors = gql_errors.map { |e| "#{e.message} #{display_id(subscription.id)}" }
23
-
24
- @errors.concat(errors)
25
- end
26
-
27
- @errors.empty?
28
- end
29
-
30
- private
31
-
32
- def find_schema(subscription)
33
- NulogyMessageBusProducer.resolve_schema(subscription.schema_key) do
34
- @errors << "Could not find a schema for schema_key '#{subscription.schema_key}' #{display_id(subscription.id)}"
35
- nil
36
- end
37
- end
38
-
39
- def display_id(id)
40
- normalized = id.presence || "<new_record>"
41
-
42
- "(id: #{normalized})"
43
- end
44
- end
45
- end