-
Notifications
You must be signed in to change notification settings - Fork 155
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
feat: add validator and deprecation notices for non-paginated queries #2651
base: main
Are you sure you want to change the base?
Conversation
deprecated_queries = ( | ||
"agents", | ||
"domains", | ||
"groups_by_name", | ||
"groups", | ||
"images", | ||
"customized_images", | ||
"users", | ||
"keypairs", | ||
"keypair_resource_policies", | ||
"user_resource_policies", | ||
"resource_presets", | ||
"scaling_groups", | ||
"scaling_groups_for_domain", | ||
"scaling_groups_for_user_group", | ||
"scaling_groups_for_keypair", | ||
"vfolders", | ||
"container_registries", | ||
) | ||
|
||
|
||
def is_deprecated_query(query_name: str) -> bool: | ||
return query_name.lower() in deprecated_queries | ||
|
||
|
||
class GQLDeprecatedQueryValidator(ValidationRule): | ||
def enter_field(self, node: FieldNode, *_args): | ||
field_name = node.name.value | ||
if is_deprecated_query(field_name): | ||
log.warning("Non-paginated query '{}' is being used.", field_name) |
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.
Referencing deprecated query outside of the query definition can cause confusion to future readers in a high chance. Please check about possibilities of flagging each query as deprecated within the query implementation.
@@ -289,6 +289,7 @@ class Queries(graphene.ObjectType): | |||
Agent, | |||
scaling_group=graphene.String(), | |||
status=graphene.String(), | |||
deprecation_reason="deprecated_reason", |
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.
When talking about the deprecation it is important to also mention about alternative solutions. Please update every deprecation reason comments to do so.
Fixes #2560
Summary:
In this update, I have introduced a new validator (
GQLDeprecatedQueryValidator
) to handle the deprecation of non-paginated GraphQL queries. This validator logs warning message whenever a non-paginated query is used. Additionally, I have marked specific queries with thedeprecation_reason
attribute to indicate that these fields are deprecated.Details:
I created a validator named GQLDeprecatedQueryValidator that checks if a field in a GraphQL query is deprecated due to being non-paginated.
The deprecated queries are listed in the deprecated_queries tuple. These include queries that:
limit
andoffset
arguments.Relay
specification.If a query matches all these conditions, the validator logs a warning message using the log.warning method.
deprecation_reason
attribute. This helps to clearly indicate that the query is deprecated and provides the reason why.Example:
Review Request:
deprecated_queries
accurately reflects the queries that should be deprecated.deprecation_reason
for each deprecated field is currently set to indicate that the query is deprecated due to lack of pagination support. If there is a more appropriate message or additional context that should be provided, please suggest it.Checklist: