From 42af6a4262defb3a389876d48a38e5ea1300f8d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Samuel=20Brand=C3=A3o?= Date: Sun, 16 Apr 2023 16:03:46 -0300 Subject: [PATCH 1/7] Update BeOfType#failure_message with 2.0 compatibility On 2.0, the implicit string conversion does not yield the type signature string. --- lib/rspec/graphql_matchers/be_of_type.rb | 2 +- spec/rspec/readme_spec.rb | 6 ------ 2 files changed, 1 insertion(+), 7 deletions(-) diff --git a/lib/rspec/graphql_matchers/be_of_type.rb b/lib/rspec/graphql_matchers/be_of_type.rb index 2f858e1..c47e0a3 100644 --- a/lib/rspec/graphql_matchers/be_of_type.rb +++ b/lib/rspec/graphql_matchers/be_of_type.rb @@ -17,7 +17,7 @@ def matches?(actual_sample) end def failure_message - "expected field '#{member_name(sample)}' to be of type '#{expected}', " \ + "expected field '#{member_name(sample)}' to be of type '#{type_name(expected)}', " \ "but it was '#{type_name(sample.type)}'" end diff --git a/spec/rspec/readme_spec.rb b/spec/rspec/readme_spec.rb index f355389..ab9d8fd 100644 --- a/spec/rspec/readme_spec.rb +++ b/spec/rspec/readme_spec.rb @@ -11,12 +11,6 @@ ) ) - before do - GraphQL::Field.accepts_definitions( - admin_only: GraphQL::Define.assign_metadata_key(:admin_only) - ) - end - # rubocop:disable Security/Eval readme_content.scan(ruby_code_regex) do |ruby_code| eval(ruby_code[0]) From cd940d239a02bbb87268ee89d389f497a34922cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Samuel=20Brand=C3=A3o?= Date: Sun, 16 Apr 2023 16:05:28 -0300 Subject: [PATCH 2/7] be_of_type matcher specs is 2.0 compatible --- spec/rspec/be_of_type_matcher_spec.rb | 34 +++++++++++++++++---------- 1 file changed, 22 insertions(+), 12 deletions(-) diff --git a/spec/rspec/be_of_type_matcher_spec.rb b/spec/rspec/be_of_type_matcher_spec.rb index a2aa2e4..2779bba 100644 --- a/spec/rspec/be_of_type_matcher_spec.rb +++ b/spec/rspec/be_of_type_matcher_spec.rb @@ -3,28 +3,38 @@ require 'spec_helper' describe 'expect(a_field).to be_of_type(graphql_type)' do - scalar_types = [types.Boolean, types.Int, types.Float, types.String, types.ID] - list_types = scalar_types.map { |t| types[t] } - all_types = scalar_types + scalar_types.map(&:'!') + list_types.map(&:'!') + scalar_types = { + "Boolean" => GraphQL::Types::Boolean, + "Int" => GraphQL::Types::Int, + "Float" => GraphQL::Types::Float, + "String" => GraphQL::Types::String, + "ID" => GraphQL::Types::ID + } + + non_nullable_scalar_types = scalar_types.each_with_object({}) do |(string_name, type), result| + result["#{string_name}!"] = type.to_non_null_type + end + + all_types = scalar_types.merge(non_nullable_scalar_types) - all_types.each do |scalar_type| - context "when the field has type #{scalar_type}" do + all_types.each do |(graphql_name, scalar_type)| + context "when the field has type #{graphql_name}" do subject(:field) { double('GrahQL Field', type: field_type) } let(:field_type) { scalar_type } - it "matches a graphQL type object representing #{scalar_type}" do + it "matches a graphQL type object representing #{graphql_name}" do expect(field).to be_of_type(scalar_type) end - it "matches the string '#{scalar_type}'" do - expect(field).to be_of_type(scalar_type.to_s) + it "matches the string '#{graphql_name}'" do + expect(field).to be_of_type(graphql_name) end - it "does not match the string '#{scalar_type.to_s.downcase}'" do - expect(field).not_to be_of_type(scalar_type.to_s.downcase) + it "does not match the string '#{graphql_name.downcase}'" do + expect(field).not_to be_of_type(graphql_name.downcase) end - scalar_types.each do |another_scalar| + scalar_types.each do |(another_graphql_name, another_scalar)| next if another_scalar == scalar_type context "when matching against the type #{another_scalar}" do @@ -42,7 +52,7 @@ it 'informs the expected and actual types' do expect(failure_message).to end_with( - "to be of type '#{expected_type}', but it was '#{field.type}'" + "to be of type '#{another_graphql_name}', but it was '#{graphql_name}'" ) end From e312e43761fb33403626f7c4b962cccd9e8e622b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Samuel=20Brand=C3=A3o?= Date: Sun, 16 Apr 2023 16:34:38 -0300 Subject: [PATCH 3/7] Fixing existing matchers and tests for 2.0 compatibility --- README.md | 8 ++--- .../graphql_matchers/accept_arguments.rb | 2 +- lib/rspec/graphql_matchers/have_a_field.rb | 5 ++- .../have_a_field_matchers/of_type.rb | 2 +- lib/rspec/graphql_matchers/matchers.rb | 4 +-- spec/rspec/accept_argument_matcher_spec.rb | 4 +-- spec/rspec/accept_arguments_matcher_spec.rb | 32 +++++++++---------- spec/rspec/have_a_field_matcher_spec.rb | 27 ++++++++-------- spec/rspec/have_a_return_field_spec.rb | 25 +++++++-------- .../rspec/have_an_input_field_matcher_spec.rb | 25 +++++++-------- 10 files changed, 65 insertions(+), 69 deletions(-) diff --git a/README.md b/README.md index 062a499..f0474ed 100644 --- a/README.md +++ b/README.md @@ -44,9 +44,9 @@ class PostType < GraphQL::Schema::Object field :published, Boolean, null: false, deprecation_reason: 'Use isPublished instead' field :subposts, PostType, null: true do - argument :filter, types.String, required: false - argument :id, types.ID, required: false - argument :isPublished, types.Boolean, required: false + argument :filter, String, required: false + argument :id, ID, required: false + argument :isPublished, Boolean, required: false end end ``` @@ -57,7 +57,7 @@ end describe PostType do subject { described_class } - it { is_expected.to have_field(:id).of_type(!types.ID) } + it { is_expected.to have_field(:id).of_type("ID!") } it { is_expected.to have_field(:comments).of_type("[String!]!") } it { is_expected.to have_field(:isPublished).of_type("Boolean") } diff --git a/lib/rspec/graphql_matchers/accept_arguments.rb b/lib/rspec/graphql_matchers/accept_arguments.rb index 8bc45e6..5127326 100644 --- a/lib/rspec/graphql_matchers/accept_arguments.rb +++ b/lib/rspec/graphql_matchers/accept_arguments.rb @@ -40,7 +40,7 @@ def matches_argument?(arg_name, arg_type) def describe_arguments(what_args) what_args.sort.map do |arg_name, arg_type| - "#{arg_name}(#{arg_type})" + "#{arg_name}(#{type_name(arg_type)})" end.join(', ') end end diff --git a/lib/rspec/graphql_matchers/have_a_field.rb b/lib/rspec/graphql_matchers/have_a_field.rb index 4856893..af66997 100644 --- a/lib/rspec/graphql_matchers/have_a_field.rb +++ b/lib/rspec/graphql_matchers/have_a_field.rb @@ -103,9 +103,8 @@ def field_collection def matcher_name case @fields - when :fields then 'have_a_field' - when :input_fields then 'have_an_input_field' - when :return_fields then 'have_a_return_field' + when :fields then 'have_a_field' + when :arguments then 'have_an_input_field' end end diff --git a/lib/rspec/graphql_matchers/have_a_field_matchers/of_type.rb b/lib/rspec/graphql_matchers/have_a_field_matchers/of_type.rb index 052ba0b..22548cc 100644 --- a/lib/rspec/graphql_matchers/have_a_field_matchers/of_type.rb +++ b/lib/rspec/graphql_matchers/have_a_field_matchers/of_type.rb @@ -5,7 +5,7 @@ module GraphqlMatchers module HaveAFieldMatchers class OfType < RSpec::GraphqlMatchers::BeOfType def description - "of type `#{expected}`" + "of type `#{type_name(expected)}`" end def failure_message diff --git a/lib/rspec/graphql_matchers/matchers.rb b/lib/rspec/graphql_matchers/matchers.rb index a90ee12..4a67a9c 100644 --- a/lib/rspec/graphql_matchers/matchers.rb +++ b/lib/rspec/graphql_matchers/matchers.rb @@ -28,12 +28,12 @@ def have_a_field(field_name) alias have_field have_a_field def have_an_input_field(field_name) - RSpec::GraphqlMatchers::HaveAField.new(field_name, :input_fields) + RSpec::GraphqlMatchers::HaveAField.new(field_name, :arguments) end alias have_input_field have_an_input_field def have_a_return_field(field_name) - RSpec::GraphqlMatchers::HaveAField.new(field_name, :return_fields) + RSpec::GraphqlMatchers::HaveAField.new(field_name) end alias have_return_field have_a_return_field # rubocop:enable Naming/PredicateName diff --git a/spec/rspec/accept_argument_matcher_spec.rb b/spec/rspec/accept_argument_matcher_spec.rb index ae4203e..b4ebc04 100644 --- a/spec/rspec/accept_argument_matcher_spec.rb +++ b/spec/rspec/accept_argument_matcher_spec.rb @@ -79,13 +79,13 @@ module GraphqlMatchers 'of type `String!`, but it was `String`' ) - expect { expect(a_type).to accept_argument('other').of_type(!types.Int) } + expect { expect(a_type).to accept_argument('other').of_type(GraphQL::Types::Int.to_non_null_type) } .to fail_with( 'expected TestObject to accept argument `other` ' \ 'of type `Int!`, but it was `ID!`' ) - expect { expect(a_type).to accept_argument('other' => !types.Int) } + expect { expect(a_type).to accept_argument('other' => GraphQL::Types::Int.to_non_null_type) } .to fail_with( 'expected TestObject to accept argument `other` ' \ 'of type `Int!`, but it was `ID!`' diff --git a/spec/rspec/accept_arguments_matcher_spec.rb b/spec/rspec/accept_arguments_matcher_spec.rb index 233f182..3400cf4 100644 --- a/spec/rspec/accept_arguments_matcher_spec.rb +++ b/spec/rspec/accept_arguments_matcher_spec.rb @@ -18,37 +18,37 @@ describe '#matches?' do context 'when expecting a single argument with type' do - let(:expected_args) { { id: !types.ID } } + let(:expected_args) { { id: GraphQL::Types::ID.to_non_null_type } } context 'when the field accepts the expected argument name and type' do it { is_expected.to accept_arguments(expected_args) } end context 'the field accepts an argument with the same name but different type' do - let(:expected_args) { { id: types.ID } } + let(:expected_args) { { id: GraphQL::Types::ID } } it { is_expected.not_to accept_arguments(expected_args) } end context 'the field does not accept the expected args' do - let(:expected_args) { { idz: !types.ID } } + let(:expected_args) { { idz: GraphQL::Types::ID.to_non_null_type } } it { is_expected.not_to accept_arguments(expected_args) } end context 'when the expected argument is camelcase' do - let(:expected_args) { { isTest: types.Boolean } } + let(:expected_args) { { isTest: GraphQL::Types::Boolean } } it { is_expected.to accept_arguments(expected_args) } end context 'when the expected argument is underscored' do - let(:expected_args) { { is_test: types.Boolean } } + let(:expected_args) { { is_test: GraphQL::Types::Boolean } } it { is_expected.to accept_arguments(expected_args) } context 'when the actual argument is not camelized' do - let(:expected_args) { { not_camelized: types.Boolean } } + let(:expected_args) { { not_camelized: GraphQL::Types::Boolean } } it { is_expected.to accept_arguments(expected_args) } end @@ -59,9 +59,9 @@ context 'when the field accepts only one argument with correct name and type' do let(:expected_args) do { - id: !types.ID, - age: types[types.Int], - name: types.String + id: GraphQL::Types::ID.to_non_null_type, + age: GraphQL::Types::Int.to_list_type, + name: GraphQL::Types::String } end @@ -71,9 +71,9 @@ context 'when the field accepts all but one of the argument expected args' do let(:expected_args) do { - id: !types.ID, - age: types.Int, - name: !types.Float + id: GraphQL::Types::ID.to_non_null_type, + age: GraphQL::Types::Int, + name: GraphQL::Types::Float.to_non_null_type } end @@ -83,9 +83,9 @@ context 'when the field accepts all arguments with correct type' do let(:expected_args) do { - id: !types.ID, - age: types.Int, - name: !types.String + id: GraphQL::Types::ID.to_non_null_type, + age: GraphQL::Types::Int, + name: GraphQL::Types::String.to_non_null_type } end @@ -113,7 +113,7 @@ context 'with multiple expected arguments with types specified' do let(:expected_args) do - { ability: types.Int, id: types.Int, some: types.Boolean } + { ability: GraphQL::Types::Int, id: GraphQL::Types::Int, some: GraphQL::Types::Boolean } end it 'describes the arguments the field should accept and their types' do diff --git a/spec/rspec/have_a_field_matcher_spec.rb b/spec/rspec/have_a_field_matcher_spec.rb index dcbf15c..6ed3af2 100644 --- a/spec/rspec/have_a_field_matcher_spec.rb +++ b/spec/rspec/have_a_field_matcher_spec.rb @@ -59,9 +59,9 @@ module GraphqlMatchers it 'passes when the type defines the field with correct type as ' \ 'graphql objects' do expect(a_type).to have_a_field(:id).that_returns('ID!') - expect(a_type).to have_a_field('other').of_type(types.String) - expect(a_type).to have_a_field(:is_test).of_type(types.Boolean) - expect(a_type).to have_a_field(:isTest).of_type(types.Boolean) + expect(a_type).to have_a_field('other').of_type(GraphQL::Types::String) + expect(a_type).to have_a_field(:is_test).of_type(GraphQL::Types::Boolean) + expect(a_type).to have_a_field(:isTest).of_type(GraphQL::Types::Boolean) end it 'fails when the type defines a field of the wrong type' do @@ -71,7 +71,8 @@ module GraphqlMatchers 'of type `ID`, but it was `ID!`' ) - expect { expect(a_type).to have_a_field('other').returning(!types.Int) } + expect { expect(a_type).to have_a_field('other') + .returning(GraphQL::Types::Int.to_non_null_type) } .to fail_with( 'expected TestObject to define field `other` ' \ 'of type `Int!`, but it was `String`' @@ -165,11 +166,11 @@ module GraphqlMatchers Class.new(GraphQL::Schema::Object) do graphql_name 'TestObject' - field :id, types.ID, null: false - field :other, types.String, hash_key: :other_on_hash, null: true - field :is_test, types.Boolean, null: true - field :not_camelized, types.String, null: false, camelize: false - field :deprecated_field, types.String, null: true, + field :id, GraphQL::Types::ID, null: false + field :other, GraphQL::Types::String, hash_key: :other_on_hash, null: true + field :is_test, GraphQL::Types::Boolean, null: true + field :not_camelized, GraphQL::Types::String, null: false, camelize: false + field :deprecated_field, GraphQL::Types::String, null: true, deprecation_reason: 'deprecated' end end @@ -182,10 +183,10 @@ module GraphqlMatchers include GraphQL::Schema::Interface graphql_name 'ActualInterface' - field :other, types.String, hash_key: :other_on_hash, null: true - field :is_test, types.Boolean, null: true - field :not_camelized, types.String, null: false, camelize: false - field :deprecated_field, types.String, null: true, + field :other, GraphQL::Types::String, hash_key: :other_on_hash, null: true + field :is_test, GraphQL::Types::Boolean, null: true + field :not_camelized, GraphQL::Types::String, null: false, camelize: false + field :deprecated_field, GraphQL::Types::String, null: true, deprecation_reason: 'deprecated' end diff --git a/spec/rspec/have_a_return_field_spec.rb b/spec/rspec/have_a_return_field_spec.rb index 18c7acf..8754dbf 100644 --- a/spec/rspec/have_a_return_field_spec.rb +++ b/spec/rspec/have_a_return_field_spec.rb @@ -7,16 +7,13 @@ module GraphqlMatchers describe 'expect(a_type).to have_a_return_field(field_name)' \ '.that_returns(a_type)' do subject(:a_type) do - types_to_define = type_fields - GraphQL::Relay::Mutation.define do - name 'TestObject' + Class.new(GraphQL::Schema::RelayClassicMutation) do + graphql_name 'TestObject' - types_to_define.each do |fname, ftype| - return_field fname, ftype - end + field :id, GraphQL::Types::String + field :other, GraphQL::Types::ID, null: false end end - let(:type_fields) { { 'id' => types.String, 'other' => !types.ID } } it { is_expected.to have_a_return_field(:id) } @@ -31,7 +28,7 @@ module GraphqlMatchers it 'fails with a failure message when the type does not define the field' do expect { expect(a_type).to have_a_return_field(:ids) } .to fail_with( - "expected #{a_type.name} to define field `ids` but no field was " \ + "expected #{a_type.graphql_name} to define field `ids` but no field was " \ 'found with that name' ) end @@ -50,21 +47,21 @@ module GraphqlMatchers it 'passes when the type defines the field with correct type as graphql ' \ 'objects' do - expect(a_type).to have_a_return_field(:id).that_returns(types.String) - expect(a_type).to have_a_return_field('other').that_returns(!types.ID) + expect(a_type).to have_a_return_field(:id).that_returns(GraphQL::Types::String) + expect(a_type).to have_a_return_field('other').that_returns(GraphQL::Types::ID.to_non_null_type) end it 'fails when the type defines a field of the wrong type' do expect { expect(a_type).to have_a_return_field(:id).returning('String!') } .to fail_with( - "expected #{a_type.name} to define field `id` of type `String!`, " \ + "expected #{a_type.graphql_name} to define field `id` of type `String!`, " \ 'but it was `String`' ) expect do - expect(a_type).to have_a_return_field('other').returning(!types.Int) + expect(a_type).to have_a_return_field('other').returning(GraphQL::Types::Int.to_non_null_type) end.to fail_with( - "expected #{a_type.name} to define field `other` of type `Int!`, " \ + "expected #{a_type.graphql_name} to define field `other` of type `Int!`, " \ 'but it was `ID!`' ) end @@ -76,7 +73,7 @@ module GraphqlMatchers expect { expect(a_type).to have_a_return_field(:id) } .to raise_error( RuntimeError, - 'Invalid object InvalidObject provided to have_a_return_field ' \ + 'Invalid object InvalidObject provided to have_a_field ' \ 'matcher. It does not seem to be a valid GraphQL object type.' ) end diff --git a/spec/rspec/have_an_input_field_matcher_spec.rb b/spec/rspec/have_an_input_field_matcher_spec.rb index a11655e..4042c05 100644 --- a/spec/rspec/have_an_input_field_matcher_spec.rb +++ b/spec/rspec/have_an_input_field_matcher_spec.rb @@ -6,17 +6,16 @@ module RSpec module GraphqlMatchers describe 'expect(a_type).to have_an_input_field(field_name)' \ '.that_returns(a_type)' do + subject(:a_type) do - types_to_define = type_fields - GraphQL::Relay::Mutation.define do - name 'TestObject' + Class.new(GraphQL::Schema::RelayClassicMutation) do + graphql_name 'TestObject' + - types_to_define.each do |fname, ftype| - input_field fname, ftype - end + argument :id, GraphQL::Types::String, required: false + argument :other, GraphQL::Types::ID, required: true end end - let(:type_fields) { { 'id' => types.String, 'other' => !types.ID } } it { is_expected.to have_an_input_field(:id) } @@ -31,7 +30,7 @@ module GraphqlMatchers it 'fails with a failure message when the type does not define the field' do expect { expect(a_type).to have_an_input_field(:ids) } .to fail_with( - "expected #{a_type.name} to define field `ids` but no field was " \ + "expected #{a_type.graphql_name} to define field `ids` but no field was " \ 'found with that name' ) end @@ -50,21 +49,21 @@ module GraphqlMatchers it 'passes when the type defines the field with correct type as graphql ' \ 'objects' do - expect(a_type).to have_an_input_field(:id).that_returns(types.String) - expect(a_type).to have_an_input_field('other').that_returns(!types.ID) + expect(a_type).to have_an_input_field(:id).that_returns(GraphQL::Types::String) + expect(a_type).to have_an_input_field('other').that_returns(GraphQL::Types::ID.to_non_null_type) end it 'fails when the type defines a field of the wrong type' do expect { expect(a_type).to have_an_input_field(:id).returning('String!') } .to fail_with( - "expected #{a_type.name} to define field `id` of type `String!`, " \ + "expected #{a_type.graphql_name} to define field `id` of type `String!`, " \ 'but it was `String`' ) expect do - expect(a_type).to have_an_input_field('other').returning(!types.Int) + expect(a_type).to have_an_input_field('other').returning(GraphQL::Types::Int.to_non_null_type) end.to fail_with( - "expected #{a_type.name} to define field `other` of type `Int!`, " \ + "expected #{a_type.graphql_name} to define field `other` of type `Int!`, " \ 'but it was `ID!`' ) end From 4f29eceddfa0423c668c596cb8dabb51a3ffb3dd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Samuel=20Brand=C3=A3o?= Date: Sun, 16 Apr 2023 16:35:02 -0300 Subject: [PATCH 4/7] Update readme to make deprecations more clear The goal is to only support the string representation of the type signature. Since the actual type graphql name is a published depencency of our APIs, we want our tests to ensure we're not breaking our public interface inadvertently. --- README.md | 8 ++------ lib/rspec/graphql_matchers/types_helper.rb | 15 ++++++++++++++- spec/rspec/accept_argument_matcher_spec.rb | 2 +- 3 files changed, 17 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index f0474ed..f232507 100644 --- a/README.md +++ b/README.md @@ -21,11 +21,9 @@ The matchers currently supported are: - `expect(a_field).to be_of_type(valid_type)` - `expect(an_input).to accept_argument(argument_name).of_type(valid_type)` -Where a valid type for the expectation is either: +Where `valid_type` is a your type signature as a String: `"String!"`, `"Int!"`, `"[String]!"` (note the exclamation mark at the end, as required by the [GraphQL specifications](http://graphql.org/). -- A reference to the actual type you expect; -- [Recommended] A String representation of a type: `"String!"`, `"Int!"`, `"[String]!"` - (note the exclamation mark at the end, as required by the [GraphQL specifications](http://graphql.org/). +Please note that using references to type instances is deprecated and will be removed in a future release. ## Examples @@ -123,8 +121,6 @@ describe PostType do expect(subject).to implement('Node') end - # Accepts arguments as an array and type objects directly - it { is_expected.to implement(GraphQL::Types::Relay::Node) } it { is_expected.not_to implement('OtherInterface') } end ``` diff --git a/lib/rspec/graphql_matchers/types_helper.rb b/lib/rspec/graphql_matchers/types_helper.rb index a9714d4..256aea7 100644 --- a/lib/rspec/graphql_matchers/types_helper.rb +++ b/lib/rspec/graphql_matchers/types_helper.rb @@ -5,8 +5,21 @@ module RSpec module GraphqlMatchers module TypesHelper + + class << self + extend Gem::Deprecate + + GraphQL::Types.constants.each do |constant_name| + klass = GraphQL::Types.const_get(constant_name) + + define_method(constant_name) { klass } + + deprecate constant_name, "GraphQL::Types::#{constant_name}", 2023, 10 + end + end + def types - GraphQL::Define::TypeDefiner.instance + TypesHelper end end end diff --git a/spec/rspec/accept_argument_matcher_spec.rb b/spec/rspec/accept_argument_matcher_spec.rb index b4ebc04..a8dfcaf 100644 --- a/spec/rspec/accept_argument_matcher_spec.rb +++ b/spec/rspec/accept_argument_matcher_spec.rb @@ -68,7 +68,7 @@ module GraphqlMatchers it 'passes when the type defines the field with correct type as ' \ 'graphql objects' do - expect(a_type).to accept_argument(:id).of_type(types.String) + expect(a_type).to accept_argument(:id).of_type(GraphQL::Types::String) expect(a_type).to accept_argument('other').of_type('ID!') end From 4a61255a8d637914752e72bac9d357a4a5f6e75b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Samuel=20Brand=C3=A3o?= Date: Sun, 16 Apr 2023 16:46:00 -0300 Subject: [PATCH 5/7] Upgrade graphql-ruby dependency to 2.0+ --- rspec-graphql_matchers.gemspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rspec-graphql_matchers.gemspec b/rspec-graphql_matchers.gemspec index ca9cfc5..41aef9e 100644 --- a/rspec-graphql_matchers.gemspec +++ b/rspec-graphql_matchers.gemspec @@ -25,7 +25,7 @@ Gem::Specification.new do |spec| spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) } spec.require_paths = ['lib'] - spec.add_dependency 'graphql', '>= 1.10.12', '< 2.0' + spec.add_dependency 'graphql', '~> 2.0' spec.add_dependency 'rspec', '~> 3.0' spec.add_development_dependency 'bundler', '~> 2.0' # CodeClimate does not yet support SimpleCov 0.18 From d94757b72d23887efa3ff7894836d046c88b1c2b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Samuel=20Brand=C3=A3o?= Date: Sun, 16 Apr 2023 16:49:04 -0300 Subject: [PATCH 6/7] Rubocop fixes --- lib/rspec/graphql_matchers/be_of_type.rb | 3 ++- lib/rspec/graphql_matchers/types_helper.rb | 1 - 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/rspec/graphql_matchers/be_of_type.rb b/lib/rspec/graphql_matchers/be_of_type.rb index c47e0a3..d1e68d6 100644 --- a/lib/rspec/graphql_matchers/be_of_type.rb +++ b/lib/rspec/graphql_matchers/be_of_type.rb @@ -17,7 +17,8 @@ def matches?(actual_sample) end def failure_message - "expected field '#{member_name(sample)}' to be of type '#{type_name(expected)}', " \ + "expected field '#{member_name(sample)}' to " \ + "be of type '#{type_name(expected)}', " \ "but it was '#{type_name(sample.type)}'" end diff --git a/lib/rspec/graphql_matchers/types_helper.rb b/lib/rspec/graphql_matchers/types_helper.rb index 256aea7..2d0a1ce 100644 --- a/lib/rspec/graphql_matchers/types_helper.rb +++ b/lib/rspec/graphql_matchers/types_helper.rb @@ -5,7 +5,6 @@ module RSpec module GraphqlMatchers module TypesHelper - class << self extend Gem::Deprecate From 8ab63d5f69745451a3f4e6efe6017a5e8146084b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Samuel=20Brand=C3=A3o?= Date: Sun, 16 Apr 2023 16:59:05 -0300 Subject: [PATCH 7/7] Prepare 2.0.0-rc.0 release --- CHANGELOG.md | 27 +++++++++++++++++++++++++++ lib/rspec/graphql_matchers/version.rb | 2 +- rspec-graphql_matchers.gemspec | 3 --- 3 files changed, 28 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f81bcbe..38dd62e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,32 @@ # Changelog +## 2.0.0 (April 16th, 2023) + +- Adds compatibility with graphql-ruby 2.0+. If you're still using an earlier version, you should stick to 1.4.x. + +### Deprecations + +- The usage of the `#types` helper when writing tests (if you're not including `RSpec::GraphqlMatchers::TypesHelper` anywhere, you shoudn't have to change anything). Use `GraphQL::Types::` instead +- The usage of type instances as expected value for a type comparison is deprecated. Instead, + use the string that represents the type specification. Examples: + + ``` + # Bad - These are deprecated: + expect(a_type).to have_a_field(:lorem).of_type(GraphQL::Types::ID) + expect(a_type).to have_a_field(:lorem).of_type(Types::MyCustomType) + + # Good - Use these instead + expect(a_type).to have_a_field(:lorem).of_type('ID') + expect(a_type).to have_a_field(:lorem).of_type('MyCustomType') + ``` + + The reason behind this change relies on the fact that we should have a decoupling between the + internal constants used to define our API and the public names exposed through it. If we test + a published API using the internal constants, it is possible to perform breaking changes by + renaming the graphql names of our types or entities without actually breaking the tests. + + If we're performing a breaking change to a public API, we want our tests to fail. + ## 1.4.0 (April 16th, 2023) - Removal of deprecated calls to #to_graphql, replacing them with #to_type_signature that was added in graphql-ruby 1.8.3 (https://github.com/khamusa/rspec-graphql_matchers/pull/43 @RobinDaugherty) diff --git a/lib/rspec/graphql_matchers/version.rb b/lib/rspec/graphql_matchers/version.rb index bc8ae0b..06d8c19 100644 --- a/lib/rspec/graphql_matchers/version.rb +++ b/lib/rspec/graphql_matchers/version.rb @@ -2,6 +2,6 @@ module Rspec module GraphqlMatchers - VERSION = '1.4.0'.freeze + VERSION = '2.0.0-rc.0'.freeze end end diff --git a/rspec-graphql_matchers.gemspec b/rspec-graphql_matchers.gemspec index 41aef9e..701fe9e 100644 --- a/rspec-graphql_matchers.gemspec +++ b/rspec-graphql_matchers.gemspec @@ -14,9 +14,6 @@ Gem::Specification.new do |spec| spec.homepage = 'https://github.com/khamusa/rspec-graphql_matchers' spec.license = 'MIT' - # raise 'RubyGems 2.0 or newer is required to protect against public gem ' \ - # 'pushes.' - spec.files = `git ls-files -z` .split("\x0")