5
5
//!
6
6
//! [graphql grammar]: http://facebook.github.io/graphql/October2016/#sec-Appendix-Grammar-Summary
7
7
//!
8
+ #[ cfg( feature = "serde" ) ]
8
9
use serde:: Serialize ;
9
10
10
11
pub use crate :: common:: { Directive , Number , Text , Type , Value } ;
11
12
use crate :: position:: Pos ;
12
13
13
14
/// Root of query data
14
- #[ derive( Debug , Clone , PartialEq , Serialize ) ]
15
+ #[ derive( Debug , Clone , PartialEq ) ]
16
+ #[ cfg_attr( feature = "serde" , derive( Serialize ) ) ]
15
17
pub struct Document < ' a , T : Text < ' a > > {
16
18
pub definitions : Vec < Definition < ' a , T > > ,
17
19
}
@@ -35,13 +37,15 @@ impl<'a> Document<'a, String> {
35
37
}
36
38
}
37
39
38
- #[ derive( Debug , Clone , PartialEq , Serialize ) ]
40
+ #[ derive( Debug , Clone , PartialEq ) ]
41
+ #[ cfg_attr( feature = "serde" , derive( Serialize ) ) ]
39
42
pub enum Definition < ' a , T : Text < ' a > > {
40
43
Operation ( OperationDefinition < ' a , T > ) ,
41
44
Fragment ( FragmentDefinition < ' a , T > ) ,
42
45
}
43
46
44
- #[ derive( Debug , Clone , PartialEq , Serialize ) ]
47
+ #[ derive( Debug , Clone , PartialEq ) ]
48
+ #[ cfg_attr( feature = "serde" , derive( Serialize ) ) ]
45
49
pub struct FragmentDefinition < ' a , T : Text < ' a > > {
46
50
pub position : Pos ,
47
51
pub name : T :: Value ,
@@ -50,15 +54,17 @@ pub struct FragmentDefinition<'a, T: Text<'a>> {
50
54
pub selection_set : SelectionSet < ' a , T > ,
51
55
}
52
56
53
- #[ derive( Debug , Clone , PartialEq , Serialize ) ]
57
+ #[ derive( Debug , Clone , PartialEq ) ]
58
+ #[ cfg_attr( feature = "serde" , derive( Serialize ) ) ]
54
59
pub enum OperationDefinition < ' a , T : Text < ' a > > {
55
60
SelectionSet ( SelectionSet < ' a , T > ) ,
56
61
Query ( Query < ' a , T > ) ,
57
62
Mutation ( Mutation < ' a , T > ) ,
58
63
Subscription ( Subscription < ' a , T > ) ,
59
64
}
60
65
61
- #[ derive( Debug , Clone , PartialEq , Serialize ) ]
66
+ #[ derive( Debug , Clone , PartialEq ) ]
67
+ #[ cfg_attr( feature = "serde" , derive( Serialize ) ) ]
62
68
pub struct Query < ' a , T : Text < ' a > > {
63
69
pub position : Pos ,
64
70
pub name : Option < T :: Value > ,
@@ -67,7 +73,8 @@ pub struct Query<'a, T: Text<'a>> {
67
73
pub selection_set : SelectionSet < ' a , T > ,
68
74
}
69
75
70
- #[ derive( Debug , Clone , PartialEq , Serialize ) ]
76
+ #[ derive( Debug , Clone , PartialEq ) ]
77
+ #[ cfg_attr( feature = "serde" , derive( Serialize ) ) ]
71
78
pub struct Mutation < ' a , T : Text < ' a > > {
72
79
pub position : Pos ,
73
80
pub name : Option < T :: Value > ,
@@ -76,7 +83,8 @@ pub struct Mutation<'a, T: Text<'a>> {
76
83
pub selection_set : SelectionSet < ' a , T > ,
77
84
}
78
85
79
- #[ derive( Debug , Clone , PartialEq , Serialize ) ]
86
+ #[ derive( Debug , Clone , PartialEq ) ]
87
+ #[ cfg_attr( feature = "serde" , derive( Serialize ) ) ]
80
88
pub struct Subscription < ' a , T : Text < ' a > > {
81
89
pub position : Pos ,
82
90
pub name : Option < T :: Value > ,
@@ -85,28 +93,32 @@ pub struct Subscription<'a, T: Text<'a>> {
85
93
pub selection_set : SelectionSet < ' a , T > ,
86
94
}
87
95
88
- #[ derive( Debug , Clone , PartialEq , Serialize ) ]
96
+ #[ derive( Debug , Clone , PartialEq ) ]
97
+ #[ cfg_attr( feature = "serde" , derive( Serialize ) ) ]
89
98
pub struct SelectionSet < ' a , T : Text < ' a > > {
90
99
pub span : ( Pos , Pos ) ,
91
100
pub items : Vec < Selection < ' a , T > > ,
92
101
}
93
102
94
- #[ derive( Debug , Clone , PartialEq , Serialize ) ]
103
+ #[ derive( Debug , Clone , PartialEq ) ]
104
+ #[ cfg_attr( feature = "serde" , derive( Serialize ) ) ]
95
105
pub struct VariableDefinition < ' a , T : Text < ' a > > {
96
106
pub position : Pos ,
97
107
pub name : T :: Value ,
98
108
pub var_type : Type < ' a , T > ,
99
109
pub default_value : Option < Value < ' a , T > > ,
100
110
}
101
111
102
- #[ derive( Debug , Clone , PartialEq , Serialize ) ]
112
+ #[ derive( Debug , Clone , PartialEq ) ]
113
+ #[ cfg_attr( feature = "serde" , derive( Serialize ) ) ]
103
114
pub enum Selection < ' a , T : Text < ' a > > {
104
115
Field ( Field < ' a , T > ) ,
105
116
FragmentSpread ( FragmentSpread < ' a , T > ) ,
106
117
InlineFragment ( InlineFragment < ' a , T > ) ,
107
118
}
108
119
109
- #[ derive( Debug , Clone , PartialEq , Serialize ) ]
120
+ #[ derive( Debug , Clone , PartialEq ) ]
121
+ #[ cfg_attr( feature = "serde" , derive( Serialize ) ) ]
110
122
pub struct Field < ' a , T : Text < ' a > > {
111
123
pub position : Pos ,
112
124
pub alias : Option < T :: Value > ,
@@ -116,19 +128,22 @@ pub struct Field<'a, T: Text<'a>> {
116
128
pub selection_set : SelectionSet < ' a , T > ,
117
129
}
118
130
119
- #[ derive( Debug , Clone , PartialEq , Serialize ) ]
131
+ #[ derive( Debug , Clone , PartialEq ) ]
132
+ #[ cfg_attr( feature = "serde" , derive( Serialize ) ) ]
120
133
pub struct FragmentSpread < ' a , T : Text < ' a > > {
121
134
pub position : Pos ,
122
135
pub fragment_name : T :: Value ,
123
136
pub directives : Vec < Directive < ' a , T > > ,
124
137
}
125
138
126
- #[ derive( Debug , Clone , PartialEq , Serialize ) ]
139
+ #[ derive( Debug , Clone , PartialEq ) ]
140
+ #[ cfg_attr( feature = "serde" , derive( Serialize ) ) ]
127
141
pub enum TypeCondition < ' a , T : Text < ' a > > {
128
142
On ( T :: Value ) ,
129
143
}
130
144
131
- #[ derive( Debug , Clone , PartialEq , Serialize ) ]
145
+ #[ derive( Debug , Clone , PartialEq ) ]
146
+ #[ cfg_attr( feature = "serde" , derive( Serialize ) ) ]
132
147
pub struct InlineFragment < ' a , T : Text < ' a > > {
133
148
pub position : Pos ,
134
149
pub type_condition : Option < TypeCondition < ' a , T > > ,
0 commit comments