-
Notifications
You must be signed in to change notification settings - Fork 205
FWF-4761 [poc] Replace Recharts with Chart.js and update GraphQL #2905
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
Draft
leodube-aot
wants to merge
16
commits into
AOT-Technologies:develop
Choose a base branch
from
leodube-aot:FWF-4761
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
9ddabbc
Add Chart.js and some initial GraphQL configuration
leodube-aot 476edc4
Add form name param to graphql submission query
leodube-aot 3ee5934
Fix typo
leodube-aot 48b5d78
Update GraphQl forms queries to pull from multple db sources
leodube-aot 9dfedc5
Add comments to added form graphql query
leodube-aot ef1529f
Rename SubmissionModel to Submission
leodube-aot 2ee489a
Refactor and implement application class methods
leodube-aot 22792ec
Implement get_submission and remove base service
leodube-aot 20ae99f
Implement get_submission query
leodube-aot 6189594
Fix typo
leodube-aot 354bfa0
Add metric endpoint
leodube-aot 9c95701
Update metricsService
leodube-aot 9882419
Undo unneccessary changes to submission graphql queries
leodube-aot 6ef433b
Fix rebase issues
leodube-aot 7618299
Apply tenant checks on form graphql query
leodube-aot 344636c
Final cleanup
leodube-aot File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,10 @@ | ||
import strawberry | ||
|
||
from src.graphql.resolvers.submission_resolvers import ( | ||
QuerySubmissionsResolver, | ||
) | ||
from src.graphql.resolvers.form_resolvers import QueryFormsResolver | ||
from src.graphql.resolvers.metric_resolvers import QueryMetricsResolver | ||
from src.graphql.resolvers.submission_resolvers import QuerySubmissionsResolver | ||
|
||
|
||
@strawberry.type | ||
class Query(QuerySubmissionsResolver): # Inherit from query classes | ||
class Query(QuerySubmissionsResolver, QueryMetricsResolver, QueryFormsResolver): # Inherit from query classes | ||
pass |
95 changes: 95 additions & 0 deletions
95
forms-flow-data-layer/src/graphql/resolvers/form_resolvers.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
from typing import Optional | ||
|
||
import strawberry | ||
|
||
from src.graphql.schema import FormSchema, PaginationWindow | ||
from src.graphql.service import FormService | ||
from src.middlewares.auth import auth | ||
|
||
|
||
@strawberry.type | ||
class QueryFormsResolver: | ||
@strawberry.field(extensions=[auth.auth_required()]) | ||
async def get_forms( | ||
self, | ||
info: strawberry.Info, | ||
limit: int = 100, | ||
page_no: int = 1, | ||
order_by: str = 'created', | ||
type: Optional[str] = None, | ||
created_by: Optional[str] = None, | ||
form_name: Optional[str] = None, | ||
status: Optional[str] = None, | ||
parent_form_id: Optional[str] = None, | ||
from_date: Optional[str] = None, | ||
to_date: Optional[str] = None | ||
) -> PaginationWindow[FormSchema]: | ||
""" | ||
GraphQL resolver for querying forms. | ||
|
||
Args: | ||
info (strawberry.Info): GraphQL context information | ||
limit (int): Number of items to return (default: 100) | ||
page_no (int): Pagination number (default: 1) | ||
order_by (str): Filter to sort forms by (default: 'created') | ||
type (Optional[str]): Filter on form type | ||
created_by (Optional[str]): Filter on user who created the form | ||
form_name (Optional[str]): Filter on form name | ||
status (Optional[str]): Filter on form status | ||
parent_form_id (Optional[str]): Filter on form parent id | ||
from_date (Optional[str]): Filter from form date | ||
to_date (Optional[str]): Filter to form date | ||
Returns: | ||
Paginated list of Form objects containing combined PostgreSQL and MongoDB data | ||
""" | ||
# Create filters dict. Filters that share names with PostgreSQL or MongoDB column names | ||
# will be applied automatically. Other filters will require additional handling. | ||
filters = {} | ||
filters["order_by"] = order_by | ||
if type: | ||
filters["type"] = type | ||
if created_by: | ||
filters["created_by"] = created_by | ||
if form_name: | ||
filters["form_name"] = form_name | ||
if status: | ||
filters["status"] = status | ||
if parent_form_id: | ||
filters["parent_form_id"] = parent_form_id | ||
if from_date: | ||
filters["from_date"] = from_date | ||
if to_date: | ||
filters["to_date"] = to_date | ||
|
||
# Convert page_no to offset | ||
offset = (page_no - 1) * limit | ||
|
||
forms = await FormService.get_forms( | ||
user_context=info.context.get("user"), | ||
limit=limit, | ||
offset=offset, | ||
filters=filters | ||
) | ||
return forms | ||
|
||
|
||
@strawberry.field(extensions=[auth.auth_required()]) | ||
async def get_form( | ||
self, | ||
info: strawberry.Info, | ||
form_id: str, | ||
) -> Optional[FormSchema]: | ||
""" | ||
GraphQL resolver for querying form. | ||
|
||
Args: | ||
info (strawberry.Info): GraphQL context information | ||
form_id (str): ID of the form | ||
Returns: | ||
Form object containing combined PostgreSQL and MongoDB data | ||
""" | ||
form = await FormService.get_form( | ||
user_context=info.context.get("user"), | ||
form_id=form_id, | ||
) | ||
return form |
89 changes: 89 additions & 0 deletions
89
forms-flow-data-layer/src/graphql/resolvers/metric_resolvers.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
from typing import List, Optional | ||
|
||
import strawberry | ||
|
||
from src.graphql.schema import MetricSchema | ||
from src.graphql.service import MetricService | ||
from src.middlewares.auth import auth | ||
|
||
|
||
@strawberry.type | ||
class QueryMetricsResolver: | ||
@strawberry.field(extensions=[auth.auth_required()]) | ||
async def get_metrics_submission_status( | ||
self, | ||
info: strawberry.Info, | ||
form_id: str, | ||
order_by: str = 'created', | ||
from_date: Optional[str] = None, | ||
to_date: Optional[str] = None, | ||
) -> List[MetricSchema]: | ||
""" | ||
GraphQL resolver for querying submission status metrics. | ||
|
||
Args: | ||
info (strawberry.Info): GraphQL context information | ||
form_id (str): ID of the form | ||
order_by (str): Filter to sort submissions by (default: 'created') | ||
from_date (Optional[str]): Filter from submission date | ||
to_date (Optional[str]): Filter to submission date | ||
Returns: | ||
List of Metric objects | ||
""" | ||
# Create filters dict. Filters that share names with PostgreSQL or MongoDB column names | ||
# will be applied automatically. Other filters will require additional handling. | ||
filters = {} | ||
filters["order_by"] = order_by | ||
if form_id: | ||
filters["latest_form_id"] = form_id | ||
if from_date: | ||
filters["from_date"] = from_date | ||
if to_date: | ||
filters["to_date"] = to_date | ||
|
||
metrics = await MetricService.get_submission_metrics( | ||
user_context=info.context.get("user"), | ||
metric='application_status', | ||
filters=filters | ||
) | ||
return metrics | ||
|
||
|
||
@strawberry.field(extensions=[auth.auth_required()]) | ||
async def get_metrics_submission_created_by( | ||
self, | ||
info: strawberry.Info, | ||
form_id: str, | ||
order_by: str = 'created', | ||
from_date: Optional[str] = None, | ||
to_date: Optional[str] = None, | ||
) -> List[MetricSchema]: | ||
""" | ||
GraphQL resolver for querying submission created by metrics. | ||
|
||
Args: | ||
info (strawberry.Info): GraphQL context information | ||
form_id (str): ID of the form | ||
order_by (str): Filter to sort submissions by (default: 'created') | ||
from_date (Optional[str]): Filter from submission date | ||
to_date (Optional[str]): Filter to submission date | ||
Returns: | ||
List of Metric objects | ||
""" | ||
# Create filters dict. Filters that share names with PostgreSQL or MongoDB column names | ||
# will be applied automatically. Other filters will require additional handling. | ||
filters = {} | ||
filters["order_by"] = order_by | ||
if form_id: | ||
filters["latest_form_id"] = form_id | ||
if from_date: | ||
filters["from_date"] = from_date | ||
if to_date: | ||
filters["to_date"] = to_date | ||
|
||
metrics = await MetricService.get_submission_metrics( | ||
user_context=info.context.get("user"), | ||
metric='created_by', | ||
filters=filters | ||
) | ||
return metrics |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,17 @@ | ||
from src.graphql.schema.form_schema import FormSchema | ||
from src.graphql.schema.metric_schema import MetricSchema | ||
from src.graphql.schema.submission_schema import ( | ||
PaginatedSubmissionResponse, | ||
SubmissionDetailsWithSubmissionData, | ||
SubmissionSchema, | ||
) | ||
from src.middlewares.pagination import PaginationWindow | ||
|
||
__all__ = [ | ||
"FormSchema", | ||
"MetricSchema", | ||
"SubmissionSchema", | ||
"SubmissionDetailsWithSubmissionData", | ||
"PaginatedSubmissionResponse", | ||
"PaginationWindow", | ||
] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import strawberry | ||
|
||
|
||
@strawberry.type | ||
class MetricSchema: | ||
""" | ||
GraphQL type representing a Metric | ||
This is the external representation of your database model | ||
""" | ||
|
||
metric: str | ||
count: int |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
from src.graphql.service.form_service import FormService | ||
from src.graphql.service.metric_service import MetricService | ||
from src.graphql.service.submission_service import SubmissionService | ||
|
||
__all__ = ["FormService", "SubmissionService"] | ||
__all__ = ["FormService", "MetricService", "SubmissionService"] |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Updated model name to maintain a consistent naming convention.