Skip to content

Commit ce3d251

Browse files
authored
Merge pull request #50 from tomhoule/better-error-message
Improve error message on unnamed queries
2 parents 889c49d + e35380a commit ce3d251

File tree

1 file changed

+29
-1
lines changed

1 file changed

+29
-1
lines changed

graphql_query_derive/src/schema.rs

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,34 @@ use unions::GqlUnion;
1414

1515
pub const DEFAULT_SCALARS: &[&str] = &["ID", "String", "Int", "Float", "Boolean"];
1616

17+
const SELECTION_SET_AT_ROOT: &str = r#"
18+
Operations in queries must be named.
19+
20+
Instead of this:
21+
22+
{
23+
user {
24+
name
25+
repositories {
26+
name
27+
commits
28+
}
29+
}
30+
}
31+
32+
Write this:
33+
34+
query UserRepositories {
35+
user {
36+
name
37+
repositories {
38+
name
39+
commits
40+
}
41+
}
42+
}
43+
"#;
44+
1745
#[derive(Debug, PartialEq)]
1846
pub struct Schema {
1947
pub enums: BTreeMap<String, GqlEnum>,
@@ -120,7 +148,7 @@ impl Schema {
120148
context.register_variables(&q.variable_definitions);
121149
}
122150
query::Definition::Operation(query::OperationDefinition::SelectionSet(_)) => {
123-
unimplemented!()
151+
panic!(SELECTION_SET_AT_ROOT)
124152
}
125153
query::Definition::Fragment(fragment) => {
126154
let query::TypeCondition::On(on) = fragment.type_condition;

0 commit comments

Comments
 (0)