@@ -163,7 +163,7 @@ public virtual void Execute_Selection_MultipleScalar()
163163 }
164164
165165 [ Fact ]
166- public virtual void Execute_Selection_Method ( )
166+ public virtual void Execute_Selection_ComputedField ( )
167167 {
168168 // arrange
169169 IServiceCollection services ;
@@ -186,31 +186,33 @@ public virtual void Execute_Selection_Method()
186186 IQueryExecutor executor = schema . MakeExecutable ( ) ;
187187
188188 // act
189- IExecutionResult result = executor . Execute (
190- "{ foos { bar shouldNotVisit } }" ) ;
189+ var result = executor . Execute (
190+ "{ foos { bar computedField } }" ) as IReadOnlyQueryResult ;
191191
192192 // assert
193193 Assert . Empty ( result . Errors ) ;
194194 Assert . NotNull ( resultCtx ) ;
195- Assert . Collection ( resultCtx . ToArray ( ) ,
195+ var foos = result . Data [ "foos" ] as IList < object > ;
196+
197+ Assert . Collection ( foos . ToArray ( ) ,
196198 x =>
197199 {
198- Assert . Equal ( "aa" , x . Bar ) ;
199- Assert . Equal ( 0 , x . Baz ) ;
200- Assert . Null ( x . Nested ) ;
201- Assert . Null ( x . ObjectArray ) ;
200+ var casted = x as IDictionary < string , object > ;
201+ Assert . NotNull ( casted ) ;
202+ Assert . Equal ( "aa" , casted [ "bar" ] ) ;
203+ Assert . Equal ( "aa1" , casted [ "computedField" ] ) ;
202204 } ,
203205 x =>
204206 {
205- Assert . Equal ( "bb" , x . Bar ) ;
206- Assert . Equal ( 0 , x . Baz ) ;
207- Assert . Null ( x . Nested ) ;
208- Assert . Null ( x . ObjectArray ) ;
207+ var casted = x as IDictionary < string , object > ;
208+ Assert . NotNull ( casted ) ;
209+ Assert . Equal ( "bb" , casted [ "bar" ] ) ;
210+ Assert . Equal ( "bb2" , casted [ "computedField" ] ) ;
209211 } ) ;
210212 }
211213
212214 [ Fact ]
213- public virtual void Execute_Selection_EmptyQueue ( )
215+ public virtual void Execute_Selection_ComputedFieldParent ( )
214216 {
215217 // arrange
216218 IServiceCollection services ;
@@ -233,26 +235,80 @@ public virtual void Execute_Selection_EmptyQueue()
233235 IQueryExecutor executor = schema . MakeExecutable ( ) ;
234236
235237 // act
236- IExecutionResult result = executor . Execute (
237- "{ foos { shouldNotVisit } }" ) ;
238+ var result = executor . Execute (
239+ "{ foos { bar computedFieldParent } }" ) as IReadOnlyQueryResult ;
238240
239241 // assert
240242 Assert . Empty ( result . Errors ) ;
241243 Assert . NotNull ( resultCtx ) ;
242- Assert . Collection ( resultCtx . ToArray ( ) ,
244+ var foos = result . Data [ "foos" ] as IList < object > ;
245+
246+ Assert . Collection ( foos . ToArray ( ) ,
243247 x =>
244248 {
245- Assert . Null ( x . Bar ) ;
246- Assert . Equal ( 0 , x . Baz ) ;
247- Assert . Null ( x . Nested ) ;
248- Assert . Null ( x . ObjectArray ) ;
249+ var casted = x as IDictionary < string , object > ;
250+ Assert . NotNull ( casted ) ;
251+ Assert . Equal ( "aa" , casted [ "bar" ] ) ;
252+ Assert . Equal ( "aa1" , casted [ "computedFieldParent" ] ) ;
249253 } ,
250254 x =>
251255 {
252- Assert . Null ( x . Bar ) ;
253- Assert . Equal ( 0 , x . Baz ) ;
254- Assert . Null ( x . Nested ) ;
255- Assert . Null ( x . ObjectArray ) ;
256+ var casted = x as IDictionary < string , object > ;
257+ Assert . NotNull ( casted ) ;
258+ Assert . Equal ( "bb" , casted [ "bar" ] ) ;
259+ Assert . Equal ( "bb2" , casted [ "computedFieldParent" ] ) ;
260+ } ) ;
261+ }
262+
263+ [ Fact ]
264+ public virtual void Execute_Selection_ComputedFieldLambda ( )
265+ {
266+ // arrange
267+ IServiceCollection services ;
268+ Func < IResolverContext , IEnumerable < Foo > > resolver ;
269+ ( services , resolver ) = _provider . CreateResolver ( SAMPLE ) ;
270+
271+ IQueryable < Foo > resultCtx = null ;
272+ ISchema schema = SchemaBuilder . New ( )
273+ . AddServices ( services . BuildServiceProvider ( ) )
274+ . AddObjectType < Foo > (
275+ x => x . Field ( "computedLambdaField" )
276+ . Resolver ( ctx => ctx . Parent < Foo > ( ) . Bar + ctx . Parent < Foo > ( ) . Baz ) )
277+ . AddQueryType < Query > (
278+ d => d . Field ( t => t . Foos )
279+ . Resolver ( resolver )
280+ . Use ( next => async ctx =>
281+ {
282+ await next ( ctx ) . ConfigureAwait ( false ) ;
283+ resultCtx = ctx . Result as IQueryable < Foo > ;
284+ } )
285+ . UseSelection ( ) )
286+ . Create ( ) ;
287+ IQueryExecutor executor = schema . MakeExecutable ( ) ;
288+
289+ // act
290+ var result = executor . Execute (
291+ "{ foos { bar computedLambdaField } }" ) as IReadOnlyQueryResult ;
292+
293+ // assert
294+ Assert . Empty ( result . Errors ) ;
295+ Assert . NotNull ( resultCtx ) ;
296+ var foos = result . Data [ "foos" ] as IList < object > ;
297+
298+ Assert . Collection ( foos . ToArray ( ) ,
299+ x =>
300+ {
301+ var casted = x as IDictionary < string , object > ;
302+ Assert . NotNull ( casted ) ;
303+ Assert . Equal ( "aa" , casted [ "bar" ] ) ;
304+ Assert . Equal ( "aa1" , casted [ "computedLambdaField" ] ) ;
305+ } ,
306+ x =>
307+ {
308+ var casted = x as IDictionary < string , object > ;
309+ Assert . NotNull ( casted ) ;
310+ Assert . Equal ( "bb" , casted [ "bar" ] ) ;
311+ Assert . Equal ( "bb2" , casted [ "computedLambdaField" ] ) ;
256312 } ) ;
257313 }
258314
@@ -485,7 +541,8 @@ public virtual void Execute_Selection_Set_Interface()
485541
486542 // assert
487543 Assert . NotNull ( resultCtx ) ;
488- Assert . Collection ( resultCtx . ToArray ( ) ,
544+ Assert . Collection (
545+ resultCtx . AsEnumerable ( ) . OrderBy ( x => x . ISet . First ( ) . Bar ) . ToArray ( ) ,
489546 x =>
490547 {
491548 Assert . Null ( x . Bar ) ;
@@ -535,7 +592,8 @@ public virtual void Execute_Selection_Set()
535592
536593 // assert
537594 Assert . NotNull ( resultCtx ) ;
538- Assert . Collection ( resultCtx . ToArray ( ) ,
595+ Assert . Collection (
596+ resultCtx . AsEnumerable ( ) . OrderBy ( x => x . HashSet . First ( ) . Bar ) . ToArray ( ) ,
539597 x =>
540598 {
541599 Assert . Null ( x . Bar ) ;
@@ -585,7 +643,8 @@ public virtual void Execute_Selection_SortedSet()
585643
586644 // assert
587645 Assert . NotNull ( resultCtx ) ;
588- Assert . Collection ( resultCtx . ToArray ( ) ,
646+ Assert . Collection (
647+ resultCtx . AsEnumerable ( ) . OrderBy ( x => x . SortedSet . First ( ) . Bar ) . ToArray ( ) ,
589648 x =>
590649 {
591650 Assert . Null ( x . Bar ) ;
@@ -1363,8 +1422,9 @@ public class Foo
13631422 [ UseSorting ]
13641423 public List < NestedFoo > MiddlewareList { get ; set ; }
13651424
1366- public IEnumerable < string > GetShouldNotVisit ( )
1367- => new string [ ] { "should not visit" } ;
1425+ public string GetComputedField ( ) => Bar + Baz ;
1426+
1427+ public string GetComputedFieldParent ( [ Parent ] Foo foo ) => foo . Bar + foo . Baz ;
13681428
13691429 public static Foo Create ( string bar , int baz )
13701430 {
0 commit comments