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