Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Version 1.2 missing support for snake_case field names #30

Closed
pattpattpatt opened this issue Feb 14, 2020 · 2 comments · Fixed by #31
Closed

Version 1.2 missing support for snake_case field names #30

pattpattpatt opened this issue Feb 14, 2020 · 2 comments · Fixed by #31

Comments

@pattpattpatt
Copy link

Hi there! Thanks for creating these helpers. Delightful code to work with. I hope I'm just missing something, but it seems like the last version bump broke support for snake case field testing.

When testing a snake case field name, version 1.2 of this gem assumes the field name to be camelized and camelizes the expected field name even though the field on the schema is snake case.

I'm using 1.8.4 of the graphql gem and 1.2 of the rspec-graphql_matchers gem, for context

Type definition:

class ExampleType < GraphQL::Schema::Object
  # metadata

  field :existing_snake_case_field, String, null: true, camelize: false
  def resolve
    # logic and things
  end
end

RSpec Expectation:

require "rails_helper"
require "rspec/graphql_matchers"

RSpec.describe Types::Objects::ExampleType do
  subject { described_class }

  it { is_expected.to have_field(:existing_snake_case_field).of_type "String" }
end

Error I'm seeing:

Failure/Error: it { is_expected.to have_field(:existing_snake_case_field).of_type "String" }
       expected Example to define field `existingSnakeCaseField` but no field was found with that name

If I dig a little further, I see that the fields hash on the type I'm testing has a snake_case field name key, rather than the camelCase version. The matcher seems to assume that the field key will be camelCase and compares the camelCase @expected_field_name to the snake case hash key, getting nil back, and subsequently failing.

subject.fields
=> {"existing_snake_case_field"=> #<GraphQL::Schema::Field:0x00007f98ca194c80 }

It seems to be related to this change, which added support for snake case arguments, but assumes the camelization of the field name: https://github.com/khamusa/rspec-graphql_matchers/pull/29/files#diff-4820620b0dee82dd3ac38023e704859eR13

I would just bump the version back to v1.1 but that drops support for snake_case arguments which are also inherent in our code base. Seems like we have to leave one or the other untested, which is... not ideal. Again, I hope I'm just missing something. Thanks!

@markd2lp
Copy link

Same problem here, I needed to go back to version 1.1 and I'm waiting for the correction

@khamusa
Copy link
Owner

khamusa commented Apr 19, 2020

Hey @pattpattpatt and @markd2lp, this has been fixed on the latest version.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants