-
Notifications
You must be signed in to change notification settings - Fork 14
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
Return GraphQL responses with underscore keys #1310
Conversation
4effb1a
to
4f202c7
Compare
Publishing API returns GraphQL responses with camel cased keys. However we use underscored keys in our applications. Therefore transforming the keys here, so the same does not need to be duplicated in every consuming application. Note: the activesupport gem is required, as `deep_transform_keys` (on Hash) and `underscore` (on String) are both part of Rails, not Ruby. This avoids needing to rewrite those methods in this application.
4f202c7
to
33b96b6
Compare
@@ -15,6 +15,7 @@ Gem::Specification.new do |s| | |||
s.required_ruby_version = ">= 3.1" | |||
s.files = Dir.glob("lib/**/*") + Dir.glob("test/fixtures/**/*") + %w[README.md Rakefile] | |||
s.require_path = "lib" | |||
s.add_dependency "activesupport" |
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.
Are there any users of this gem that don't already have ActiveSupport?
I do get that it's still a bit gross to do this even if that's currently the case, but if it's not the case I'd be a lot less keen on doing this 😆
Maybe there are standalone gems that implement these methods?
def graphql_query(query) | ||
post_json("#{endpoint}/graphql", query:) | ||
response = post_json("#{endpoint}/graphql", query:) |
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.
Repeating what I said in directly to Bruce, for the rest of the team: I reckon we could do something with the JsonClient
's create_response
block (
gds-api-adapters/lib/gds_api/json_client.rb
Lines 93 to 94 in 0ddad8b
# create_response: optional block to instantiate a custom response object | |
# from the Net::HTTPResponse |
Closing in favour of using snake cased keys for fields and arguments in Publishing API: alphagov/publishing-api#3049. |
Publishing API returns GraphQL responses with camel cased keys. However we use underscored keys in our applications.
Therefore transforming the keys here, so the same does not need to be duplicated in every consuming application.
Trello card