title: GraphQL loop through array and get all results
body: <p>I'm new to GraphQL. I'm using API's from Amazon and Itunes to get the title (and other information) of a book. I'm returning an object like this:</p>
  
  <pre><code>var data = [];
  data.title = results[0].title;
  data.author = results[0].author;
  return data;
  </code></pre>
  
  <p>I can make calls to the Amazon and Itunes API and return the available data of a book. However I would like to be able to insert an array of EAN/ISBN, and return data from Amazon and Itunes for all the books.</p>
  
  <p>So the query would become something like this:</p>
  
  <pre><code>{
    book(id:["9789025451608", "8974832789431","9789024576791"]){
      amazon{
        title
      },
      itunes{
        title
      }
    }
  }
  </code></pre>
  
  <p>And the response:</p>
  
  <pre><code>{
    "data": {
      "book": {
        "book1":{
             "amazon": {
                  "title": "De Moord op Commendatore"
              },
             "itunes": {
                  "title": "Niet beschikbaar" // not available
             }
         },
         "book2":{
             "amazon": {
                  "title": "Origin"
              },
             "itunes": {
                  "title": "Origin" 
             }
         }
      }
    }
  }
  </code></pre>
  
  <p>I've searched for examples of the use of graphQLList, but I'm unsure where to use a graphQLList and how to loop through the BookTypes.</p>
  
  <p>Maybe someone can help me or give me an example.</p>
  
  <p><strong>My query looks like this</strong></p>
  
  <pre><code>{
    book(id:["9789025451608"]){
      amazon{
        title
      },
      itunes{
        title
      }
    }
  }
  </code></pre>
  
  <p><strong>and returns:</strong></p>
  
  <pre><code>{
    "data": {
      "book": {
        "amazon": {
          "title": "De Moord op Commendatore"
        },
        "itunes": {
          "title": "Niet beschikbaar" // not available
        }
      }
    }
  }
  </code></pre>
  
  <p><strong>Schema.js</strong></p>
  
  <pre><code>"use strict";
  const graphql = require('graphql');
  const axios = require('axios');
  const {
    GraphQLObjectType,
    GraphQLString,
    GraphQLInt,
    GraphQLSchema,
    GraphQLList
  } = graphql;
  
  // root queries
  const RootQuery = require('./types/query');
  
  module.exports = new GraphQLSchema({
    query: RootQuery
  });
  </code></pre>
  
  <p><strong>RootQuery:</strong></p>
  
  <pre><code>const graphql = require('graphql');
  const axios = require('axios');
  
  const {
    GraphQLObjectType,
    GraphQLString,
    GraphQLList,
    GraphQLInt
  } = graphql;
  
  const BookType = require('../types/book');
  
  const RootQuery = new GraphQLObjectType({
    name:'RootQuery',
    fields: () =&gt; ( {
      book: {
        type: BookType,
        args:{ id : { type: GraphQLString } },
        resolve (parentValue, args) {
         return resp = { id: args.id }
       }
      }
    })
  });
  
  module.exports = RootQuery;
  </code></pre>
  
  <p><strong>Booktype</strong></p>
  
  <pre><code>const graphql = require('graphql');
  const axios = require('axios');
  const {
    GraphQLObjectType,
    GraphQLString,
    GraphQLInt
  } = graphql;
  
  // Itunes
  const itunes = require('../connections/itunes');
  const ItunesType = require('./itunes');
  
  // Amazon
  const amazon = require('../connections/amazon');
  const AmazonType = require('./amazon');
  
  
  const BookType = new GraphQLObjectType({
    name:'book',
    fields: () =&gt; ( {
      id: {
        type: GraphQLString,
      },
      itunes: {
        type: ItunesType,
        resolve(parentValue,args){
          console.log(parentValue);
          data = itunes.getMetadataItunes(parentValue.id);
          return data;
        }
      },
      amazon: {
        type: AmazonType,
        resolve(parentValue, args) {
          console.log(parentValue);
          data = amazon.getMetadataAmazon(parentValue.id);
          return data;
        }
      }
    })
  });
  
  module.exports = BookType;
  </code></pre>
  
  <p><strong>AmazonType</strong></p>
  
  <pre><code>const graphql = require('graphql');
  
  const{
    GraphQLObjectType,
    GraphQLString,
    GraphQLList
  } = graphql;
  
  
  const AmazonType = new GraphQLObjectType({
      name: 'amazon',
      fields: () =&gt; ( {
          title: { type: GraphQLString },
      })
  });
  
  module.exports = AmazonType;
  </code></pre>
  
  <p>Same kind of code goes for ItunesType.</p>