@@ -6,7 +6,7 @@ use proc_macro2::Span;
66use proc_macro2:: TokenStream ;
77use schema:: Schema ;
88use selection:: Selection ;
9- use std:: collections:: BTreeMap ;
9+ use std:: collections:: { BTreeMap , BTreeSet } ;
1010use syn:: Ident ;
1111
1212/// This holds all the information we need during the code generation phase.
@@ -120,21 +120,21 @@ impl<'query, 'schema> QueryContext<'query, 'schema> {
120120 }
121121
122122 pub ( crate ) fn response_enum_derives ( & self ) -> TokenStream {
123- let enum_derives: Vec < _ > = self
123+ let always_derives = [
124+ Ident :: new ( "Eq" , Span :: call_site ( ) ) ,
125+ Ident :: new ( "PartialEq" , Span :: call_site ( ) ) ,
126+ ] ;
127+ let mut enum_derives: BTreeSet < _ > = self
124128 . response_derives
125129 . iter ( )
126130 . filter ( |derive| {
127131 !derive. to_string ( ) . contains ( "erialize" )
128132 && !derive. to_string ( ) . contains ( "Deserialize" )
129133 } )
130134 . collect ( ) ;
131-
132- if !enum_derives. is_empty ( ) {
133- quote ! {
134- #[ derive( #( #enum_derives) , * ) ]
135- }
136- } else {
137- quote ! ( )
135+ enum_derives. extend ( always_derives. iter ( ) ) ;
136+ quote ! {
137+ #[ derive( #( #enum_derives) , * ) ]
138138 }
139139 }
140140}
@@ -162,7 +162,10 @@ mod tests {
162162 fn response_enum_derives_does_not_produce_empty_list ( ) {
163163 let schema = :: schema:: Schema :: new ( ) ;
164164 let context = QueryContext :: new_empty ( & schema) ;
165- assert_eq ! ( context. response_enum_derives( ) . to_string( ) , "" ) ;
165+ assert_eq ! (
166+ context. response_enum_derives( ) . to_string( ) ,
167+ "# [ derive ( Eq , PartialEq ) ]"
168+ ) ;
166169 }
167170
168171 #[ test]
@@ -176,7 +179,7 @@ mod tests {
176179
177180 assert_eq ! (
178181 context. response_enum_derives( ) . to_string( ) ,
179- "# [ derive ( PartialEq , PartialOrd ) ]"
182+ "# [ derive ( Eq , PartialEq , PartialOrd ) ]"
180183 ) ;
181184 }
182185
0 commit comments