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

Array type attributes #162

Closed wunderbarr closed 4 years ago

wunderbarr commented 4 years ago

Enable to have Arrays of all scalar types, Int, String, Float, Boolean, Date(Time) as an attribute. Reuse work done by Veronica Suaste on foreign key arrays. Luckily, to make this work, we only need to handle how these attributes are stored in the respective supported storages (RDBMS and Cassandra). Create, update, and delete thus becomes trivial. There will be no support to update parts of an array, only as a whole. Additionally extend our search API to handle in and notIn for array attributes.

// Example Person { name: Chris rand: [1,2,3,66] }

// Example "in" operator search { person( search: {operator: in, field: rand, value: 2} ) { name rand }

// NOTES: The above supports subset and not subset queries by combining 1 in AND 2 in -> [1,2] subset of 1 notIn AND 2 notIn -> [1,2] not subset of

// Example of a subset query { person( search: {operator: and, search: [{operator: in, field: rand, value: 1}, {operator: in, field: rand, value: 2}]} ) { name rand }

// Future Witch: Any and All operators additionally to the AND, OR operators check whether the logical child expression is true on any or all elements of an array:

{ person( search: {operator: any, search: [{operator: gt, value: 3, field: "element"}]} ) { name rand }

// Note that the above 'field: "element"' could be left out

Open question still: How to handle eq and ne operators for Array types?

// Example { person( search: {operator: eq, field: rand, value: '[1,2,3,66]', valueType: Array} ) { name rand }

Probably no extension of valueType Array to

ArrayOfInt

ArrayOfFloat

ArrayOfString etc is needed. This is because the data model layer, depending on the respective storage technology, needs or does not need to do specific conversions, anyway.

Operators: Any, All At least for two logical expressions, they can be implemented as or (any), and (all) operators. Example: Arr Data-Model { arrStr: [String] } Query: {Arr( search: {operator: and, search: [{operator: gt, field: arrStr, value: '1'}, {operator: lt, field: arrStr, value: '5'}]) } -> [/ array of Arr records /].every( x => x.arrStr.any(i => i > 1 && i < 5) ) 'every' equals 'any' Hypothesis: Any and All can be translated to And and Or expressions. Answer: Not really, because any and all expect a single logical expression to be evaluated on all or any members of the array, respectively. This expression of course can be composite and use and or or in turn...

To given an example of a working any and or operator: // Assume above Data Model Arr Query: {Arr( search: { operator: any, search: [ {operator: gt, field: arrStr, value: '6'} ] } ) { id arrStr } } {arrStr:[1,2,3]} {arrStr:[5,6,7]} {arrStr:[8,9,10]} this query would find the last two records. The above would not work in the following example: {Arr( search: { operator: any, search: [ {operator: gt, field: arrStr, value: '2'}, {operator: lt, field: arrStr, value: '5'} ] } ) { id arrStr } } // Should cause the following error: 'Any' and 'All' operators only accept a single logical expression in the 'search' array of child expressions.