@@ -20,23 +20,35 @@ const resolvers = {
2020 } ,
2121 addressAuthor ( parent , args , context ) {
2222 let returnAddress = { }
23- for ( let k = 0 ; k < db . authors . length ; k ++ ) {
23+ for ( let k = 0 ; k < db . authors . length ; k ++ ) {
2424 if ( db . authors [ k ] . name === args . name ) {
25- for ( let i = 0 ; i < db . address . length ; i ++ ) {
26- if ( db . address [ i ] . id === db . authors [ k ] . address ) {
25+ for ( let i = 0 ; i < db . address . length ; i ++ ) {
26+ if ( db . address [ i ] . id === db . authors [ k ] . address ) {
2727 returnAddress = db . address [ i ]
2828 }
2929 }
30- } }
30+ }
31+ }
3132 if ( returnAddress ) return returnAddress
3233 } ,
33- book ( parent , args , context ) {
34+ booksAndAuthors ( ) {
35+ let booksAndAuthorsArray = [ ]
36+ for ( let i = 0 ; i < db . books . length ; i ++ ) {
37+ for ( let j = 0 ; j < db . authors . length ; j ++ ) {
38+ if ( db . books [ i ] . author === db . authors [ j ] . id ) {
39+ booksAndAuthorsArray . push ( { title : db . books [ i ] . title , authorName : db . authors [ j ] . name } )
40+ }
41+ }
42+ }
43+ return booksAndAuthorsArray
44+ } ,
45+ book ( parent , args , context ) {
3446 //console.log(parent, "\n", context)
3547 let result = db . books . find ( ( b ) => {
3648 return b . id === args . id
3749 } )
38-
39- if ( result ) {
50+
51+ if ( result ) {
4052 return result
4153 } else {
4254 throw new GraphQLError ( 'NOT FOUND' , {
0 commit comments