Skip to content

Commit 11b5495

Browse files
Shashank Kambhampatimeta-codesync[bot]
authored andcommitted
Replace flatbuffer schema support with compact schema in relay compiler
Reviewed By: tyao1 Differential Revision: D96355938 fbshipit-source-id: c4394080d435f1718a2e2256aeabdc239a06fb89
1 parent 39170b0 commit 11b5495

11 files changed

Lines changed: 104 additions & 108 deletions

File tree

compiler/crates/relay-compiler/relay-compiler-config-schema.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,12 @@
207207
"null"
208208
]
209209
},
210+
"schemaCompact": {
211+
"type": [
212+
"string",
213+
"null"
214+
]
215+
},
210216
"schemaConfig": {
211217
"description": "Extra configuration for the GraphQL schema itself.",
212218
"$ref": "#/$defs/SchemaConfig",
@@ -250,12 +256,6 @@
250256
"type": "string"
251257
}
252258
},
253-
"schemaFlatbuffer": {
254-
"type": [
255-
"string",
256-
"null"
257-
]
258-
},
259259
"schemaName": {
260260
"description": "Schema name, if differs from project name.\nIf schema name is unset, the project name will be used as schema name.",
261261
"anyOf": [

compiler/crates/relay-compiler/src/build_project/build_schema.rs

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ use relay_docblock::extend_schema_with_resolver_type_system_definition;
1818
use relay_docblock::validate_resolver_schema;
1919
use schema::SDLSchema;
2020
use schema::SchemaDocuments;
21-
use schema::build_schema_with_flat_buffer_unchecked;
2221
use schema::parse_schema_with_extensions;
2322
use schema_validate_lib::SchemaValidationOptions;
2423
use schema_validate_lib::validate;
@@ -62,32 +61,30 @@ fn build_schema_impl(
6261
config: &Config,
6362
graphql_asts_map: &FnvHashMap<ProjectName, GraphQLAsts>,
6463
) -> DiagnosticsResult<Arc<SDLSchema>> {
65-
if let SchemaLocation::FlatbufferFile(fb_path) = &project_config.schema_location {
66-
// Load flatbuffer (has base schema + SDL extensions, but NOT docblock IRs)
67-
let mut schema = if let Some(fb_sources) =
68-
compiler_state.flatbuffer_schemas.get(&project_config.name)
69-
&& let Some(bytes) = fb_sources.get_current_bytes()
64+
if let SchemaLocation::CompactFile(compact_path) = &project_config.schema_location {
65+
// Load compact schema (has base schema + SDL extensions, but NOT docblock IRs).
66+
// Compact format deserializes directly into InMemorySchema with parallel decoding.
67+
let owned_bytes;
68+
let compact_bytes: &[u8] = if let Some(compact_sources) =
69+
compiler_state.compact_schemas.get(&project_config.name)
70+
&& let Some(bytes) = compact_sources.get_current_bytes()
7071
{
71-
build_schema_with_flat_buffer_unchecked(bytes.clone())
72+
bytes
7273
} else {
73-
let contents = std::fs::read(config.root_dir.join(fb_path))
74+
owned_bytes = std::fs::read(config.root_dir.join(compact_path))
7475
.map_err(|e| vec![Diagnostic::error(e.to_string(), Location::generated())])?;
75-
build_schema_with_flat_buffer_unchecked(contents)
76+
&owned_bytes
7677
};
78+
let mut schema = log_event.time("deserialize_compact_schema_time", || {
79+
SDLSchema::InMemory(schema::compact::deserialize_parallel(compact_bytes))
80+
});
7781

7882
// Extract docblock IRs
7983
let resolver_schema_data = log_event.time("collect_resolver_schema_time", || {
8084
extract_docblock_ir(config, compiler_state, project_config, graphql_asts_map)
8185
})?;
8286

83-
// Apply type IRs as mutations (since they can't be baked into the flatbuffer).
84-
//
85-
// Unlike the non-FB path (InMemorySchema::build), which does a two-pass
86-
// batch build (collect all type names, then resolve all field references),
87-
// here we apply each resolver type definition one-by-one. This works because
88-
// resolver types typically only reference existing base-schema types that are
89-
// already present in the flatbuffer. If cross-resolver-type references become
90-
// necessary, this will need to be converted to a two-pass approach.
87+
// Apply type IRs as mutations
9188
log_event.time(
9289
"build_resolver_types_schema_time",
9390
|| -> DiagnosticsResult<()> {

0 commit comments

Comments
 (0)