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

Return GraphQL responses with underscore keys #1310

Closed
wants to merge 2 commits into from

Conversation

brucebolt
Copy link
Member

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

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.
@brucebolt brucebolt force-pushed the underscore-graphql-keys branch from 4f202c7 to 33b96b6 Compare December 17, 2024 08:53
@brucebolt brucebolt marked this pull request as ready for review December 17, 2024 08:53
@@ -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"
Copy link
Contributor

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:)
Copy link
Contributor

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 (

# create_response: optional block to instantiate a custom response object
# from the Net::HTTPResponse
). It'd allow us to be as Publishing API- / GraphQL-specific as we wanted without forcing those details onto the rest of GDS API Adapters.

@brucebolt
Copy link
Member Author

Closing in favour of using snake cased keys for fields and arguments in Publishing API: alphagov/publishing-api#3049.

@brucebolt brucebolt closed this Dec 17, 2024
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 this pull request may close these issues.

2 participants