title: Efficient GraphQL query on a join table
body: <p>I'll set this up.</p>
  
  <ul>
  <li><strong>Backend</strong>: Node, GraphQL, Sequelize with a PostGRES DB.</li>
  <li><strong>Frontend</strong>: React, GraphQL.</li>
  <li>I have models of a user, event and member.</li>
  <li>A user can belong to many different events.</li>
  <li>An event can have many users.</li>
  <li>A user will have a specific role for each event.</li>
  <li><p>I'm dynamically creating a member join table via Sequelize, like this:</p>
  
  <pre><code>`Event.belongsToMany(models.User, {
     through: models.Member,
     foreignKey: {
       name: "eventId",
       field: "event_id"
     }
  });`
  
  
  `User.belongsToMany(models.Event, {
      through: models.Member,
      foreignKey: {
         name: "email",
         field: "email"
      }
  });`
  </code></pre></li>
  </ul>
  
  <p>My member model code <strong>does</strong> have one unique field, <code>role</code>. That file looks like this:</p>
  
  <pre><code>`export default (sequelize, DataTypes) =&gt; {
    const Member = sequelize.define("member", {
      role: DataTypes.STRING
    });
    return Member;
  };`
  </code></pre>
  
  <p>In the end, I have a member table with a <strong>role</strong> field, and also fields tied to user (<strong>email</strong>) as well as event (<strong>eventId</strong>).</p>
  
  <hr>
  
  <p><strong>My two questions</strong></p>
  
  <ol>
  <li><strong>Front-end:</strong> I'm able to query the member table (allMembers), and map through each row's role, email and eventId. <em>But how can I display the event <strong>name</strong>?</em> (yes, it's part of my event model). For display purposes, the eventId is obviously meaningless to the end user.</li>
  <li><strong>Front-end:</strong> Once a user sees their list of events they belong to, I'd like for them to be able to click on an event — placing that event's id into state. That way, I can use that eventId for other queries. <em>Any suggestions on the best approach to achieve this?</em></li>
  </ol>