title: GraphQL data modelling - extended types (Prisma)
body: <p>In my Prisma Data Model I started out with a basic User type like this:</p>
  
  <pre><code>type User {
    name: String!
    email: String! @unique
    password: String!
  }
  </code></pre>
  
  <p>Now a User can have two roles: either as a candidate or as a user associated with an employer. If a candidate, the user should also have a set of applications and a set of qualifications, if associated with an employer it should have an access level and a reference to the employer.</p>
  
  <p>First off, is there any way to extend basic types in GraphQL data modelling? If so, how would I go about doing it?</p>
  
  <p>If there is not, I can see three different methods used, and I'm curious what are the pros and cons of each approach:</p>
  
  <ol>
  <li>Having two separate types <code>CandidateUser</code> and <code>EmployerUser</code>, each with the fields <code>name</code>, <code>email</code>, <code>password</code>. I see two problems with this approach: The <code>@unique</code> tag on <code>email</code> is not reliable, and I would have to write a custom verification to make sure the field is unique across both types; and having a single login-function that takes email and fetches the users corresponding data is no longer trivial: it needs to do a lookup in both tables. </li>
  </ol>
  
  <p>Like this:</p>
  
  <pre><code>    type CandidateUser {
        name: String!
        email: String! @unique
        password: String!
        applications: [Application!]!
        qualifications: [Qualification!]!
      }
      type EmployerUser{
        name: String!
        email: String! @unique
        password: String!
        employer: Employer!
        accessRight: AccessRight!
      }
  </code></pre>
  
  <ol start="2">
  <li><p>Again two separate types, but with a <code>RootUser</code> containing <code>name</code>, <code>email</code> and <code>password</code>, and with <code>CandidateUser</code> and <code>EmployerUser</code> each having a one-to-one reference to a <code>RootUser</code>. This would enforce the <code>@unique</code> tag on the email field, but lookup would still be nontrivial.</p>
  
  <pre><code>type RootUser{
    name: String!
    email: String! @unique
    password: String!
  }
  type CandidateUser {
    rootUser: RootUser!
    applications: [Application!]!
    qualifications: [Qualification!]!
  }
  type EmployerUser{
    rootUser: RootUser!
    employer: Employer!
    accessRight: AccessRight!
  }
  </code></pre></li>
  <li><p>Extending <code>User</code> to have the fields within EmployerUser and CandidateUser as optional parameters. This is a pretty simple approach, but I would need custom handling to enforce requiring fields (as in, I can not mark for instance employer as required as that field would not exist for a Candidate). </p>
  
  <pre><code>type User{
    name: String!
    email: String! @unique
    password: String!
    applications: [Application!]!
    qualifications: [Qualification!]!
    employer: Employer
    accessRight: AccessRight
  }
  </code></pre></li>
  </ol>
  
  <p>I really want to ask if there is a better way of solving this. I'm still pretty new to GraphQL and not the best data modeler to begin with, but I'd greatly appraciate any nudge in the right direction :)</p>
  
  <p>And if I do not have any other choice but the three I listed, which one would make the most sense?</p>