Sha256: 98ee5470b52f9037c02767f9c3cde22f4a3119f352b730578ab7a3f6835cba97

Contents?: true

Size: 1.46 KB

Versions: 8

Compression:

Stored size: 1.46 KB

Contents

require "spec_helper"

describe GraphQL::StaticValidation::VariableDefaultValuesAreCorrectlyTyped do
  let(:query_string) {%|
    query getCheese(
      $id:        Int = 1,
      $int:       Int = 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(:query) { GraphQL::Query.new(DummySchema, query_string) }
  let(:errors) { validator.validate(query) }

  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"=>7}]
      },
      {
        "message"=>"Default value for $badInt doesn't match type Int",
        "locations"=>[{"line"=>7, "column"=>7}]
      },
      {
        "message"=>"Default value for $badInput doesn't match type DairyProductInput",
        "locations"=>[{"line"=>9, "column"=>7}]
      },
      {
        "message"=>"Non-null variable $nonNull can't have a default value",
        "locations"=>[{"line"=>10, "column"=>7}]
      }
    ]
    assert_equal(expected, errors)
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
graphql-0.15.3 spec/graphql/static_validation/rules/variable_default_values_are_correctly_typed_spec.rb
graphql-0.15.2 spec/graphql/static_validation/rules/variable_default_values_are_correctly_typed_spec.rb
graphql-0.14.2 spec/graphql/static_validation/rules/variable_default_values_are_correctly_typed_spec.rb
graphql-0.15.1 spec/graphql/static_validation/rules/variable_default_values_are_correctly_typed_spec.rb
graphql-0.15.0 spec/graphql/static_validation/rules/variable_default_values_are_correctly_typed_spec.rb
graphql-0.14.1 spec/graphql/static_validation/rules/variable_default_values_are_correctly_typed_spec.rb
graphql-0.14.0 spec/graphql/static_validation/rules/variable_default_values_are_correctly_typed_spec.rb
graphql-0.13.0 spec/graphql/static_validation/rules/variable_default_values_are_correctly_typed_spec.rb