Zendro-dev / graphql-server-model-codegen

Command line utility to auto-generate the structure files for a graphql server
MIT License
1 stars 2 forks source link

Integrity of Cenzontle associations #76

Open vsuaste opened 4 years ago

vsuaste commented 4 years ago

UPDATE: See the comment below from @asishallab which deprecates the following job-description:

DEPRECATED job-description The migration files need to create FOREIGN KEY( <foreign_key_as_defined_in_associations.json>) constraints. Use the ON DELETE SET NULL option. Also add an INDEX on the foreign key to enable efficient searching.

asishallab commented 4 years ago

Consider the following problems and their solutions presented in this document.

Basically in the context of the above examples and identified problems:

  1. We need to check the existence of provided ID values in some cases.
  2. In case of "to-one" associations where the "targetKey" is found in the associated data model, we need to verify the uniqueness of provided "toAdd" arguments. Otherwise in our classical Dog has one Owner example, where additionally the reverse association is not declared as "to-many", but as "to-one" an Owner can have many dogs, except we verify that the targetKey ("ownerId") is unique in all persistent dog records.

Both above sub-issues should be implemented in the data model layer within the "create" and "update" functions that receive the respective "toAdd" and "toRemove" arguments. Consider writing a helper function, if that appears to maintain the code-base simpler and more concise.

asishallab commented 4 years ago

Comment on inverse to-one associations

An inverse to-one association is called inverse, if and only if the targetKey is in the associated model. The association technically is a to-many, to enforce the uniqueness a respective constraint, if supported by the underlying storage, or a respective validation has to be implemented. In the latter validation case potential performance issues may arise, e.g. in case a very large Cassandra database has to check for uniqueness of the targetKey.

Hence, the decision of how to implement this has to be the programmer's (user's). The code-generator should just print a warning to the console in case an inverse to-one association is defined in the respective model,json file. The warning should say:

Creating an INVERSE to-one association. You have to manually implement a UNIQUE CONSTRAINT, if supported by the storage, or use a respective UNIQUE validation of attribute XYZ in model ZXY