Sha256: 255131acd9a682bdd77894d47bdc087fb78e85a2e80c897bc35062453d1a9f13

Contents?: true

Size: 1.2 KB

Versions: 12

Compression:

Stored size: 1.2 KB

Contents

require 'spec_helper'

describe GraphQL::StaticValidation::RequiredArgumentsArePresent do
  let(:document) { GraphQL.parse("
    query getCheese {
      cheese(id: 1) { source }
      cheese { source }
    }

    fragment cheeseFields on Cheese {
      similarCheeses(id: 1)
      flavor @include(if: true)
      id @skip
    }
  ")}

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

  it 'finds undefined arguments to fields and directives' do
    assert_equal(3, errors.length)

    query_root_error = {
      "message"=>"Field 'cheese' is missing required arguments: id",
      "locations"=>[{"line"=>4, "column"=>7}]
    }
    assert_includes(errors, query_root_error)

    fragment_error = {
      "message"=>"Field 'similarCheeses' is missing required arguments: source",
      "locations"=>[{"line"=>8, "column"=>7}]
    }
    assert_includes(errors, fragment_error)

    directive_error = {
      "message"=>"Directive 'skip' is missing required arguments: if",
      "locations"=>[{"line"=>10, "column"=>11}]
    }
    assert_includes(errors, directive_error)
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
graphql-0.9.3 spec/graphql/static_validation/rules/required_arguments_are_present_spec.rb
graphql-0.9.2 spec/graphql/static_validation/rules/required_arguments_are_present_spec.rb
graphql-0.8.1 spec/graphql/static_validation/rules/required_arguments_are_present_spec.rb
graphql-0.8.0 spec/graphql/static_validation/rules/required_arguments_are_present_spec.rb
graphql-0.7.1 spec/graphql/static_validation/rules/required_arguments_are_present_spec.rb
graphql-0.7.0 spec/graphql/static_validation/rules/required_arguments_are_present_spec.rb
graphql-0.6.2 spec/graphql/static_validation/rules/required_arguments_are_present_spec.rb
graphql-0.6.1 spec/graphql/static_validation/rules/required_arguments_are_present_spec.rb
graphql-0.6.0 spec/graphql/static_validation/rules/required_arguments_are_present_spec.rb
graphql-0.5.0 spec/graph_ql/static_validation/rules/required_arguments_are_present_spec.rb
graphql-0.4.0 spec/graph_ql/static_validation/rules/required_arguments_are_present_spec.rb
graphql-0.3.0 spec/graph_ql/static_validation/rules/required_arguments_are_present_spec.rb