Skip to content

Commit 4e47221

Browse files
captbaritonemeta-codesync[bot]
authored andcommitted
Report diagnostic when schema shards don't form a complete SDL document
Differential Revision: D114452812 fbshipit-source-id: cbfa55643fc32fcf206863f3aecf1e213f642ddf
1 parent e3baba7 commit 4e47221

5 files changed

Lines changed: 92 additions & 2 deletions

File tree

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
==================================== INPUT ====================================
2+
//- src/App.js
3+
graphql`
4+
query AppQuery {
5+
greeting
6+
}
7+
`
8+
9+
//- relay.config.json
10+
{
11+
"sources": {
12+
"src": "test_project"
13+
},
14+
"projects": {
15+
"test_project": {
16+
"language": "flow",
17+
"schemaDir": "./schema"
18+
}
19+
}
20+
}
21+
22+
//- schema/0000.graphql
23+
type Query {
24+
greeting: String
25+
}
26+
27+
//- schema/0001.graphql
28+
type Mutation {
29+
create_thing: String
30+
==================================== OUTPUT ===================================
31+
✖︎ Schema shard files did not form a complete SDL document — the last file in the sequence did not end with `}`.
32+
33+
All files processed in order:
34+
1: schema/0000.graphql
35+
2: schema/0001.graphql
36+
37+
<generated>: <missing source>
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
//- src/App.js
2+
graphql`
3+
query AppQuery {
4+
greeting
5+
}
6+
`
7+
8+
//- relay.config.json
9+
{
10+
"sources": {
11+
"src": "test_project"
12+
},
13+
"projects": {
14+
"test_project": {
15+
"language": "flow",
16+
"schemaDir": "./schema"
17+
}
18+
}
19+
}
20+
21+
//- schema/0000.graphql
22+
type Query {
23+
greeting: String
24+
}
25+
26+
//- schema/0001.graphql
27+
type Mutation {
28+
create_thing: String

compiler/crates/relay-compiler/tests/relay_compiler_integration_test.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* This source code is licensed under the MIT license found in the
55
* LICENSE file in the root directory of this source tree.
66
*
7-
* @generated SignedSource<<4fa0284246e2d17615f4a165bec3297e>>
7+
* @generated SignedSource<<a04527254ed592c40836185646d8c1cc>>
88
*/
99

1010
mod relay_compiler_integration;
@@ -845,6 +845,13 @@ async fn schema_in_generated_dir() {
845845
test_fixture(transform_fixture, file!(), "schema_in_generated_dir.input", "relay_compiler_integration/fixtures/schema_in_generated_dir.expected", input, expected).await;
846846
}
847847

848+
#[tokio::test]
849+
async fn schema_incomplete_last_shard() {
850+
let input = include_str!("relay_compiler_integration/fixtures/schema_incomplete_last_shard.input");
851+
let expected = include_str!("relay_compiler_integration/fixtures/schema_incomplete_last_shard.expected");
852+
test_fixture(transform_fixture, file!(), "schema_incomplete_last_shard.input", "relay_compiler_integration/fixtures/schema_incomplete_last_shard.expected", input, expected).await;
853+
}
854+
848855
#[tokio::test]
849856
async fn schema_outside_root_dir() {
850857
let input = include_str!("relay_compiler_integration/fixtures/schema_outside_root_dir.input");

compiler/crates/schema/src/errors.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,4 +57,11 @@ pub enum SchemaError {
5757

5858
#[error("The directive `@{0}` can only be used once at this location, but was used {1} times.")]
5959
RepeatedNonRepeatableDirective(StringKey, usize),
60+
61+
#[error(
62+
"Schema shard files did not form a complete SDL document — the last file in the sequence \
63+
did not end with `}}`.\n\n\
64+
All files processed in order:\n{all_files}"
65+
)]
66+
IncompleteSchemaDocument { all_files: String },
6067
}

compiler/crates/schema/src/lib.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@ mod schema;
2222
pub mod suggestion_list;
2323
use std::borrow::Cow;
2424

25+
use common::Diagnostic;
2526
use common::DiagnosticsResult;
27+
use common::Location;
2628
use common::SourceLocationKey;
2729
use common::sync::IntoParallelIterator;
2830
use common::sync::ParallelIterator;
@@ -124,7 +126,16 @@ pub fn parse_schema_with_extensions_parallel<
124126
}
125127
}
126128
if !buffer.is_empty() {
127-
eprintln!("Incomplete schema document: {buffer}")
129+
let all_files = server_sdls
130+
.iter()
131+
.enumerate()
132+
.map(|(i, (_, loc))| format!(" {}: {}", i + 1, loc.path()))
133+
.collect::<Vec<_>>()
134+
.join("\n");
135+
return Err(vec![Diagnostic::error(
136+
errors::SchemaError::IncompleteSchemaDocument { all_files },
137+
Location::generated(),
138+
)]);
128139
}
129140
chunks
130141
}

0 commit comments

Comments
 (0)