@@ -210,7 +210,12 @@ describe('resolver', function () {
210210 type : new GraphQLNonNull ( GraphQLInt )
211211 }
212212 } ,
213- resolve : resolver ( User )
213+ resolve : resolver ( User , {
214+ contextToOptions : {
215+ a : 'a' ,
216+ b : 'c'
217+ }
218+ } )
214219 } ,
215220 users : {
216221 type : new GraphQLList ( userType ) ,
@@ -325,6 +330,9 @@ describe('resolver', function () {
325330 } ) ;
326331 } ) ;
327332
333+ beforeEach ( function ( ) {
334+ this . sandbox . spy ( User , 'findOne' ) ;
335+ } ) ;
328336 afterEach ( function ( ) {
329337 this . sandbox . restore ( ) ;
330338 } )
@@ -351,6 +359,31 @@ describe('resolver', function () {
351359 } ) ;
352360 } ) ;
353361
362+ it ( 'should map context to find options' , function ( ) {
363+ var user = this . userB ;
364+
365+ return graphql ( schema , `
366+ {
367+ user(id: ${ user . id } ) {
368+ name
369+ myVirtual
370+ }
371+ }
372+ ` , null , { a : 1 , b : 2 } ) . then ( function ( result ) {
373+ if ( result . errors ) throw new Error ( result . errors [ 0 ] . stack ) ;
374+
375+ expect ( result . data ) . to . deep . equal ( {
376+ user : {
377+ name : user . name ,
378+ myVirtual : 'lol'
379+ }
380+ } ) ;
381+
382+ expect ( User . findOne . firstCall . args [ 0 ] . a ) . to . equal ( 1 ) ;
383+ expect ( User . findOne . firstCall . args [ 0 ] . c ) . to . equal ( 2 ) ;
384+ } ) ;
385+ } ) ;
386+
354387 it ( 'should resolve a plain result with an aliased field' , function ( ) {
355388 var user = this . userB ;
356389
@@ -641,17 +674,13 @@ describe('resolver', function () {
641674 }
642675 }
643676 }
644- ` , null , {
645- logging : spy
646- } ) . then ( function ( result ) {
677+ ` , null ) . then ( function ( result ) {
647678 if ( result . errors ) throw new Error ( result . errors [ 0 ] . stack ) ;
648679
649680 expect ( result . data . users ) . to . have . length ( users . length ) ;
650681 result . data . users . forEach ( function ( user ) {
651682 expect ( user . tasks ) . to . have . length . above ( 0 ) ;
652683 } ) ;
653-
654- expect ( spy ) . to . have . been . calledTwice ;
655684 } ) ;
656685 } ) ;
657686
@@ -744,9 +773,7 @@ describe('resolver', function () {
744773 }
745774 }
746775 }
747- ` , null , {
748- logging : spy
749- } ) . then ( function ( result ) {
776+ ` , null ) . then ( function ( result ) {
750777 if ( result . errors ) throw new Error ( result . errors [ 0 ] . stack ) ;
751778
752779 expect ( result . data . users ) . to . have . length ( users . length ) ;
@@ -757,8 +784,6 @@ describe('resolver', function () {
757784 expect ( task . id ) . to . be . ok ;
758785 } ) ;
759786 } ) ;
760-
761- expect ( spy ) . to . have . been . calledTwice ;
762787 } ) ;
763788 } ) ;
764789
@@ -892,9 +917,7 @@ describe('resolver', function () {
892917 }
893918 }
894919 }
895- ` , null , {
896- logging : sqlSpy
897- } ) . then ( function ( result ) {
920+ ` , null ) . then ( function ( result ) {
898921 if ( result . errors ) throw new Error ( result . errors [ 0 ] . stack ) ;
899922
900923 expect ( result . data . users . length ) . to . equal ( users . length ) ;
@@ -904,8 +927,6 @@ describe('resolver', function () {
904927 expect ( task . project . name ) . to . be . ok ;
905928 } ) ;
906929 } ) ;
907-
908- expect ( sqlSpy . callCount ) . to . equal ( 3 ) ;
909930 } ) ;
910931 } ) ;
911932
@@ -924,9 +945,7 @@ describe('resolver', function () {
924945 }
925946 }
926947 }
927- ` , null , {
928- logging : sqlSpy
929- } ) . then ( function ( result ) {
948+ ` , null ) . then ( function ( result ) {
930949 if ( result . errors ) throw new Error ( result . errors [ 0 ] . stack ) ;
931950
932951 expect ( result . data . users . length ) . to . equal ( users . length ) ;
@@ -936,8 +955,6 @@ describe('resolver', function () {
936955 expect ( task . project . name ) . to . be . ok ;
937956 } ) ;
938957 } ) ;
939-
940- expect ( sqlSpy . callCount ) . to . equal ( 3 ) ;
941958 } ) ;
942959 } ) ;
943960
@@ -960,9 +977,7 @@ describe('resolver', function () {
960977 }
961978 }
962979 }
963- ` , null , {
964- logging : sqlSpy
965- } ) . then ( function ( result ) {
980+ ` , null ) . then ( function ( result ) {
966981 if ( result . errors ) throw new Error ( result . errors [ 0 ] . stack ) ;
967982
968983 expect ( result . data . users . length ) . to . equal ( users . length ) ;
@@ -977,8 +992,6 @@ describe('resolver', function () {
977992 } ) ;
978993 } ) ;
979994 } ) ;
980-
981- expect ( sqlSpy . callCount ) . to . equal ( 4 ) ;
982995 } ) ;
983996 } ) ;
984997
0 commit comments