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

feat: Bundle Analysis v0.5 Update GraphQL schema #405

Merged
merged 9 commits into from
Feb 20, 2024
164 changes: 143 additions & 21 deletions graphql_api/tests/test_commit.py
Original file line number Diff line number Diff line change
Expand Up @@ -932,31 +932,70 @@ def test_bundle_analysis_report(self, get_storage_service):
)
storage.write_file(get_bucket_name(), storage_path, f)

query = (
query_commit
% """
bundleAnalysisReport {
__typename
... on BundleAnalysisReport {
sizeTotal
loadTimeTotal
bundles {
name
sizeTotal
loadTimeTotal
query = """
query FetchCommit($org: String!, $repo: String!, $commit: String!, $filters: BundleAnalysisReportFilters) {
owner(username: $org) {
repository(name: $repo) {
... on Repository {
commit(id: $commit) {
bundleAnalysisReport {
__typename
... on BundleAnalysisReport {
sizeTotal
loadTimeTotal
bundles {
name
sizeTotal
loadTimeTotal
moduleExtensions
moduleCount
assets(filters: $filters) {
name
}
asset(name: "not_exist") {
name
}
bundleData {
loadTime {
threeG
highSpeed
}
size {
gzip
uncompress
}
}
}
bundleData {
loadTime {
threeG
highSpeed
}
size {
gzip
uncompress
}
}
bundle(name: "not_exist") {
name
}
}
... on MissingHeadReport {
message
}
}
}
}
}
}
... on MissingHeadReport {
message
}
}
"""
)
"""

variables = {
"org": self.org.username,
"repo": self.repo.name,
"commit": self.commit.commitid,
"filters": {"moduleExtensions": []},
}
data = self.gql_request(query, variables=variables)
commit = data["owner"]["repository"]["commit"]
Expand All @@ -966,11 +1005,94 @@ def test_bundle_analysis_report(self, get_storage_service):
"sizeTotal": 201720,
"loadTimeTotal": 0.5,
"bundles": [
{"name": "b1", "sizeTotal": 20, "loadTimeTotal": 0.0},
{"name": "b2", "sizeTotal": 200, "loadTimeTotal": 0.0},
{"name": "b3", "sizeTotal": 1500, "loadTimeTotal": 0.0},
{"name": "b5", "sizeTotal": 200000, "loadTimeTotal": 0.5},
{
"name": "b1",
"sizeTotal": 20,
"loadTimeTotal": 0.0,
"moduleExtensions": [],
"moduleCount": 0,
"assets": [],
"asset": None,
"bundleData": {
"loadTime": {
"threeG": 0,
"highSpeed": 0,
},
"size": {
"gzip": 0,
"uncompress": 20,
},
},
},
{
"name": "b2",
"sizeTotal": 200,
"loadTimeTotal": 0.0,
"moduleExtensions": [],
"moduleCount": 0,
"assets": [],
"asset": None,
"bundleData": {
"loadTime": {
"threeG": 2,
"highSpeed": 0,
},
"size": {
"gzip": 0,
"uncompress": 200,
},
},
},
{
"name": "b3",
"sizeTotal": 1500,
"loadTimeTotal": 0.0,
"moduleExtensions": [],
"moduleCount": 0,
"assets": [],
"asset": None,
"bundleData": {
"loadTime": {
"threeG": 16,
"highSpeed": 0,
},
"size": {
"gzip": 1,
"uncompress": 1500,
},
},
},
{
"name": "b5",
"sizeTotal": 200000,
"loadTimeTotal": 0.5,
"moduleExtensions": [],
"moduleCount": 0,
"assets": [],
"asset": None,
"bundleData": {
"loadTime": {
"threeG": 2133,
"highSpeed": 53,
},
"size": {
"gzip": 200,
"uncompress": 200000,
},
},
},
],
"bundleData": {
"loadTime": {
"threeG": 2151,
"highSpeed": 53,
},
"size": {
"gzip": 201,
"uncompress": 201720,
},
},
"bundle": None,
}

def test_compare_with_parent_missing_change_coverage(self):
Expand Down
14 changes: 10 additions & 4 deletions graphql_api/types/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,18 @@

Copy link
Contributor Author

@JerrySentry JerrySentry Feb 16, 2024

Choose a reason for hiding this comment

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

This file is all boilerplate imports

from ..helpers.ariadne import ariadne_load_local_graphql
from .branch import branch, branch_bindable
from .bundle_analysis_comparison import (
from .bundle_analysis import (
bundle_analysis,
bundle_analysis_comparison,
bundle_analysis_comparison_bindable,
bundle_analysis_comparison_result_bindable,
bundle_comparison_bindable,
)
from .bundle_analysis_report import (
bundle_analysis_report,
bundle_analysis_report_bindable,
bundle_analysis_report_result_bindable,
bundle_asset_bindable,
bundle_comparison_bindable,
bundle_data_bindable,
bundle_module_bindable,
bundle_report_bindable,
)
from .commit import commit, commit_bindable
Expand Down Expand Up @@ -70,6 +72,7 @@
query,
me,
branch,
bundle_analysis,
bundle_analysis_comparison,
bundle_analysis_report,
commit,
Expand Down Expand Up @@ -108,6 +111,9 @@
query_bindable,
me_bindable,
branch_bindable,
bundle_module_bindable,
bundle_asset_bindable,
bundle_data_bindable,
bundle_analysis_comparison_result_bindable,
bundle_analysis_comparison_bindable,
bundle_comparison_bindable,
Expand Down
21 changes: 21 additions & 0 deletions graphql_api/types/bundle_analysis/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
from graphql_api.helpers.ariadne import ariadne_load_local_graphql
Copy link
Contributor Author

Choose a reason for hiding this comment

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

More boilerplate imports and refactored the folder structure to be:

bundle_analysis/
  base.py
  report.py
  comparison.py

before it was

bundle_analysis_comparison/
  comparison.py
bundle_analysis_report/
  report.py


from .base import (
bundle_asset_bindable,
bundle_data_bindable,
bundle_module_bindable,
bundle_report_bindable,
)
from .comparison import (
bundle_analysis_comparison_bindable,
bundle_analysis_comparison_result_bindable,
bundle_comparison_bindable,
)
from .report import (
bundle_analysis_report_bindable,
bundle_analysis_report_result_bindable,
)

bundle_analysis = ariadne_load_local_graphql(__file__, "base.graphql")
bundle_analysis_comparison = ariadne_load_local_graphql(__file__, "comparison.graphql")
bundle_analysis_report = ariadne_load_local_graphql(__file__, "report.graphql")
38 changes: 38 additions & 0 deletions graphql_api/types/bundle_analysis/base.graphql
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
type BundleSize {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

All the new types here, except BundleReport is modified.

gzip: Int!
uncompress: Int!
}

type BundleLoadTime {
threeG: Int!
highSpeed: Int!
}

type BundleData {
loadTime: BundleLoadTime!
size: BundleSize!
}

type BundleModule {
name: String!
bundleData: BundleData!
}

type BundleAsset {
name: String!
normalizedName: String!
moduleExtensions: [String!]!
modules: [BundleModule]!
bundleData: BundleData!
}

type BundleReport {
name: String!
sizeTotal: Int!
loadTimeTotal: Float!
moduleExtensions: [String!]!
moduleCount: Int!
assets(filters: BundleAnalysisReportFilters): [BundleAsset]!
asset(name: String!): BundleAsset
bundleData: BundleData!
}
80 changes: 80 additions & 0 deletions graphql_api/types/bundle_analysis/base.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
from typing import List, Mapping
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added lots of Unimplemented resolvers here for coming PRs and also implemented a new way to present size and load times. Also marked the old ways of calculating it to be removed when it is fully migrated on the FE.


from ariadne import ObjectType

from services.bundle_analysis import (
BundleData,
BundleLoadTime,
BundleReport,
BundleSize,
)

bundle_data_bindable = ObjectType("BundleData")
bundle_module_bindable = ObjectType("BundleModule")
bundle_asset_bindable = ObjectType("BundleAsset")
bundle_report_bindable = ObjectType("BundleReport")

# ============= Bundle Data Bindable =============


@bundle_data_bindable.field("size")
def resolve_bundle_size(bundle_data: BundleData, info) -> BundleSize:
return bundle_data.size


@bundle_data_bindable.field("loadTime")
def resolve_bundle_load_time(bundle_data: BundleData, info) -> BundleLoadTime:
return bundle_data.load_time


# ============= Bundle Report Bindable =============


@bundle_report_bindable.field("name")
def resolve_name(bundle_report: BundleReport, info) -> str:
return bundle_report.bundle_name


# TODO: depreacted with Issue 1199
@bundle_report_bindable.field("sizeTotal")
def resolve_size_total(bundle_report: BundleReport, info) -> int:
return bundle_report.size_total


# TODO: depreacted with Issue 1199
@bundle_report_bindable.field("loadTimeTotal")
def resolve_load_time_total(bundle_report: BundleReport, info) -> float:
return bundle_report.load_time_total


@bundle_report_bindable.field("moduleExtensions")
def resolve_module_extensions(bundle_report: BundleReport, info) -> List[str]:
# TODO: Unimplemented
return []


@bundle_report_bindable.field("moduleCount")
def resolve_module_count(bundle_report: BundleReport, info) -> List[str]:
# TODO: Unimplemented
return 0


@bundle_report_bindable.field("assets")
def resolve_assets(
bundle_report: BundleReport,
info,
filters: Mapping = None,
) -> List[str]:
# TODO: Unimplemented
return []


@bundle_report_bindable.field("asset")
def resolve_asset(bundle_report: BundleReport, info, name: str) -> List[str]:
# TODO: Unimplemented
return None


@bundle_report_bindable.field("bundleData")
def resolve_bundle_data(bundle_report: BundleReport, info) -> BundleData:
return BundleData(bundle_report.size_total)
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,6 @@ type BundleAnalysisReport {
sizeTotal: Int!
loadTimeTotal: Float!
bundles: [BundleReport]!
bundleData: BundleData!
bundle(name: String!): BundleReport
}

type BundleReport {
name: String!
sizeTotal: Int!
loadTimeTotal: Float!
}
Loading
Loading