Skip to content

Commit 0ce962c

Browse files
ginfungmeta-codesync[bot]
authored andcommitted
Add Android support to shared GraphQL providers and codegen rule
Summary: Extend the shared `GraphQLInfo` provider and `graphql_codegen` UDR rule to support both iOS and Android using platform-specific record types. Integrate into Android `graphql_library_defs.bzl` in hybrid mode alongside the legacy genrule chain. Changes: - Move `fbcode/buck2/prelude/apple/graphql.bzl` to `fbcode/buck2/prelude/graphql/graphql.bzl` (shared location in its own folder). - Define `GraphQLiOSInfo` and `GraphQLAndroidInfo` as separate `record()` types, each containing the full set of fields for their platform. `GraphQLInfo` is a provider with two optional fields: `ios: GraphQLiOSInfo | None` and `android: GraphQLAndroidInfo | None`. Each instance is either iOS or Android, never a mix. - Add `graphql_providers(ctx, deps)` as a single merged function for both platforms. iOS calls with `cxx_attr_deps`, Android calls with `ctx.attrs.deps`. - Modify `tools/build_defs/graphql/rules/graphql_codegen.bzl`: Add `platform` attr ("ios" or "android") to select which record type to create. JSON output extracts fields from the platform-specific record via `_get_platform_info()` helper. - Add `platform = "ios"` to existing iOS `graphql_codegen()` call sites. - Modify `fbcode/buck2/prelude/android/android_library.bzl`: Append `graphql_providers(ctx, ctx.attrs.deps)` to propagate GraphQL providers through the Android dep graph. - Integrate `graphql_codegen()` into `graphql_library_defs.bzl` with `platform = "android"`, passing Android-specific fields from `graphql_bad_practices` and `composition_mode` from the build config's `JAVA_INTERFACES` capability. - Update all import paths to `prelude//graphql:graphql.bzl`. Legacy targets (`_local_graphql_files`, `__collected_graphql_deps`, `_recursive_graphql_files`) remain unchanged -- this is additive/hybrid. Reviewed By: rmaz Differential Revision: D97816914 fbshipit-source-id: d26883231857ed1a2dd01aeb02c4b30690c05e75
1 parent 9b899e4 commit 0ce962c

3 files changed

Lines changed: 15 additions & 3 deletions

File tree

prelude/android/android_library.bzl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ load(
1616
)
1717
load("@prelude//android:android_toolchain.bzl", "AndroidToolchainInfo")
1818
load("@prelude//android:r_dot_java.bzl", "get_dummy_r_dot_java")
19+
load("@prelude//graphql:graphql.bzl", "graphql_providers")
1920
load("@prelude//java:java_library.bzl", "build_java_library")
2021
load(
2122
"@prelude//java:java_providers.bzl",
@@ -81,7 +82,7 @@ def android_library_impl(ctx: AnalysisContext) -> list[Provider]:
8182
manifest = ctx.attrs.manifest,
8283
),
8384
merge_exported_android_resource_info(ctx.attrs.exported_deps),
84-
] + android_providers + [LabelInfo(labels = ctx.attrs.labels)]
85+
] + android_providers + [LabelInfo(labels = ctx.attrs.labels)] + graphql_providers(ctx)
8586

8687
def optional_jars(ctx: AnalysisContext) -> list[Artifact]:
8788
if not ctx.attrs.android_optional_jars:

prelude/apple/apple_library.bzl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ load("@prelude//:paths.bzl", "paths")
1515
load("@prelude//:validation_deps.bzl", "get_validation_deps_outputs")
1616
load("@prelude//apple:apple_dsym.bzl", "DSYM_SUBTARGET", "get_apple_dsym")
1717
load("@prelude//apple:apple_stripping.bzl", "apple_strip_args")
18-
load("@prelude//apple:graphql.bzl", "graphql_providers")
1918
# @oss-disable[end= ]: load("@prelude//apple/meta_only:apple_library_meta_validation.bzl", "apple_library_validate_for_meta_restrictions")
2019
# @oss-disable[end= ]: load("@prelude//apple/meta_only:linker_outputs.bzl", "extra_distributed_thin_lto_opt_outputs_merger", "get_extra_linker_output_flags", "get_extra_linker_outputs")
2120
load("@prelude//apple/mockingbird:mockingbird_types.bzl", "MockingbirdLibraryInfo", "MockingbirdLibraryInfoTSet", "MockingbirdLibraryRecord", "MockingbirdSourcesInfo", "MockingbirdTargetType")
@@ -94,6 +93,7 @@ load(
9493
"CPreprocessorInfo", # @unused Used as a type
9594
)
9695
load("@prelude//cxx:target_sdk_version.bzl", "get_unversioned_target_triple")
96+
load("@prelude//graphql:graphql.bzl", "graphql_providers")
9797
load(
9898
"@prelude//linking:link_info.bzl",
9999
"ExtraLinkerOutputs",
Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,24 @@ load(
1717
"cxx_attr_exported_deps",
1818
)
1919

20+
GraphQLiOSInfo = record(
21+
header_path_prefix = str | None,
22+
)
23+
24+
GraphQLAndroidInfo = record(
25+
allow_legacy_fragments = bool,
26+
allow_type_models = bool,
27+
composition_mode = str | None,
28+
enable_associated_library = bool,
29+
)
30+
2031
GraphQLInfo = provider(
2132
fields = {
2233
"config_name": provider_field(str),
2334
"enforce_colocation": provider_field(bool),
24-
"header_path_prefix": provider_field(str | None),
2535
"is_subconfig": provider_field(bool),
2636
"is_test_target": provider_field(bool),
37+
"platform_config": provider_field(GraphQLAndroidInfo | GraphQLiOSInfo),
2738
"srcs": provider_field(list[Artifact]),
2839
"target": provider_field(Label),
2940
},

0 commit comments

Comments
 (0)