Sha256: 59b60fe69fcbb774ac47639a0aa3419fa8eee796fa3eadcf40f93f57974b8e04

Contents?: true

Size: 1.63 KB

Versions: 12

Compression:

Stored size: 1.63 KB

Contents

require "spec_helper"

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


  describe "validation order" do
    let(:document) { GraphQL.parse(query_string)}

    describe "fields & arguments" do
      let(:query_string) { %|
        query getCheese($id: Int!) {
          cheese(id: $undefinedVar, bogusArg: true) {
            source,
            nonsenseField,
            id(nonsenseArg: 1)
            bogusField(bogusArg: true)
          }

          otherCheese: cheese(id: $id) {
            source,
          }
        }
      |}

      it "handles args on invalid fields" do
        # nonsenseField, nonsenseArg, bogusField, bogusArg, undefinedVar
        assert_equal(5, errors.length)
      end
    end

    describe "infinite fragments" do
      let(:query_string) { %|
        query getCheese {
          cheese(id: 1) {
            ... cheeseFields
          }
        }
        fragment cheeseFields on Cheese {
          id, ... cheeseFields
        }
      |}

      it "handles infinite fragment spreads" do
        assert_equal(1, errors.length)
      end
    end

    describe "fragment spreads with no selections" do
      let(:query_string) {%|
        query SimpleQuery {
          cheese(id: 1) {
            # OK:
            ... {
              id
            }
            # NOT OK:
            ...cheeseFields
          }
        }
      |}
      it "marks an error" do
        assert_equal(1, errors.length)
      end
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
graphql-0.18.6 spec/graphql/static_validation/validator_spec.rb
graphql-0.18.5 spec/graphql/static_validation/validator_spec.rb
graphql-0.18.4 spec/graphql/static_validation/validator_spec.rb
graphql-0.18.3 spec/graphql/static_validation/validator_spec.rb
graphql-0.18.2 spec/graphql/static_validation/validator_spec.rb
graphql-0.18.1 spec/graphql/static_validation/validator_spec.rb
graphql-0.18.0 spec/graphql/static_validation/validator_spec.rb
graphql-0.17.2 spec/graphql/static_validation/validator_spec.rb
graphql-0.17.1 spec/graphql/static_validation/validator_spec.rb
graphql-0.17.0 spec/graphql/static_validation/validator_spec.rb
graphql-0.16.1 spec/graphql/static_validation/validator_spec.rb
graphql-0.16.0 spec/graphql/static_validation/validator_spec.rb