Sha256: 51ad59703406b42e3e440bf2e11d802cdcba0828a1fba9bbf50a8ff0d4cf93c9

Contents?: true

Size: 1.62 KB

Versions: 15

Compression:

Stored size: 1.62 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)[:errors] }

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

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
graphql-0.18.14 spec/graphql/static_validation/rules/variable_default_values_are_correctly_typed_spec.rb
graphql-0.18.13 spec/graphql/static_validation/rules/variable_default_values_are_correctly_typed_spec.rb
graphql-0.18.12 spec/graphql/static_validation/rules/variable_default_values_are_correctly_typed_spec.rb
graphql-0.18.11 spec/graphql/static_validation/rules/variable_default_values_are_correctly_typed_spec.rb
graphql-0.18.10 spec/graphql/static_validation/rules/variable_default_values_are_correctly_typed_spec.rb
graphql-0.18.9 spec/graphql/static_validation/rules/variable_default_values_are_correctly_typed_spec.rb
graphql-0.18.8 spec/graphql/static_validation/rules/variable_default_values_are_correctly_typed_spec.rb
graphql-0.18.7 spec/graphql/static_validation/rules/variable_default_values_are_correctly_typed_spec.rb
graphql-0.18.6 spec/graphql/static_validation/rules/variable_default_values_are_correctly_typed_spec.rb
graphql-0.18.5 spec/graphql/static_validation/rules/variable_default_values_are_correctly_typed_spec.rb
graphql-0.18.4 spec/graphql/static_validation/rules/variable_default_values_are_correctly_typed_spec.rb
graphql-0.18.3 spec/graphql/static_validation/rules/variable_default_values_are_correctly_typed_spec.rb
graphql-0.18.2 spec/graphql/static_validation/rules/variable_default_values_are_correctly_typed_spec.rb
graphql-0.18.1 spec/graphql/static_validation/rules/variable_default_values_are_correctly_typed_spec.rb
graphql-0.18.0 spec/graphql/static_validation/rules/variable_default_values_are_correctly_typed_spec.rb