Sha256: 5ce7c7156aab52915a9aa511ba992455b54cb9640181a70422716364a6e95cbf

Contents?: true

Size: 820 Bytes

Versions: 9

Compression:

Stored size: 820 Bytes

Contents

# This module assumes you have `let(:query_string)` in your spec.
# It provides `errors` which are the validation errors for that string,
# as validated against `DummySchema`.
# You can override `schema` to provide another schema
# @example testing static validation
#   include StaticValidationHelpers
#   let(:query_string) { " ... " }
#   it "validates" do
#     assert_equal(errors, [ ... ])
#     assert_equal(error_messages, [ ... ])
#   end
module StaticValidationHelpers
  def errors
    target_schema = schema
    validator = GraphQL::StaticValidation::Validator.new(schema: target_schema)
    query = GraphQL::Query.new(target_schema, query_string)
    validator.validate(query)[:errors].map(&:to_h)
  end

  def error_messages
    errors.map { |e| e["message"] }
  end

  def schema
    DummySchema
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
graphql-1.2.6 spec/support/static_validation_helpers.rb
graphql-1.2.5 spec/support/static_validation_helpers.rb
graphql-1.2.4 spec/support/static_validation_helpers.rb
graphql-1.2.3 spec/support/static_validation_helpers.rb
graphql-1.2.2 spec/support/static_validation_helpers.rb
graphql-1.2.1 spec/support/static_validation_helpers.rb
graphql-1.2.0 spec/support/static_validation_helpers.rb
graphql-1.1.0 spec/support/static_validation_helpers.rb
graphql-1.0.0 spec/support/static_validation_helpers.rb