title: How to return an array of objects in GraphQL, possibly using the same endpoint as the one that returns a single object?
body: <p>I am making a GraphQL API where I would be able to retrieve a car object by its id or retrieve all the cars when no parameter is provided. </p>
  
  <p>Using the code below, I am successfully able to retrieve a single car object by supplying id as a parameter.</p>
  
  <p><strong>However, in the case where I would expect an array of objects i.e. when I supply no parameter at all, I get no result on GraphiQL.</strong></p>
  
  <p>schema.js</p>
  
  <pre><code>let cars = [
    { name: "Honda", id: "1" },
    { name: "Toyota", id: "2" },
    { name: "BMW", id: "3" }
  ];
  
  const CarType = new GraphQLObjectType({
    name: "Car",
    fields: () =&gt; ({
      id: { type: GraphQLString },
      name: { type: GraphQLString }
    })
  });
  
  const RootQuery = new GraphQLObjectType({
    name: "RootQueryType",
    fields: {
      cars: {
        type: CarType,
        args: {
          id: { type: GraphQLString }
        },
        resolve(parent, args) {
          if (args.id) {
            console.log(cars.find(car =&gt; car.id == args.id));
            return cars.find(car =&gt; car.id == args.id);
          }
          console.log(cars);
          //***Problem Here***
          return cars;
        }
      }
    }
  });
  </code></pre>
  
  <p>Test queries and their respective results:</p>
  
  <p>Query 1</p>
  
  <pre><code>{
    cars(id:"1"){
      name
    }
  }
  </code></pre>
  
  <p>Query 1 Response (Success) </p>
  
  <pre><code>{
    "data": {
      "cars": {
        "name": "Honda"
      }
    }
  }
  </code></pre>
  
  <p>Query 2 </p>
  
  <pre><code>{
    cars{
      name
    }
  }
  </code></pre>
  
  <p>Query 2 Response (Fail)</p>
  
  <pre><code>{
    "data": {
      "cars": {
        "name": null
      }
    }
  }
  </code></pre>
  
  <p>Any help would be much appreciated. </p>