@@ -126,154 +126,6 @@ impl FieldAttributes {
126
126
}
127
127
}
128
128
129
- pub struct GraphQLTypeDefinitionFieldArg {
130
- pub name : String ,
131
- pub description : Option < String > ,
132
- pub _type : syn:: Type ,
133
- }
134
-
135
- pub struct GraphQLTypeDefinitionField {
136
- pub name : String ,
137
- pub _type : syn:: Type ,
138
- pub description : Option < String > ,
139
- pub deprecation : Option < String > ,
140
- pub args : Vec < GraphQLTypeDefinitionFieldArg > ,
141
- pub resolver_code : proc_macro2:: TokenStream ,
142
- }
143
-
144
- /// Definition of a graphql type based on information extracted
145
- /// by various macros.
146
- /// The definition can be rendered to Rust code.
147
- pub struct GraphQLTypeDefiniton {
148
- pub name : String ,
149
- pub _type : syn:: Type ,
150
- pub context : Option < syn:: Type > ,
151
- pub scalar : Option < syn:: Type > ,
152
- pub description : Option < String > ,
153
- pub fields : Vec < GraphQLTypeDefinitionField > ,
154
- }
155
-
156
- impl GraphQLTypeDefiniton {
157
- fn to_tokens ( & self ) -> proc_macro2:: TokenStream {
158
- let name = & self . name ;
159
- let ty = & self . _type ;
160
- let context = self
161
- . context
162
- . as_ref ( )
163
- . map ( |ctx| quote ! ( #ctx ) )
164
- . unwrap_or ( quote ! ( ( ) ) ) ;
165
- let scalar = self
166
- . scalar
167
- . as_ref ( )
168
- . map ( |s| quote ! ( #s ) )
169
- . unwrap_or ( quote ! ( juniper:: DefaultScalarValue ) ) ;
170
-
171
- let field_definitions = self . fields . iter ( ) . map ( |field| {
172
- let args = field. args . iter ( ) . map ( |arg| {
173
- let arg_type = & arg. _type ;
174
- let arg_name = & arg. name ;
175
- quote ! {
176
- . argument( registry. arg:: <#arg_type>( #arg_name, info) )
177
- }
178
- } ) ;
179
-
180
- let description = match field. description . as_ref ( ) {
181
- Some ( description) => quote ! ( . description( #description) ) ,
182
- None => quote ! ( ) ,
183
- } ;
184
-
185
- let deprecation = match field. deprecation . as_ref ( ) {
186
- Some ( deprecation) => quote ! ( . deprecation( #deprecation) ) ,
187
- None => quote ! ( ) ,
188
- } ;
189
-
190
- let field_name = & field. name ;
191
-
192
- let _type = & field. _type ;
193
- quote ! {
194
- registry
195
- . field_convert:: <#_type, _, Self :: Context >( #field_name, info)
196
- #( #args) *
197
- #description
198
- #deprecation
199
- }
200
- } ) ;
201
-
202
- let resolve_matches = self . fields . iter ( ) . map ( |field| {
203
- let name = & field. name ;
204
- let code = & field. resolver_code ;
205
-
206
- quote ! (
207
- #name => {
208
- let res = #code;
209
- juniper:: IntoResolvable :: into(
210
- res,
211
- executor. context( )
212
- )
213
- . and_then( |res| {
214
- match res {
215
- Some ( ( ctx, r) ) => executor. replaced_context( ctx) . resolve_with_ctx( & ( ) , & r) ,
216
- None => Ok ( juniper:: Value :: null( ) ) ,
217
- }
218
- } )
219
- } ,
220
- )
221
- } ) ;
222
-
223
- let description = match self . description . as_ref ( ) {
224
- Some ( description) => quote ! ( . description( #description) ) ,
225
- None => quote ! ( ) ,
226
- } ;
227
-
228
- quote ! (
229
- impl juniper:: GraphQLType <#scalar> for #ty {
230
- type Context = #context;
231
- type TypeInfo = ( ) ;
232
-
233
- fn name( _: & Self :: TypeInfo ) -> Option <& str > {
234
- Some ( #name)
235
- }
236
-
237
- fn meta<' r>(
238
- info: & Self :: TypeInfo ,
239
- registry: & mut juniper:: Registry <' r, #scalar>
240
- ) -> juniper:: meta:: MetaType <' r, #scalar>
241
- where #scalar : ' r,
242
- for <' z> & ' z juniper:: DefaultScalarValue : juniper:: ScalarRefValue <' z>,
243
- {
244
- let fields = vec![
245
- #( #field_definitions ) , *
246
- ] ;
247
- let meta = registry. build_object_type:: <#ty>( info, & fields ) ;
248
- let meta = meta # description;
249
- meta. into_meta( )
250
- }
251
-
252
- #[ allow( unused_variables) ]
253
- #[ allow( unused_mut) ]
254
- fn resolve_field(
255
- & self ,
256
- _info: & ( ) ,
257
- field: & str ,
258
- args: & juniper:: Arguments ,
259
- executor: & juniper:: Executor <Self :: Context >,
260
- ) -> juniper:: ExecutionResult {
261
- match field {
262
- #( #resolve_matches ) *
263
- _ => {
264
- panic!( "Field {} not found on type {}" , field, "Mutation" ) ;
265
- }
266
- }
267
- }
268
-
269
- fn concrete_type_name( & self , _: & Self :: Context , _: & Self :: TypeInfo ) -> String {
270
- #name. to_string( )
271
- }
272
-
273
- }
274
- )
275
- }
276
- }
277
129
278
130
/// Generate code for the juniper::impl_object macro.
279
131
pub fn build ( args : TokenStream , body : TokenStream ) -> TokenStream {
@@ -309,7 +161,7 @@ pub fn build(args: TokenStream, body: TokenStream) -> TokenStream {
309
161
310
162
let target_type = * _impl. self_ty . clone ( ) ;
311
163
312
- let mut definition = GraphQLTypeDefiniton {
164
+ let mut definition = util :: GraphQLTypeDefiniton {
313
165
name,
314
166
_type : target_type. clone ( ) ,
315
167
context : impl_attrs. context ,
@@ -386,7 +238,7 @@ pub fn build(args: TokenStream, body: TokenStream) -> TokenStream {
386
238
. get:: <#ty>( #arg_name)
387
239
. expect( "Argument missing - validation must have failed" )
388
240
) ) ;
389
- args. push ( GraphQLTypeDefinitionFieldArg {
241
+ args. push ( util :: GraphQLTypeDefinitionFieldArg {
390
242
name : arg_name,
391
243
description : None ,
392
244
_type : ty. clone ( ) ,
@@ -407,7 +259,7 @@ pub fn build(args: TokenStream, body: TokenStream) -> TokenStream {
407
259
. unwrap_or ( util:: to_camel_case ( & method_ident. to_string ( ) ) ) ;
408
260
let description = attrs. description . or ( util:: get_doc_comment ( & method. attrs ) ) ;
409
261
410
- definition. fields . push ( GraphQLTypeDefinitionField {
262
+ definition. fields . push ( util :: GraphQLTypeDefinitionField {
411
263
name,
412
264
_type,
413
265
args,
0 commit comments