Sha256: 74f0432a1491ad478dec680ed990f2b1d92054b62b9250353465f55e35602c61

Contents?: true

Size: 1.83 KB

Versions: 70

Compression:

Stored size: 1.83 KB

Contents

# frozen_string_literal: true
require "spec_helper"

describe GraphQL::StaticValidation::OperationNamesAreValid do
  include StaticValidationHelpers

  describe "when there are multiple operations" do
    let(:query_string) { <<-GRAPHQL
    query getCheese {
      cheese(id: 1) { flavor }
    }

    {
      cheese(id: 2) { flavor }
    }

    {
      cheese(id: 3) { flavor }
    }
    GRAPHQL
    }

    it "must have operation names" do
      assert_equal 1, errors.length
      requires_name_error = {
        "message"=>"Operation name is required when multiple operations are present",
        "locations"=>[{"line"=>5, "column"=>5}, {"line"=>9, "column"=>5}],
        "fields"=>[],
      }
      assert_includes(errors, requires_name_error)
    end
  end

  describe "when there are only unnamed operations" do
    let(:query_string) { <<-GRAPHQL
    {
      cheese(id: 2) { flavor }
    }

    {
      cheese(id: 3) { flavor }
    }
    GRAPHQL
    }

    it "requires names" do
      assert_equal 1, errors.length
      requires_name_error = {
        "message"=>"Operation name is required when multiple operations are present",
        "locations"=>[{"line"=>1, "column"=>5}, {"line"=>5, "column"=>5}],
        "fields"=>[],
      }
      assert_includes(errors, requires_name_error)
    end
  end

  describe "when multiple operations have names" do
    let(:query_string) { <<-GRAPHQL
    query getCheese {
      cheese(id: 1) { flavor }
    }

    query getCheese {
      cheese(id: 2) { flavor }
    }
    GRAPHQL
    }

    it "must be unique" do
      assert_equal 1, errors.length
      name_uniqueness_error = {
        "message"=>'Operation name "getCheese" must be unique',
        "locations"=>[{"line"=>1, "column"=>5}, {"line"=>5, "column"=>5}],
        "fields"=>[],
      }
      assert_includes(errors, name_uniqueness_error)
    end
  end
end

Version data entries

70 entries across 70 versions & 1 rubygems

Version Path
graphql-1.8.18 spec/graphql/static_validation/rules/operation_names_are_valid_spec.rb
graphql-1.8.17 spec/graphql/static_validation/rules/operation_names_are_valid_spec.rb
graphql-1.8.16 spec/graphql/static_validation/rules/operation_names_are_valid_spec.rb
graphql-1.8.15 spec/graphql/static_validation/rules/operation_names_are_valid_spec.rb
graphql-1.8.14 spec/graphql/static_validation/rules/operation_names_are_valid_spec.rb
graphql-1.8.13 spec/graphql/static_validation/rules/operation_names_are_valid_spec.rb
graphql-1.8.12 spec/graphql/static_validation/rules/operation_names_are_valid_spec.rb
graphql-1.9.0.pre1 spec/graphql/static_validation/rules/operation_names_are_valid_spec.rb
graphql-1.8.11 spec/graphql/static_validation/rules/operation_names_are_valid_spec.rb
graphql-1.8.10 spec/graphql/static_validation/rules/operation_names_are_valid_spec.rb
graphql-1.8.9 spec/graphql/static_validation/rules/operation_names_are_valid_spec.rb
graphql-1.8.8 spec/graphql/static_validation/rules/operation_names_are_valid_spec.rb
graphql-1.8.7 spec/graphql/static_validation/rules/operation_names_are_valid_spec.rb
graphql-1.8.6 spec/graphql/static_validation/rules/operation_names_are_valid_spec.rb
graphql-1.8.5 spec/graphql/static_validation/rules/operation_names_are_valid_spec.rb
graphql-1.8.4 spec/graphql/static_validation/rules/operation_names_are_valid_spec.rb
graphql-1.8.3 spec/graphql/static_validation/rules/operation_names_are_valid_spec.rb
graphql-1.8.2 spec/graphql/static_validation/rules/operation_names_are_valid_spec.rb
graphql-1.8.1 spec/graphql/static_validation/rules/operation_names_are_valid_spec.rb
graphql-1.8.0 spec/graphql/static_validation/rules/operation_names_are_valid_spec.rb