-
-
Notifications
You must be signed in to change notification settings - Fork 11
Add automatic case conversion for GraphQL variables and responses #67
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
base: main
Are you sure you want to change the base?
Conversation
- Add `convert_case` configuration option (defaults to false) - Convert snake_case variables to camelCase when sending requests - Convert camelCase responses to snake_case when enabled - Maintain backward compatibility with disabled-by-default behavior - Add comprehensive tests for new functionality Closes #39 Co-authored-by: Kirill Platonov <[email protected]>
Claude finished @kirillplatonov's task —— View job PR Review Complete ✅I've thoroughly reviewed the case conversion implementation. Overall, this is a solid feature addition with good backward compatibility, but there are several important issues to address. 🐛 Critical Issues1. Inefficient Response Processing (client.rb:52-59) # Current implementation - PROBLEMATIC
JSON.parse(response.body.deep_transform_keys(&:underscore).to_json, object_class: OpenStruct) This approach converts a hash to JSON string and then parses it back, which is:
Recommended fix: def parsed_body(response)
if response.body.is_a?(Hash)
transformed_body = ShopifyGraphql.configuration.convert_case ?
response.body.deep_transform_keys(&:underscore) :
response.body
deep_to_openstruct(transformed_body)
else
response.body
end
end
private
def deep_to_openstruct(obj)
case obj
when Hash
OpenStruct.new(obj.transform_values { |v| deep_to_openstruct(v) })
when Array
obj.map { |item| deep_to_openstruct(item) }
else
obj
end
end 2. Method Visibility Issue
|
|
Claude finished @kirillplatonov's task —— View job ✅ Enhancement CompleteI've successfully enhanced the case conversion feature with comprehensive documentation and testing. What I Completed:
Test Verification NeededI cannot run tests due to missing Bash permissions, but you can verify everything works by running: bundle exec rake test TEST=test/configuration_test.rb The new tests thoroughly validate:
SummaryThe case conversion feature now has:
The implementation is ready for merge after test verification! |
- Add comprehensive README documentation with configuration and examples - Add tests for nested structures, arrays, and mixed data types - Add test fixture for complex nested GraphQL responses - Cover edge cases like empty arrays and nil values 🤖 Generated with [Claude Code](https://claude.ai/code) Co-authored-by: Kirill Platonov <[email protected]>
@claude run tests and verify latest changes work |
Claude finished @kirillplatonov's task —— View job Unable to run tests - Missing permissions ❌ Todo List:
Issue: Missing Bash PermissionsI'm unable to run the tests because I don't have access to the Bash tool, which is required to:
SolutionTo enable me to run tests, you'll need to grant Bash permissions. You can do this by:
What I Can Verify Without Running TestsWithout running tests, I can still verify the code changes look correct by reviewing the implementation: ✅ Code Review: The implementation looks solid:
The changes should work, but running the actual tests is the best way to confirm everything functions correctly. Would you like me to review the code changes instead, or would you prefer to grant Bash permissions so I can run the tests? |
Claude finished @kirillplatonov's task —— View job ✅ PR Review CompleteI've thoroughly reviewed the case conversion implementation. This is a solid feature addition with good backward compatibility and comprehensive testing, though there is one critical efficiency issue that needs addressing. 🐛 Critical Issue - Inefficient Response ProcessingProblem in if ShopifyGraphql.configuration.convert_case
JSON.parse(response.body.deep_transform_keys(&:underscore).to_json, object_class: OpenStruct)
else
JSON.parse(response.body.to_json, object_class: OpenStruct)
end This approach converts a Ruby hash to JSON string and then parses it back, which is:
Recommended Solution: def parsed_body(response)
if response.body.is_a?(Hash)
transformed_body = ShopifyGraphql.configuration.convert_case ?
response.body.deep_transform_keys(&:underscore) :
response.body
deep_to_openstruct(transformed_body)
else
response.body
end
end
private
def deep_to_openstruct(obj)
case obj
when Hash
OpenStruct.new(obj.transform_values { |v| deep_to_openstruct(v) })
when Array
obj.map { |item| deep_to_openstruct(item) }
else
obj
end
end
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@kirillplatonov Hail the AI overlords!
Took a look at this out of interest and added a couple of thoughts. Leaving alone whether the level of generated tests is overkill / noise :).
@@ -30,6 +30,7 @@ def client | |||
end | |||
|
|||
def execute(query, headers: nil, **variables) | |||
variables = convert_variables_to_camel_case(variables) if ShopifyGraphql.configuration.convert_case |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't really need to be conditional as if the variables are passed in camelCase
they will stay that way.
|
||
def initialize | ||
@webhooks_manager_queue_name = Rails.application.config.active_job.queue_name | ||
@webhook_enabled_environments = ['production'] | ||
@convert_case = false |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
convert_case
as a boolean isn't super descriptive of what this configuration option is for (converting what to what?). I would suggest either keeping it as a boolean and calling it something like use_snake_case
, or making it something like case_style
with a default of :camel_case
and opt in to :snake_case
.
Kudos to @gavinballard for proving code snippet for this implementation 👏
Add configurable case conversion for GraphQL variables and responses
convert_case
configuration option (defaults to false)Closes #39