title: How do you define an upsert (if exists update else insert) or even an update using graphql?
body: <p>EDIT: I'm going to give the SQL equivalents here because its the easiest way I can convey what I'm trying to find an equivalent to.</p>
  <p>The schema for a <code>person</code> is</p>
  <pre><code> id (system assigned clustered PK, probably a guid, doesnt really matter for this)
   FirstName : string
   LastName : string, required
   EmployeeCode : string, required, Unique
  </code></pre>
  <p>I want to be able to represent a query like this in GraphQL (BEGIN/END ommitted for brevity), and just the UPDATE statement and I need examples for either that shows how to target specific records like the WHERE clause does.</p>
  <pre><code>IF EXISTS(SELECT TOP 1 1 FROM person WITH (UPDLOCK) WHERE EmployeeCode = 'ABC123')
     UPDATE person 
        SET FirstName = 'Mike'
            , LastName = 'Jones' 
     WHERE EmployeeCode = 'ABC123
  ELSE
     INSERT person (FirstName, LastName, EmployeeCode) 
        VALUES ('Mike', &quot;Hones', 'ABC123')
  </code></pre>
  <p>The <a href="http://spec.graphql.org/June2018/#sec-Mutation" rel="nofollow noreferrer">GraphQl spec</a> discusses mutations but not what it looks like. The <a href="https://graphql.org/learn/queries/#mutations" rel="nofollow noreferrer">examples</a> only cover the INSERT scenario. The only mention about updates is that they will/must/? be executed consecutively.</p>
  <p>Original question -</p>
  <p>I want to be able to send a single graphql document to add a record if none exist for the criteria specified, or update (partial or all non ident/non PK/non NK fields) an existing one if the criteria specified match an existing record.</p>
  <p>I can do this a few ways in conventional SQL dialects and in ElasticSearch (update by query). But I dont see how its supposed to be specified or described within graphql - or if its even possible.</p>
  <p>In the spec and on the web there are some examples for adding records that seem to require things that look like they are <a href="https://stackoverflow.com/a/51524027/16391">&quot;extra&quot; or &quot;nice to have&quot;</a> (like schema/type definitions) to be included in the document. The update examples often have field, argument, and variable names that dont match (<a href="https://medium.com/workflowgen/graphql-mutations-partial-updates-implementation-bff586bda989" rel="nofollow noreferrer">like Author.Id and authorId</a>), or are written using a non-graphql specific language like Javascript (same example page as &quot;Author&quot;.) Doing this two stage operation from the end client doesnt seem like the correct approach either as only the target data store is going to know which is the correct operation to take.</p>
  <p>There will not be a fixed predefined centralized schema for what I'm working on as its a muilti-tenant API and each tenant may have different definitions for a type (for example Tenant A has a Contract entity with 16 fields, but Tenant B has a type of the same name and intended function with 20 field. Both would share the same storage space for Contracts.</p>
  <p>Is any what I'm asking about for even possible? If so can an example be shared?</p>