README.md in rspec-graphql_matchers-1.3.1 vs README.md in rspec-graphql_matchers-1.4.0

- old
+ new

@@ -23,27 +23,22 @@ Where a valid type for the expectation is either: - 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 specs](http://graphql.org/). + (note the exclamation mark at the end, as required by the [GraphQL specifications](http://graphql.org/). -For objects defined with the legacy `#define` api, testing `:property`, `:hash_key` and _metadata_ is also possible by chaining `.with_property`, `.with_hash_key` and `.with_metadata`. For example: - -- `expect(a_graphql_object).to have_a_field(field_name).with_property(property_name).with_metadata(metadata_hash)` -- `expect(a_graphql_object).to have_a_field(field_name).with_hash_key(hash_key)` - ## Examples Given a GraphQL object defined as ```ruby class PostType < GraphQL::Schema::Object graphql_name "Post" description "A blog post" - implements GraphQL::Relay::Node.interface + implements GraphQL::Types::Relay::Node field :id, ID, null: false field :comments, [String], null: false field :isPublished, Boolean, null: true field :published, Boolean, null: false, deprecation_reason: 'Use isPublished instead' @@ -95,33 +90,13 @@ it { is_expected.to be_of_type('Post') } end end ``` -### 3) For objects defined using the legacy `#define` api, you can also use `with_property`, `with_hash_key` and `with_metadata`: +### 3) Test the arguments accepted by a field with `accept_argument` matcher: ```ruby -PostTypeWithDefineApi = GraphQL::ObjectType.define do - name "DefinedPost" - - interfaces [GraphQL::Relay::Node.interface] - - field :id, !types.ID, property: :post_id - field :comments, !types[types.String], hash_key: :post_comments - field :isPublished, admin_only: true -end - -describe PostTypeWithDefineApi do - it { is_expected.to have_a_field(:id).of_type('ID!').with_property(:post_id) } - it { is_expected.to have_a_field(:comments).with_hash_key(:post_comments) } - it { is_expected.to have_a_field(:isPublished).with_metadata(admin_only: true) } -end -``` - -### 4) Test the arguments accepted by a field with `accept_argument` matcher: - -```ruby describe PostType do describe 'subposts' do subject { PostType.fields['subposts'] } it 'accepts a filter and an id argument, of types String and ID' do @@ -136,34 +111,34 @@ it { is_expected.to accept_argument(:is_published).of_type("Boolean") } end end ``` -### 5) Test an object's interface implementations: +### 4) Test an object's interface implementations: ```ruby describe PostType do subject { described_class } it 'implements interface Node' do expect(subject).to implement('Node') end # Accepts arguments as an array and type objects directly - it { is_expected.to implement(GraphQL::Relay::Node.interface) } + it { is_expected.to implement(GraphQL::Types::Relay::Node) } it { is_expected.not_to implement('OtherInterface') } end ``` -### 6) Using camelize: false on field names +### 5) Using camelize: false on field names By default the graphql gem camelizes field names. This gem deals with it transparently: ```ruby class ObjectMessingWithCamelsAndSnakesType < GraphQL::Schema::Object graphql_name 'ObjectMessingWithCamelsAndSnakes' - implements GraphQL::Relay::Node.interface + implements GraphQL::Types::Relay::Node field :me_gusta_los_camellos, ID, null: false # note the camelize: false field :prefiero_serpientes, ID, null: false, camelize: false