README.md in rspec-graphql_matchers-1.2 vs README.md in rspec-graphql_matchers-1.2.1
- old
+ new
@@ -61,10 +61,14 @@
subject { described_class }
it { is_expected.to have_field(:id).of_type(!types.ID) }
it { is_expected.to have_field(:comments).of_type("[String!]!") }
it { is_expected.to have_field(:isPublished).of_type("Boolean") }
+
+ # The gem automatically converts field names to CamelCase, so this will
+ # pass even though the field was defined as field :isPublished
+ it { is_expected.to have_field(:is_published).of_type("Boolean") }
end
```
### 2) Test a specific field type with `be_of_type` matcher:
@@ -136,13 +140,48 @@
it { is_expected.to implement(GraphQL::Relay::Node.interface) }
it { is_expected.not_to implement('OtherInterface') }
end
```
+### 6) 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
+
+ field :me_gusta_los_camellos, ID, null: false
+
+ # note the camelize: false
+ field :prefiero_serpientes, ID, null: false, camelize: false
+end
+```
+
+The following specs demonstrate the current behavior of the gem regarding fields:
+
+```ruby
+describe ObjectMessingWithCamelsAndSnakesType do
+ subject { described_class }
+
+ # For a field name that was automatically camelized, you can add expectations
+ # against both versions and we handle it transparently:
+ it { is_expected.to have_a_field(:meGustaLosCamellos) }
+ it { is_expected.to have_a_field(:me_gusta_los_camellos) }
+
+ # However, when using camelize: false, you have to use the exact case of the field definition:
+ it { is_expected.to have_a_field(:prefiero_serpientes) }
+ it { is_expected.not_to have_a_field(:prefieroSerpientes) } # Note we're using `not_to`
+end
+```
+
+This behaviour is currently active only on field name matching. PRs are welcome to
+reproduce it to arguments as well.
+
## TODO
-- Support GraphQL 1.9.x;
-- Check the method used for resolving a field;
- New matchers!
## Contributing
- Send Bug reports, suggestions or any general