File tree Expand file tree Collapse file tree 2 files changed +19
-6
lines changed Expand file tree Collapse file tree 2 files changed +19
-6
lines changed Original file line number Diff line number Diff line change @@ -48,18 +48,26 @@ pub(crate) fn response_for_query(
48
48
. find ( |op| op. name == selected_operation)
49
49
. map ( |i| i. to_owned ( ) ) ;
50
50
51
- let operation = context. selected_operation . clone ( ) . unwrap_or_else ( || {
51
+ let opt_operation = context. selected_operation . clone ( ) . or_else ( || {
52
52
operations
53
53
. iter ( )
54
54
. next ( )
55
55
. map ( |i| i. to_owned ( ) )
56
- . expect ( "no operation in query document" )
57
56
} ) ;
57
+ let operation = if let Some ( operation) = opt_operation {
58
+ operation
59
+ } else {
60
+ panic ! ( "no operation '{}' in query document" , selected_operation) ;
61
+ } ;
58
62
59
63
let response_data_fields = {
60
- let root_name: String = operation
61
- . root_name ( & context. schema )
62
- . expect ( "operation type not in schema" ) ;
64
+ let opt_root_name = operation
65
+ . root_name ( & context. schema ) ;
66
+ let root_name: String = if let Some ( root_name) = opt_root_name {
67
+ root_name
68
+ } else {
69
+ panic ! ( "operation type '{:?}' not in schema" , operation. operation_type) ;
70
+ } ;
63
71
let definition = context
64
72
. schema
65
73
. objects
Original file line number Diff line number Diff line change @@ -13,7 +13,12 @@ impl GqlFragment {
13
13
pub ( crate ) fn to_rust ( & self , context : & QueryContext ) -> Result < TokenStream , :: failure:: Error > {
14
14
let derives = context. response_derives ( ) ;
15
15
let name_ident = Ident :: new ( & self . name , Span :: call_site ( ) ) ;
16
- let object = context. schema . objects . get ( & self . on ) . expect ( "oh, noes" ) ;
16
+ let opt_object = context. schema . objects . get ( & self . on ) ;
17
+ let object = if let Some ( object) = opt_object {
18
+ object
19
+ } else {
20
+ panic ! ( "fragment '{}' cannot operate on unknown type '{}'" , self . name, self . on) ;
21
+ } ;
17
22
let field_impls = object. field_impls_for_selection ( context, & self . selection , & self . name ) ?;
18
23
let fields = object. response_fields_for_selection ( context, & self . selection , & self . name ) ?;
19
24
You can’t perform that action at this time.
0 commit comments