Sha256: 1defb6438e3d64e30c9e180bd5389d9a7ed33de34d3daac1e7dd4655ad988b34

Contents?: true

Size: 1.42 KB

Versions: 26

Compression:

Stored size: 1.42 KB

Contents

require 'spec_helper'

describe GraphQL::StaticValidation::VariableDefaultValuesAreCorrectlyTyped do
  let(:document) { GraphQL.parse('
    query getCheese(
      $id:        Int = 1,
      $bool:      Boolean = 3.4e24, # can be coerced
      $str:       String!,
      $badFloat:  Float = true,
      $badInt:    Int = "abc",
      $input:     DairyProductInput = {source: YAK, fatContent: 1},
      $badInput:  DairyProductInput = {source: YAK, fatContent: true},
      $nonNull:  Int! = 1,
    ) {
      cheese(id: $id) { source }
    }
  ')}

  let(:validator) { GraphQL::StaticValidation::Validator.new(schema: DummySchema, rules: [GraphQL::StaticValidation::VariableDefaultValuesAreCorrectlyTyped]) }
  let(:errors) { validator.validate(document) }

  it "finds default values that don't match their types" do
    expected = [
      {
        "message"=>"Default value for $badFloat doesn't match type Float",
        "locations"=>[{"line"=>6, "column"=>8}]
      },
      {
        "message"=>"Default value for $badInt doesn't match type Int",
        "locations"=>[{"line"=>7, "column"=>8}]
      },
      {
        "message"=>"Default value for $badInput doesn't match type DairyProductInput",
        "locations"=>[{"line"=>9, "column"=>8}]
      },
      {
        "message"=>"Non-null variable $nonNull can't have a default value",
        "locations"=>[{"line"=>10, "column"=>8}]
      }
    ]
    assert_equal(expected, errors)
  end
end

Version data entries

26 entries across 26 versions & 1 rubygems

Version Path
graphql-0.11.1 spec/graphql/static_validation/rules/variable_default_values_are_correctly_typed_spec.rb
graphql-0.11.0 spec/graphql/static_validation/rules/variable_default_values_are_correctly_typed_spec.rb
graphql-0.10.9 spec/graphql/static_validation/rules/variable_default_values_are_correctly_typed_spec.rb
graphql-0.10.8 spec/graphql/static_validation/rules/variable_default_values_are_correctly_typed_spec.rb
graphql-0.10.7 spec/graphql/static_validation/rules/variable_default_values_are_correctly_typed_spec.rb
graphql-0.10.6 spec/graphql/static_validation/rules/variable_default_values_are_correctly_typed_spec.rb
graphql-0.10.5 spec/graphql/static_validation/rules/variable_default_values_are_correctly_typed_spec.rb
graphql-0.10.4 spec/graphql/static_validation/rules/variable_default_values_are_correctly_typed_spec.rb
graphql-0.10.3 spec/graphql/static_validation/rules/variable_default_values_are_correctly_typed_spec.rb
graphql-0.10.2 spec/graphql/static_validation/rules/variable_default_values_are_correctly_typed_spec.rb
graphql-0.10.1 spec/graphql/static_validation/rules/variable_default_values_are_correctly_typed_spec.rb
graphql-0.10.0 spec/graphql/static_validation/rules/variable_default_values_are_correctly_typed_spec.rb
graphql-0.9.5 spec/graphql/static_validation/rules/variable_default_values_are_correctly_typed_spec.rb
graphql-0.9.4 spec/graphql/static_validation/rules/variable_default_values_are_correctly_typed_spec.rb
graphql-0.9.3 spec/graphql/static_validation/rules/variable_default_values_are_correctly_typed_spec.rb
graphql-0.9.2 spec/graphql/static_validation/rules/variable_default_values_are_correctly_typed_spec.rb
graphql-0.8.1 spec/graphql/static_validation/rules/variable_default_values_are_correctly_typed_spec.rb
graphql-0.8.0 spec/graphql/static_validation/rules/variable_default_values_are_correctly_typed_spec.rb
graphql-0.7.1 spec/graphql/static_validation/rules/variable_default_values_are_correctly_typed_spec.rb
graphql-0.7.0 spec/graphql/static_validation/rules/variable_default_values_are_correctly_typed_spec.rb