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

fix: exclude invalid fields in analyzer #44

Merged
merged 7 commits into from
Dec 3, 2024

Conversation

al-yanna
Copy link
Contributor

@al-yanna al-yanna commented Dec 2, 2024

Context

When encountering invalid fields in a query, the analyzer would throw an error:

undefined method 'graphql_name' for nil (NoMethodError)

We want to handle these cases gracefully.

Changes

  • Updated the on_enter_field method in the GraphQL::Hive::Analyzer to validate both the parent type and the field existence before adding to @used_fields.

Testing

  • Unit test (Analyzer)

@al-yanna al-yanna marked this pull request as ready for review December 2, 2024 21:51
Copy link
Collaborator

@cassidycodes cassidycodes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Requesting changes to make the tests more specific about expectations. This looks good to me otherwise.

spec/graphql/graphql-hive/analyzer_spec.rb Outdated Show resolved Hide resolved
spec/graphql/graphql-hive/analyzer_spec.rb Outdated Show resolved Hide resolved
Copy link
Collaborator

@aryascripts aryascripts left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Small change related to when we log, but otherwise looks good!

lib/graphql-hive/client.rb Outdated Show resolved Hide resolved
Comment on lines 27 to 29
if response.code.to_i >= 400 && response.code.to_i < 500
@options[:logger].warn("Unsuccessful response: #{response.code} - #{response.body}")
end
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did this get added to this PR? Are you certain response.body is safe to log without exposing tokens?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

its mostly for debugging purposes. to be safe, we can parse and log specific fields instead of the entire body. i'll remove this for now and address it in a separate PR!

@al-yanna al-yanna requested a review from cassidycodes December 3, 2024 21:53
@rperryng rperryng merged commit 6b2b430 into rperryng:master Dec 3, 2024
4 checks passed
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.

4 participants