title: How to include mutation request metadata in GraphQL?
body: <p>I'm building a GraphQL server from scratch with an API backend, replacing a REST API server. Currently some requests in the existing API server, mainly Create / Update requests that will be mutations in GraphQL, include a request id which is used by the client. This request id is metadata about the request itself not part of the domain resource. </p>
  
  <p>My question is how to model / include request metadata in GraphQL queries and mutations? My only solution so far is to make a request Type, which other types could include as a field so the request data can be included in the mutation return type. However i do not like this approach as it mixes request data into my domain types and this very much feels against the ethos of GraphQL. Is there an accepted way to pass 'arbitrary' e.g. non-domain type data in the response of a query or mutation in GraphQL?</p>
  
  <p>Example - what i would like to avoid:</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>type UserType {
    id: ID
    name: String
    request: RequestType // mixing request data in with domain type of User
  }
  
  type RequestType {
    id: ID
  }</code></pre>
  </div>
  </div>
  </p>
  
  <h1>Update</h1>
  
  <p>For others interested in this problem, based on the responses here I have decided that the GraphQL <code>extensions</code> key is good option for adding arbitrary data to a GraphQL response without the data becoming part of your data Graph. In Express-GraphQL, docs on adding an extensions key to responses can be found here: <a href="https://github.com/graphql/express-graphql#providing-extensions" rel="nofollow noreferrer">https://github.com/graphql/express-graphql#providing-extensions</a>. A good overview of extensions here: <a href="https://marmelab.com/blog/2017/09/06/dive-into-graphql-part-iii-building-a-graphql-server-with-nodejs.html#server-logging" rel="nofollow noreferrer">https://marmelab.com/blog/2017/09/06/dive-into-graphql-part-iii-building-a-graphql-server-with-nodejs.html#server-logging</a></p>
  
  <p>That said, if the request metadata is conceptually part of the domain data then following Kashif's suggestion below of creating ResponseTypes that embed domain Types might be the correct approach.</p>