Skip to content

Commit

Permalink
chore: Dedupe kwargs snake case decorator (#924)
Browse files Browse the repository at this point in the history
  • Loading branch information
suejung-sentry authored Oct 25, 2024
1 parent 1279697 commit c5b5a8f
Show file tree
Hide file tree
Showing 15 changed files with 15 additions and 54 deletions.
4 changes: 1 addition & 3 deletions graphql_api/types/bundle_analysis/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from typing import Dict, List, Mapping, Optional, Union

import sentry_sdk
from ariadne import ObjectType, convert_kwargs_to_snake_case
from ariadne import ObjectType
from graphql import GraphQLResolveInfo

from codecov.commands.exceptions import ValidationError
Expand Down Expand Up @@ -139,7 +139,6 @@ def resolve_modules(

@sentry_sdk.trace
@bundle_asset_bindable.field("measurements")
@convert_kwargs_to_snake_case
@sync_to_async
def resolve_asset_report_measurements(
bundle_asset: AssetReport,
Expand Down Expand Up @@ -277,7 +276,6 @@ def resolve_bundle_report_filtered(

@sentry_sdk.trace
@bundle_report_bindable.field("measurements")
@convert_kwargs_to_snake_case
@sync_to_async
def resolve_bundle_report_measurements(
bundle_report: BundleReport,
Expand Down
4 changes: 1 addition & 3 deletions graphql_api/types/commit/commit.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import sentry_sdk
import shared.reports.api_report_service as report_service
import yaml
from ariadne import ObjectType, convert_kwargs_to_snake_case
from ariadne import ObjectType
from graphql import GraphQLResolveInfo
from shared.reports.api_report_service import ReadOnlyReport
from shared.reports.filtered import FilteredReportFile
Expand Down Expand Up @@ -84,7 +84,6 @@ async def resolve_yaml(commit: Commit, info) -> dict:


@commit_bindable.field("yamlState")
@convert_kwargs_to_snake_case
async def resolve_yaml_state(commit: Commit, info) -> YamlStates:
command = info.context["executor"].get_command("commit")
final_yaml = await command.get_final_yaml(commit)
Expand Down Expand Up @@ -149,7 +148,6 @@ def resolve_critical_files(commit: Commit, info, **kwargs) -> List[CriticalFile]

@sentry_sdk.trace
@commit_bindable.field("pathContents")
@convert_kwargs_to_snake_case
@sync_to_async
def resolve_path_contents(commit: Commit, info, path: str = None, filters=None):
"""
Expand Down
3 changes: 1 addition & 2 deletions graphql_api/types/comparison/comparison.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from typing import List, Optional

import sentry_sdk
from ariadne import ObjectType, UnionType, convert_kwargs_to_snake_case
from ariadne import ObjectType, UnionType
from graphql.type.definition import GraphQLResolveInfo

import services.components as components_service
Expand Down Expand Up @@ -36,7 +36,6 @@ def resolve_state(comparison: ComparisonReport, info: GraphQLResolveInfo) -> str


@comparison_bindable.field("impactedFiles")
@convert_kwargs_to_snake_case
@sync_to_async
def resolve_impacted_files(
comparison_report: ComparisonReport, info: GraphQLResolveInfo, filters=None
Expand Down
3 changes: 1 addition & 2 deletions graphql_api/types/impacted_file/impacted_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from typing import List, Union

import sentry_sdk
from ariadne import ObjectType, UnionType, convert_kwargs_to_snake_case
from ariadne import ObjectType, UnionType
from shared.reports.types import ReportTotals
from shared.torngit.exceptions import TorngitClientError

Expand Down Expand Up @@ -67,7 +67,6 @@ def resolve_hashed_path(impacted_file: ImpactedFile, info) -> str:
@sentry_sdk.trace
@impacted_file_bindable.field("segments")
@sync_to_async
@convert_kwargs_to_snake_case
def resolve_segments(
impacted_file: ImpactedFile, info, filters=None
) -> Union[UnknownPath, ProviderError, SegmentComparisons]:
Expand Down
3 changes: 1 addition & 2 deletions graphql_api/types/line_comparison/line_comparison.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from functools import cached_property
from typing import List, Optional

from ariadne import ObjectType, convert_kwargs_to_snake_case
from ariadne import ObjectType
from shared.utils.merge import LineType

from graphql_api.types.enums import CoverageLine
Expand Down Expand Up @@ -72,7 +72,6 @@ def resolve_content(line_comparison: LineComparison, info) -> str:


@line_comparison_bindable.field("coverageInfo")
@convert_kwargs_to_snake_case
def resolve_coverage_info(
line_comparison: LineComparison,
info,
Expand Down
3 changes: 1 addition & 2 deletions graphql_api/types/me/me.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from typing import Optional

from ariadne import ObjectType, convert_kwargs_to_snake_case
from ariadne import ObjectType
from graphql import GraphQLResolveInfo

from codecov.db import sync_to_async
Expand Down Expand Up @@ -41,7 +41,6 @@ def resolve_owner(user, _):


@me_bindable.field("viewableRepositories")
@convert_kwargs_to_snake_case
def resolve_viewable_repositories(
current_user,
info: GraphQLResolveInfo,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from ariadne import UnionType, convert_kwargs_to_snake_case
from ariadne import UnionType

from codecov.db import sync_to_async
from core.commands.component import ComponentCommands
Expand All @@ -9,7 +9,6 @@


@wrap_error_handling_mutation
@convert_kwargs_to_snake_case
@sync_to_async
def resolve_delete_component_measurements(_, info, input):
command: ComponentCommands = info.context["executor"].get_command("component")
Expand Down
3 changes: 1 addition & 2 deletions graphql_api/types/mutation/delete_flag/delete_flag.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from ariadne import UnionType, convert_kwargs_to_snake_case
from ariadne import UnionType

from codecov.db import sync_to_async
from core.commands.flag import FlagCommands
Expand All @@ -9,7 +9,6 @@


@wrap_error_handling_mutation
@convert_kwargs_to_snake_case
@sync_to_async
def resolve_delete_flag(_, info, input):
command: FlagCommands = info.context["executor"].get_command("flag")
Expand Down
3 changes: 1 addition & 2 deletions graphql_api/types/mutation/onboard_user/onboard_user.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from ariadne import UnionType, convert_kwargs_to_snake_case
from ariadne import UnionType

from graphql_api.helpers.mutation import (
resolve_union_error_type,
Expand All @@ -7,7 +7,6 @@


@wrap_error_handling_mutation
@convert_kwargs_to_snake_case
async def resolve_onboard_user(_, info, input):
command = info.context["executor"].get_command("owner")
input["goals"] = [goal.value for goal in input.get("goals", [])]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from ariadne import UnionType, convert_kwargs_to_snake_case
from ariadne import UnionType

from graphql_api.helpers.mutation import (
require_authenticated,
Expand All @@ -9,7 +9,6 @@

@wrap_error_handling_mutation
@require_authenticated
@convert_kwargs_to_snake_case
async def resolve_regenerate_repository_token(_, info, input):
command = info.context["executor"].get_command("repository")

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from ariadne import UnionType, convert_kwargs_to_snake_case
from ariadne import UnionType

from graphql_api.helpers.mutation import (
require_authenticated,
Expand All @@ -9,7 +9,6 @@

@wrap_error_handling_mutation
@require_authenticated
@convert_kwargs_to_snake_case
async def resolve_save_okta_config(_, info, input):
command = info.context["executor"].get_command("owner")
return await command.save_okta_config(input)
Expand Down
7 changes: 1 addition & 6 deletions graphql_api/types/owner/owner.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import shared.rate_limits as rate_limits
import stripe
import yaml
from ariadne import ObjectType, convert_kwargs_to_snake_case
from ariadne import ObjectType
from graphql import GraphQLResolveInfo

import services.activation as activation
Expand Down Expand Up @@ -53,7 +53,6 @@


@owner_bindable.field("repositories")
@convert_kwargs_to_snake_case
def resolve_repositories(
owner: Owner,
info: GraphQLResolveInfo,
Expand Down Expand Up @@ -108,15 +107,13 @@ def resolve_plan(owner: Owner, info: GraphQLResolveInfo) -> PlanService:


@owner_bindable.field("pretrialPlan")
@convert_kwargs_to_snake_case
@require_part_of_org
def resolve_plan_representation(owner: Owner, info: GraphQLResolveInfo) -> PlanData:
info.context["plan_service"] = PlanService(current_org=owner)
return FREE_PLAN_REPRESENTATIONS[PlanName.BASIC_PLAN_NAME.value]


@owner_bindable.field("availablePlans")
@convert_kwargs_to_snake_case
@require_part_of_org
def resolve_available_plans(owner: Owner, info: GraphQLResolveInfo) -> List[PlanData]:
plan_service = PlanService(current_org=owner)
Expand Down Expand Up @@ -223,7 +220,6 @@ def resolve_org_default_org_username(

@owner_bindable.field("measurements")
@sync_to_async
@convert_kwargs_to_snake_case
def resolve_measurements(
owner: Owner,
info: GraphQLResolveInfo,
Expand Down Expand Up @@ -313,7 +309,6 @@ def resolve_is_github_rate_limited(

@owner_bindable.field("invoice")
@require_part_of_org
@convert_kwargs_to_snake_case
def resolve_owner_invoice(
owner: Owner,
info: GraphQLResolveInfo,
Expand Down
15 changes: 1 addition & 14 deletions graphql_api/types/plan/plan.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from datetime import datetime
from typing import List, Optional

from ariadne import ObjectType, convert_kwargs_to_snake_case
from ariadne import ObjectType

from codecov.db import sync_to_async
from graphql_api.helpers.ariadne import ariadne_load_local_graphql
Expand All @@ -15,39 +15,33 @@


@plan_bindable.field("trialStartDate")
@convert_kwargs_to_snake_case
def resolve_trial_start_date(plan_service: PlanService, info) -> Optional[datetime]:
return plan_service.trial_start_date


@plan_bindable.field("trialTotalDays")
@convert_kwargs_to_snake_case
@sync_to_async
def resolve_trial_total_days(plan_service: PlanService, info) -> Optional[int]:
return plan_service.trial_total_days


@plan_bindable.field("trialEndDate")
@convert_kwargs_to_snake_case
def resolve_trial_end_date(plan_service: PlanService, info) -> Optional[datetime]:
return plan_service.trial_end_date


@plan_bindable.field("trialStatus")
@convert_kwargs_to_snake_case
def resolve_trial_status(plan_service: PlanService, info) -> TrialStatus:
return TrialStatus(plan_service.trial_status)


@plan_bindable.field("marketingName")
@convert_kwargs_to_snake_case
@sync_to_async
def resolve_marketing_name(plan_service: PlanService, info) -> str:
return plan_service.marketing_name


@plan_bindable.field("planName")
@convert_kwargs_to_snake_case
def resolve_plan_name(plan_service: PlanService, info) -> str:
return plan_service.plan_name

Expand All @@ -58,21 +52,18 @@ def resolve_plan_name_as_value(plan_service: PlanService, info) -> str:


@plan_bindable.field("tierName")
@convert_kwargs_to_snake_case
@sync_to_async
def resolve_tier_name(plan_service: PlanService, info) -> str:
return plan_service.tier_name


@plan_bindable.field("billingRate")
@convert_kwargs_to_snake_case
@sync_to_async
def resolve_billing_rate(plan_service: PlanService, info) -> Optional[str]:
return plan_service.billing_rate


@plan_bindable.field("baseUnitPrice")
@convert_kwargs_to_snake_case
@sync_to_async
def resolve_base_unit_price(plan_service: PlanService, info) -> int:
return plan_service.base_unit_price
Expand All @@ -85,29 +76,25 @@ def resolve_benefits(plan_service: PlanService, info) -> List[str]:


@plan_bindable.field("pretrialUsersCount")
@convert_kwargs_to_snake_case
def resolve_pretrial_users_count(plan_service: PlanService, info) -> Optional[int]:
if plan_service.is_org_trialing:
return plan_service.pretrial_users_count
return None


@plan_bindable.field("monthlyUploadLimit")
@convert_kwargs_to_snake_case
@sync_to_async
def resolve_monthly_uploads_limit(plan_service: PlanService, info) -> Optional[int]:
return plan_service.monthly_uploads_limit


@plan_bindable.field("planUserCount")
@convert_kwargs_to_snake_case
@sync_to_async
def resolve_plan_user_count(plan_service: PlanService, info) -> int:
return plan_service.plan_user_count


@plan_bindable.field("hasSeatsLeft")
@convert_kwargs_to_snake_case
@sync_to_async
def resolve_has_seats_left(plan_service: PlanService, info) -> bool:
return plan_service.has_seats_left
7 changes: 1 addition & 6 deletions graphql_api/types/plan_representation/plan_representation.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from typing import List, Optional

from ariadne import ObjectType, convert_kwargs_to_snake_case
from ariadne import ObjectType

from graphql_api.helpers.ariadne import ariadne_load_local_graphql
from plan.constants import PlanData
Expand All @@ -13,13 +13,11 @@


@plan_representation_bindable.field("marketingName")
@convert_kwargs_to_snake_case
def resolve_marketing_name(plan_data: PlanData, info) -> str:
return plan_data.marketing_name


@plan_representation_bindable.field("planName")
@convert_kwargs_to_snake_case
def resolve_plan_name(plan_data: PlanData, info) -> str:
return plan_data.value

Expand All @@ -30,13 +28,11 @@ def resolve_plan_value(plan_data: PlanData, info) -> str:


@plan_representation_bindable.field("billingRate")
@convert_kwargs_to_snake_case
def resolve_billing_rate(plan_data: PlanData, info) -> Optional[str]:
return plan_data.billing_rate


@plan_representation_bindable.field("baseUnitPrice")
@convert_kwargs_to_snake_case
def resolve_base_unit_price(plan_data: PlanData, info) -> int:
return plan_data.base_unit_price

Expand All @@ -58,6 +54,5 @@ def resolve_benefits(plan_data: PlanData, info) -> List[str]:


@plan_representation_bindable.field("monthlyUploadLimit")
@convert_kwargs_to_snake_case
def resolve_monthly_uploads_limit(plan_data: PlanData, info) -> Optional[int]:
return plan_data.monthly_uploads_limit
Loading

0 comments on commit c5b5a8f

Please sign in to comment.