title: Is there a way to write a type for unknown keys in GraphQL?
body: <p>I'm fairly new to GraphQL. Previously I've used Firebase, and when I started learning, I've realised that there's no support for arrays. I couldn't understand why, but after reading <a href="https://firebase.googleblog.com/2014/04/best-practices-arrays-in-firebase.html" rel="nofollow noreferrer">this explanation of it</a>, and started to think in that way, and to use it in practice, everything became easier and faster.</p>
  
  <p>Check the numbers. Numbers of speed, and characters of code of each approach:</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>const obj = {
   id: {
     data: "foo"
    }
  };
  const arr = [{
   id: "id",
    data: "foo"
  }];
  const required = "id";
  
  console.time("Get data by key from object");
  (() =&gt; obj[required])();
  console.timeEnd("Get data by key from object");
  
  console.time("Get data by finding key's value from array");
  (() =&gt; arr.find(({ id }) =&gt; id === required))();
  console.timeEnd("Get data by finding key's value from array");
  
  
  console.time("Set data of object by key from object");
  (() =&gt; obj[required].data = "bar")();
  console.timeEnd("Set data of object by key from object");
  
  console.time("Set data of object by finding key's value from array");
  (() =&gt; arr.find(({ id }) =&gt; id === required).data = "bar")();
  console.timeEnd("Set data of object by finding key's value from array");</code></pre>
  </div>
  </div>
  </p>
  
  <p>Long story short, I'm learning GraphQL, and I haven't found a method which can be used with this approach.</p>
  
  <p>For example in this data structure:</p>
  
  <pre><code>users: {
    "firstUser": {
      name: "first user's name"
    },
    "secondUser": {
      name: "second user's name"
    }
  }
  </code></pre>
  
  <p>I'd need something like:</p>
  
  <pre><code>union Ids = String | [String!]
  
  type User {
      name: String
  }
  
  type Query {
    users(id: Ids): {
    # the [id] would mean that it's returning unknown, even multiple fields
      [id]: User
    }
  }
  
  # querying like
  
  query Users (id: ["firstUser", "secondUser"]) {
      name
  }
  </code></pre>
  
  <p>So basically what I want to pass an array of ids, and the query would return exactly the same data structure as shown in the second snippet.</p>
  
  <p>I'm very new to GraphQL, so every tip would be useful if I've made something wrong, or anything.</p>