Sha256: 1c64deb8b20c13f6c49282d15e9ef4471ca9801aae55b4cdaa45e58b67f7258f

Contents?: true

Size: 1.4 KB

Versions: 15

Compression:

Stored size: 1.4 KB

Contents

require "spec_helper"

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

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

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

  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}],
      "path"=>["query getCheese", "cheese"],
    }
    assert_includes(errors, query_root_error)

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

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

Version data entries

15 entries across 15 versions & 1 rubygems

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