Sha256: 4e0ba82d692b0d9529896c894519c644f304f93c16d8207573aec3f0fe5d2138

Contents?: true

Size: 1.46 KB

Versions: 2

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"=>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

2 entries across 2 versions & 1 rubygems

Version Path
graphql-0.12.1 spec/graphql/static_validation/rules/variable_default_values_are_correctly_typed_spec.rb
graphql-0.12.0 spec/graphql/static_validation/rules/variable_default_values_are_correctly_typed_spec.rb