Sha256: 72bd847e3bd5aa5202b8168b4238fbf56e29a577938aca408155478bfe4437b8

Contents?: true

Size: 954 Bytes

Versions: 8

Compression:

Stored size: 954 Bytes

Contents

require "spec_helper"

class TypeCheckValidator
  def self.checks
    @checks ||= []
  end

  def validate(context)
    self.class.checks.clear
    context.visitor[GraphQL::Language::Nodes::Field] << ->(node, parent) {
      self.class.checks << context.object_types.map {|t| t.name || t.kind.name }
    }
  end
end

describe GraphQL::StaticValidation::TypeStack do
  let(:query_string) {%|
    query getCheese {
      cheese(id: 1) { id, ... edibleFields }
    }
    fragment edibleFields on Edible { fatContent @skip(if: false)}
  |}

  let(:validator) { GraphQL::StaticValidation::Validator.new(schema: DummySchema, rules: [TypeCheckValidator]) }
  let(:query) { GraphQL::Query.new(DummySchema, query_string) }


  it "stores up types" do
    validator.validate(query)
    expected = [
      ["Query", "Cheese"],
      ["Query", "Cheese", "NON_NULL"],
      ["Edible", "NON_NULL"]
    ]
    assert_equal(expected, TypeCheckValidator.checks)
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
graphql-1.2.6 spec/graphql/static_validation/type_stack_spec.rb
graphql-1.2.5 spec/graphql/static_validation/type_stack_spec.rb
graphql-1.2.4 spec/graphql/static_validation/type_stack_spec.rb
graphql-1.2.3 spec/graphql/static_validation/type_stack_spec.rb
graphql-1.2.2 spec/graphql/static_validation/type_stack_spec.rb
graphql-1.2.1 spec/graphql/static_validation/type_stack_spec.rb
graphql-1.2.0 spec/graphql/static_validation/type_stack_spec.rb
graphql-1.1.0 spec/graphql/static_validation/type_stack_spec.rb