How do you define an upsert (if exists update else insert) using GraphQL?
15:34 15 Dec 2020

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.

I can do this a few ways in conventional SQL dialects and in ElasticSearch (update by query). But I do not see how it is supposed to be specified or described within graphql - or if it is even possible.

In the spec and on the web there are some examples for adding records that seem to require things that look like they are "extra" or "nice to have" (like schema/type definitions) to be included in the document. The update examples often have field, argument, and variable names that do not match (like Author.Id and authorId), or are written using a non-GraphQL specific language like Javascript (same example page as "Author".) Doing this two stage operation from the end client does not seem like the correct approach either as only the target data store is going to know which is the correct operation to take.

There will not be a fixed predefined centralized schema for what I'm working on as it is a multi-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.

Is any what I'm asking about for even possible? If so can an example be shared?

graphql upsert