@@ -27,24 +27,35 @@ public class GraphQLProvider {
2727 GraphQL graphQL ;
2828
2929 List <Map > books = ImmutableList .of (
30- ImmutableMap .of ("title" , "Harry Potter and the Chamber of Secrets" , "author" , "J.K. Rowling" )
30+ ImmutableMap .of ("title" , "Harry Potter and the Chamber of Secrets" , "author" , "J.K. Rowling" ),
31+ ImmutableMap .of ("title" , "The Lord of the rings" , "author" , "J. R. R. Tolkien" )
3132 );
3233
33- List <Map > comments = ImmutableList .of (
34+ List <Map > commentsHarryPotter = ImmutableList .of (
3435 ImmutableMap .of ("user" , "andi" , "text" , "great" ),
3536 ImmutableMap .of ("user" , "brad" , "text" , "read better ones" ),
3637 ImmutableMap .of ("user" , "felipe" , "text" , "scary" )
3738 );
39+ List <Map > commentsRings = ImmutableList .of (
40+ ImmutableMap .of ("user" , "andi" , "text" , "too long" ),
41+ ImmutableMap .of ("user" , "anonymous" , "text" , "it is a book?" )
42+ );
3843
3944 DataFetcher <Object > booksFetcher = environment -> books ;
4045 DataFetcher <Object > commentsFetcher = environment -> CompletableFuture .supplyAsync (() -> {
41- sleep ();
42- return comments ;
46+ Map <String , String > source = environment .getSource ();
47+ if (source .get ("title" ).contains ("Potter" )) {
48+ sleep (1000 );
49+ return commentsHarryPotter ;
50+ } else {
51+ sleep (3000 );
52+ return commentsRings ;
53+ }
4354 });
4455
45- private void sleep () {
56+ private void sleep (int time ) {
4657 try {
47- Thread .sleep (2000 );
58+ Thread .sleep (time );
4859 } catch (InterruptedException e ) {
4960 throw new RuntimeException (e );
5061 }
0 commit comments