Sha256: f2c0b1bf18a1808058d2c09cf30c9e25588aca7b2e228ab3dffe72b1510c301c
Contents?: true
Size: 1.48 KB
Versions: 6
Compression:
Stored size: 1.48 KB
Contents
module NulogyMessageBusProducer # A custom validator that checks that the provided (or all) subscriptions have a query that is valid for its # configured schema. Schemas must be registered with a `schema_key`, that is persisted in the database. # It ties the subscription to a particular schema. # # This validator is run as part of an initializer as a last ditch effort to verify that the stored queries in the # database are valid against the deployed schema, so that when events are generated in the system, they are always # sucessfully created. class SubscriberGraphqlSchemaValidator attr_reader :errors def initialize @errors = [] end def validate(subscription_or_subscriptions = NulogyMessageBusProducer::PublicSubscription.all) Array(subscription_or_subscriptions).each do |subscription| schema = find_schema(subscription) next unless schema gql_errors = schema.validate(subscription.query) errors = gql_errors.map { |e| "#{e.message} #{display_id(subscription.id)}" } @errors.concat(errors) end @errors.empty? end private def find_schema(subscription) NulogyMessageBusProducer.resolve_schema(subscription.schema_key) do @errors << "Could not find a schema for schema_key '#{subscription.schema_key}' #{display_id(subscription.id)}" nil end end def display_id(id) normalized = id.presence || "<new_record>" "(id: #{normalized})" end end end
Version data entries
6 entries across 6 versions & 1 rubygems