-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement generic models and generic association support #120
Comments
Summary and update taken from Slack communication Distinguish between generic models and generic associations. A generic model has standard resolvers and a "standard" data model layer, except all data model layer functions throw a 'not implemented error'. Methodology: |
In all read resolvers, i.e. root and field (associations), Cenzontle by default generates security and efficiency checks. These are:
See the template for e.g. "standard" SQL data models for details on Cenzontle's default behaviour. In the case of write operations, especially on associations adhere to our specification. Make sure the respective create and update root mutations still perform the security and efficiency checks as defined in the spec before invoking implementations in the data model. |
Consider the following example from our specification: // root mutation (resolver)
// e.g.
addPerson( input, context ) {
let inputSanitized = sanitizeAssociationArguments( input, /* assocArgNames */ )
// Security check
checkAuthorization(...) // standard create permission on "Person" model as before
checkAuthorizationOnAssocArgs( inputSanitized, context, associationArgsDef )
// check if association args don't exceed record limit
checkAndAdjustRecordLimitForCreateUpdate( inputSanitized, context, associationArgsDef )
// check if association args actually point to existing IDs
// MAKE SURE THAT IN CASE OF A REMOTE DATA MODEL (DDM, cenzontle-web-server, generic web-service)
// that the association related args in input are ignored or removed, i.e. not processed.
// MAKE SURE THE
validateAssociationArgsExistence( inputSanitized, context,
// HANDLE PERSON ATTRIBUTES
// models.Person.addOne uses named function arguments, to
// only receive Person scalar attributes
let theNewBaby = models.Person.addOne( sanitizedInput )
// In Case of the DDM the above line passes the input the a responsible adapter!
// HANDLE ASSOCIATIONS
theNewBaby.handleAssociations()
} Note that because we do not expect generic associations to use foreign keys, maybe the above |
A note on generic associations in distributed data modelsProblemAssociations of distributed data models (DDMs) can be distributed as well. In that case the security and efficiency checks are more elaborated, because responsible adapters have to be found for the associated records' identifiers (see ConclusionThus generic associations cannot be distributed in the way Cenzontle handles standard
SolutionNow, that this has been understood, we can define how generic associations should be implemented for DDMs. Basically, they stay exactly the same as in any other model. The only noteworthy detail here is, that no code will be generated in the adapters. Generic associations will be handled directly in the DDM model module itself. |
Fix error handlingAdapt error handling as in issue #123 In detail this means that the data model layer functions should receive a new argument Root readers and writersFunctions in the data model layer affected by this are all root-reader and root-writer functions:
Because our default Special association casesAll generic associations invoke "Impl-Functions" in the respective data model modules. This goes for reading and writing generic associations. In these cases the resolver needs to initialize a
Use a single template for resolversGeneric data models and generic associations do not require a separate template for the generated resolvers. Merge into a single template |
We want the user / programmer be able to write their own code to resolve data models and their associations. The specification is to treat generic models and generic associations separately. The resolvers and schema should largely remain unchanged, i.e. the default case generated by Cenzontle. The respective resolver functions should invoke so called "Impl" functions in the data models.
For further details on the spec see our markdown specification.
Also see the summary shared in our Slack channel written to give more details on the above (older) specification. See screenshot below.
The text was updated successfully, but these errors were encountered: