File tree Expand file tree Collapse file tree 5 files changed +35
-18
lines changed Expand file tree Collapse file tree 5 files changed +35
-18
lines changed Original file line number Diff line number Diff line change @@ -22,3 +22,9 @@ pub fn typename_field() -> GqlObjectField {
22
22
type_ : FieldType :: Named ( string_type ( ) ) ,
23
23
}
24
24
}
25
+
26
+ pub const MULTIPLE_SUBSCRIPTION_FIELDS_ERROR : & str = r##"
27
+ Multiple-field queries on the root subscription field are forbidden by the spec.
28
+
29
+ See: https://github.com/facebook/graphql/blob/master/spec/Section%205%20--%20Validation.md#subscription-operation-definitions
30
+ "## ;
Original file line number Diff line number Diff line change @@ -24,6 +24,7 @@ mod inputs;
24
24
mod interfaces;
25
25
mod introspection_response;
26
26
mod objects;
27
+ mod operations;
27
28
mod query;
28
29
mod scalars;
29
30
mod schema;
Original file line number Diff line number Diff line change
1
+ use selection:: Selection ;
2
+
3
+ pub enum OperationType {
4
+ Query ,
5
+ Mutation ,
6
+ Subscription ,
7
+ }
8
+
9
+ #[ derive( Debug ) ]
10
+ pub struct Operation {
11
+ pub name : String ,
12
+ pub selection : Selection ,
13
+ }
14
+
15
+ pub struct Operations ( Vec < Operation > ) ;
16
+
17
+ impl Operations {
18
+ fn from_document ( doc : :: graphql_parser:: query:: Document ) -> Result < Self , :: failure:: Error > {
19
+ unimplemented ! ( )
20
+ }
21
+ }
Original file line number Diff line number Diff line change @@ -9,10 +9,8 @@ use variables::Variable;
9
9
10
10
/// This holds all the information we need during the code generation phase.
11
11
pub struct QueryContext {
12
- pub _subscription_root : Option < Vec < TokenStream > > ,
12
+ pub root : Option < Vec < TokenStream > > ,
13
13
pub fragments : BTreeMap < String , GqlFragment > ,
14
- pub mutation_root : Option < Vec < TokenStream > > ,
15
- pub query_root : Option < Vec < TokenStream > > ,
16
14
pub schema : Schema ,
17
15
pub variables : Vec < Variable > ,
18
16
}
@@ -21,10 +19,8 @@ impl QueryContext {
21
19
/// Create a QueryContext with the given Schema.
22
20
pub fn new ( schema : Schema ) -> QueryContext {
23
21
QueryContext {
24
- _subscription_root : None ,
22
+ root : None ,
25
23
fragments : BTreeMap :: new ( ) ,
26
- mutation_root : None ,
27
- query_root : None ,
28
24
schema,
29
25
variables : Vec :: new ( ) ,
30
26
}
@@ -72,10 +68,8 @@ impl QueryContext {
72
68
#[ cfg( test) ]
73
69
pub fn new_empty ( ) -> QueryContext {
74
70
QueryContext {
75
- _subscription_root : None ,
76
71
fragments : BTreeMap :: new ( ) ,
77
- mutation_root : None ,
78
- query_root : None ,
72
+ root : None ,
79
73
schema : Schema :: new ( ) ,
80
74
variables : Vec :: new ( ) ,
81
75
}
Original file line number Diff line number Diff line change @@ -78,7 +78,7 @@ impl Schema {
78
78
for definition in query. definitions {
79
79
match definition {
80
80
query:: Definition :: Operation ( query:: OperationDefinition :: Query ( q) ) => {
81
- context. query_root = {
81
+ context. root = {
82
82
let definition = context
83
83
. schema
84
84
. query_type
@@ -101,7 +101,7 @@ impl Schema {
101
101
context. register_variables ( & q. variable_definitions ) ;
102
102
}
103
103
query:: Definition :: Operation ( query:: OperationDefinition :: Mutation ( q) ) => {
104
- context. mutation_root = {
104
+ context. root = {
105
105
let definition = context
106
106
. schema
107
107
. mutation_type
@@ -124,7 +124,7 @@ impl Schema {
124
124
context. register_variables ( & q. variable_definitions ) ;
125
125
}
126
126
query:: Definition :: Operation ( query:: OperationDefinition :: Subscription ( q) ) => {
127
- context. _subscription_root = {
127
+ context. root = {
128
128
let definition = context
129
129
. schema
130
130
. subscription_type
@@ -173,12 +173,7 @@ impl Schema {
173
173
. collect ( ) ;
174
174
let fragment_definitions = fragment_definitions?;
175
175
let variables_struct = context. expand_variables ( ) ;
176
- let response_data_fields = context
177
- . query_root
178
- . as_ref ( )
179
- . or_else ( || context. mutation_root . as_ref ( ) )
180
- . or_else ( || context. _subscription_root . as_ref ( ) )
181
- . expect ( "no selection defined" ) ;
176
+ let response_data_fields = context. root . as_ref ( ) . expect ( "no selection defined" ) ;
182
177
183
178
let input_object_definitions: Result < Vec < TokenStream > , _ > = context
184
179
. schema
You can’t perform that action at this time.
0 commit comments