From 126bef901500558bac685e50d740601424a4b52b Mon Sep 17 00:00:00 2001 From: Milo Hyben Date: Mon, 22 Jan 2024 11:28:52 +1100 Subject: [PATCH] Removing temporary Billing GraphQL, will be properly implemented in the next PRs. --- api/graphql/schema.py | 107 ------------------------------------------ 1 file changed, 107 deletions(-) diff --git a/api/graphql/schema.py b/api/graphql/schema.py index 1b7213642..436a1c334 100644 --- a/api/graphql/schema.py +++ b/api/graphql/schema.py @@ -18,10 +18,8 @@ from api.graphql.filters import GraphQLFilter, GraphQLMetaFilter from api.graphql.loaders import LoaderKeys, get_context from db.python import enum_tables -from db.python.gcp_connect import BqConnection from db.python.layers import AnalysisLayer, SampleLayer, SequencingGroupLayer from db.python.layers.assay import AssayLayer -from db.python.layers.billing import BillingLayer from db.python.layers.family import FamilyLayer from db.python.tables.analysis import AnalysisFilter from db.python.tables.assay import AssayFilter @@ -34,9 +32,6 @@ AnalysisInternal, AssayInternal, AuditLogInternal, - BillingColumn, - BillingInternal, - BillingTotalCostQueryModel, FamilyInternal, ParticipantInternal, Project, @@ -597,33 +592,6 @@ async def sample(self, info: Info, root: 'GraphQLAssay') -> GraphQLSample: return GraphQLSample.from_internal(sample) -@strawberry.type -class GraphQLBilling: - """GraphQL Billing""" - - id: str | None - ar_guid: str | None - gcp_project: str | None - topic: str | None - batch_id: str | None - cost_category: str | None - day: datetime.date | None - cost: float | None - - @staticmethod - def from_internal(internal: BillingInternal) -> 'GraphQLBilling': - return GraphQLBilling( - id=internal.id, - ar_guid=internal.ar_guid, - gcp_project=internal.gcp_project, - topic=internal.topic, - batch_id=internal.batch_id, - cost_category=internal.cost_category, - day=internal.day, - cost=internal.cost, - ) - - @strawberry.type class Query: """GraphQL Queries""" @@ -762,81 +730,6 @@ async def my_projects(self, info: Info) -> list[GraphQLProject]: ) return [GraphQLProject.from_internal(p) for p in projects] - @strawberry.field - async def billing( - self, - info: Info, - batch_id: str | None = None, - ar_guid: str | None = None, - topic: str | None = None, - gcp_project: str | None = None, - day: GraphQLFilter[datetime.datetime] | None = None, - cost: GraphQLFilter[float] | None = None, - ) -> list[GraphQLBilling]: - """ - This is the first raw implementation of Billing inside GraphQL - """ - # TODO check billing is enabled e.g.: - # if not is_billing_enabled(): - # raise ValueError('Billing is not enabled') - - # TODO is there a better way to get the BQ connection? - connection = info.context['connection'] - bg_connection = BqConnection(connection.author) - slayer = BillingLayer(bg_connection) - - if ar_guid: - res = await slayer.get_cost_by_ar_guid(ar_guid) - if res: - # only show the costs - res = res.costs - - elif batch_id: - res = await slayer.get_cost_by_batch_id(batch_id) - if res: - # only show the costs - res = res.costs - - else: - # TODO construct fields from request.body (selected attributes) - # For time being, just use these fields - fields = [ - BillingColumn.DAY, - BillingColumn.COST, - BillingColumn.COST_CATEGORY, - ] - - filters = {} - if topic: - filters['topic'] = topic - fields.append(BillingColumn.TOPIC) - if gcp_project: - filters['gcp_project'] = gcp_project - fields.append(BillingColumn.GCP_PROJECT) - - if day: - all_days_vals = day.all_values() - start_date = min(all_days_vals).strftime('%Y-%m-%d') - end_date = max(all_days_vals).strftime('%Y-%m-%d') - else: - # TODO we need to limit to small time periods to avoid huge charges - # If day is not selected use only current day records - start_date = datetime.datetime.now().strftime('%Y-%m-%d') - end_date = start_date - - query = BillingTotalCostQueryModel( - fields=fields, - start_date=start_date, - end_date=end_date, - filters=filters, - ) - res = await slayer.get_total_cost(query) - - return [ - GraphQLBilling.from_internal(BillingInternal.from_db(**dict(p))) - for p in res - ] - schema = strawberry.Schema( query=Query, mutation=None, extensions=[QueryDepthLimiter(max_depth=10)]