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

Refactor graphql query runner + fix nested or #6986

Merged
merged 2 commits into from
Sep 11, 2024

Conversation

Weiko
Copy link
Member

@Weiko Weiko commented Sep 11, 2024

No description provided.

Copy link

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

PR Summary

This pull request refactors the GraphQL query runner, improving nested 'OR' condition handling and introducing new services for better code organization and maintainability.

  • Introduced GraphqlQueryFindOneResolverService and GraphqlQueryFindManyResolverService in separate files, simplifying the main GraphqlQueryRunnerService
  • Refactored GraphqlQueryFilterConditionParser to handle nested 'and' and 'or' conditions more efficiently
  • Added new exception codes INVALID_ARGS_FIRST and INVALID_ARGS_LAST for improved pagination error handling
  • Implemented getObjectMetadata function in convert-object-metadata-to-map.util.ts for robust object metadata retrieval
  • Updated exception handling in workspace-query-runner-graphql-api-exception-handler.util.ts to provide more specific error feedback

7 file(s) reviewed, 8 comment(s)
Edit PR Review Bot Settings

Comment on lines +34 to +35
const graphqlQueryFindOneResolverService =
new GraphqlQueryFindOneResolverService(this.twentyORMGlobalManager);
Copy link

Choose a reason for hiding this comment

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

style: Consider injecting this service instead of creating a new instance

Comment on lines +49 to +50
const graphqlQueryFindManyResolverService =
new GraphqlQueryFindManyResolverService(this.twentyORMGlobalManager);
Copy link

Choose a reason for hiding this comment

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

style: Consider injecting this service instead of creating a new instance

Comment on lines +105 to +107
if (objectRecords.length > limit) {
objectRecords.pop();
}
Copy link

Choose a reason for hiding this comment

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

style: This modifies the original objectRecords array. Consider creating a new array instead

Comment on lines +175 to +179
for (const column of Object.keys(order || {})) {
if (!select[column]) {
select[column] = true;
}
}
Copy link

Choose a reason for hiding this comment

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

style: This mutates the select object. Consider creating a new object instead

>(
args: FindOneResolverArgs<Filter>,
options: WorkspaceQueryRunnerOptions,
): Promise<ObjectRecord | undefined> {
Copy link

Choose a reason for hiding this comment

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

logic: The return type Promise<ObjectRecord | undefined> doesn't match the implementation, which always returns ObjectRecord or throws an exception.

objectMetadataItem,
graphqlFields(info),
);
const where = graphqlQueryParser.parseFilter(args.filter ?? ({} as Filter));
Copy link

Choose a reason for hiding this comment

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

style: Consider adding a type assertion to {} instead of using 'as Filter' to maintain type safety.

Comment on lines +73 to +78
return typeORMObjectRecordsParser.processRecord(
objectRecord,
objectMetadataItem.nameSingular,
1,
1,
) as ObjectRecord;
Copy link

Choose a reason for hiding this comment

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

style: The hardcoded values 1, 1 passed to processRecord() might need explanation or be replaced with meaningful constants.

@charlesBochet charlesBochet merged commit 725ee83 into main Sep 11, 2024
5 checks passed
@charlesBochet charlesBochet deleted the c--refactor-query-runner-fix-nested-or branch September 11, 2024 12:22
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