-
Notifications
You must be signed in to change notification settings - Fork 92
Filter Graphql fields on top level #250
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: master
Are you sure you want to change the base?
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -223,10 +223,21 @@ def remove_fields_from_query(self, fields_to_remove: list) -> str: | |
|
|
||
| class FieldRemover(Visitor): | ||
| def enter_selection_set(self, node, _key, _parent, _path, _ancestors): | ||
| # Only prune fields at the top-level record node (stream → edges → node). | ||
| # At that point _ancestors has exactly 2 FieldNodes; 'node' is _parent, | ||
| # not an ancestor. | ||
| field_ancestor_names = [ | ||
| a.name.value | ||
| for a in _ancestors | ||
| if isinstance(a, FieldNode) | ||
| ] | ||
|
|
||
| at_top_level_node = len(field_ancestor_names) == 2 | ||
|
|
||
| new_selections = [] | ||
| for selection in node.selections: | ||
| if isinstance(selection, FieldNode): | ||
| if selection.name.value in fields_to_remove: | ||
| if at_top_level_node and selection.name.value in fields_to_remove: | ||
| continue | ||
|
||
| # Check field arguments for variable usage | ||
| for arg in selection.arguments or []: | ||
|
|
||
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.
Current unit coverage for
remove_fields_from_queryonly exercises the...edges { node { ... } }shape (seetests/unittests/test_schema_validation.py::test_remove_fields_from_query). Given this change alters pruning scope, please add tests for at least one stream/query where record fields are not directly under that pattern (e.g.,transactionswhere fields live undertransactions { ... }, orinventory_levelswhere fields live underinventoryLevels.edges.node).