Skip to content

Commit 4f809ed

Browse files
committed
[UPG] Changed way of generating arguments
1 parent 8d94a7c commit 4f809ed

File tree

2 files changed

+60
-25
lines changed

2 files changed

+60
-25
lines changed

cls/GraphQL/Query/Executor.cls

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@ Class GraphQL.Query.Executor [ Abstract ]
44
ClassMethod Execute(ast As GraphQL.AST.GraphQLDocument) As %DynamicObject
55
{
66
set queryClass = ..GetQueryClassname(ast)
7-
7+
do ##class(GraphQL.Utils.Arguments).%New().Get(ast, .args)
88
if ##class(%Dictionary.CompiledClass).%ExistsId(queryClass) && $classmethod(queryClass, "IsUpToDate") && 0{
9-
set result = $classmethod(queryClass, "Execute") // TODO args...
9+
set result = $classmethod(queryClass, "Execute", args...)
1010
} else {
1111
set sc = ##class(GraphQL.Query.GenerateClass).Generate(ast)
1212
if $$$ISOK(sc) {
13-
set result = $classmethod(queryClass, "Execute")
13+
set result = $classmethod(queryClass, "Execute", args...)
1414
} else {
1515
set result = {"ERROR": ("Unable to generate query"_$system.Status.DisplayError(sc))}
1616
}

cls/GraphQL/Query/GenerateClass.cls

Lines changed: 57 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@ Property Modifier As %String;
99

1010
Property OrderBy As %String;
1111

12-
Property ModifierFlag As %String;
13-
1412
Property From As %String;
1513

1614
Property Where As %String;
@@ -25,10 +23,18 @@ Property ClassList As list Of %Dictionary.CacheClassname;
2523

2624
Property QueryCount As %Integer [ InitialExpression = 0 ];
2725

26+
Property SubQueryCount As %Integer [ InitialExpression = 0 ];
27+
28+
Property ArgCount As %Integer [ InitialExpression = 0 ];
29+
2830
Property FieldCount As list Of %Integer;
2931

3032
Property IsFirstField As %Boolean [ InitialExpression = {$$$YES} ];
3133

34+
Property IsRelationship As %Boolean [ InitialExpression = {$$$NO} ];
35+
36+
Property IsManyCardinality As %Boolean [ InitialExpression = {$$$NO} ];
37+
3238
Method %OnNew(classname As %Dictionary.CacheClassname) As %Status [ Private, ServerOnly = 1 ]
3339
{
3440
set ..Class = ..GenerateClass(classname)
@@ -56,6 +62,13 @@ Method GenerateQueryCode()
5662
#dim method As %Dictionary.MethodDefinition
5763
set method = ..Class.Methods.GetAt(1)
5864

65+
set argList = ""
66+
for i=1:1:..ArgCount
67+
{
68+
set argList = argList_$lb("arg"_i)
69+
}
70+
set method.FormalSpec = $lts(argList)
71+
5972
#dim code As %Stream.TmpCharacter
6073
set code = method.Implementation
6174
do code.WriteLine($$$TAB _ "set query" _ ..QueryCount _" = []" _ $c(10))
@@ -197,7 +210,7 @@ Method EndObject(classname As %Dictionary.ClassDefinition)
197210
set ..IsFirstField = $$$NO
198211
}
199212

200-
Method AppendField(name As %String, classname As %Dictionary.ClassDefinition, path As %String = "")
213+
Method AppendField(name As %String, classname As %Dictionary.ClassDefinition, path As %String = "", propName As %String = "")
201214
{
202215
set fieldCount = ..FieldCount.GetAt(..QueryCount) + 1
203216
if ..IsFirstField {
@@ -206,27 +219,26 @@ Method AppendField(name As %String, classname As %Dictionary.ClassDefinition, pa
206219
set ..Row = ..Row _ ", "
207220
}
208221

209-
if fieldCount>1 {
222+
if (fieldCount>1){
210223
set ..Select = ..Select _ ", "
211224
}
212225
set collection = $$$comMemberKeyGet(classname,$$$cCLASSproperty,name,$$$cPROPcollection)
213226
set type = $$$comMemberKeyGet(classname,$$$cCLASSproperty,name,$$$cPROPtype)
214227

215228
set field = "f" _ fieldCount
229+
set select = ""
230+
set select = path _ $select(path'="":$select($$$classIsSerial(classname):"_",$$$classIsPersistent(classname):"->",$$$classIsDataType(classname):"_") ,1:"") _ name
216231

217232
if collection="" {
218233
set ..Row = ..Row _ """" _ name _ """:(" _ field _ ")"
219-
} else {
234+
}else {
220235
/// TODO arrays
221236
/// TODO lists of dates
222237
set ..Row = ..Row _ """" _ name _ """:(##class(GraphQL.Utils.SQL).ListToArray(" _ field _ "))"
223-
set name = "%INTERNAL(" _ name _ ")"
238+
set select = "%INTERNAL(" _ select _ ")"
224239
}
225-
226-
if (path '= "") {
227-
set objType = $$$comMemberKeyGet(classname,$$$cCLASSproperty,path,$$$cPROPtype)
228-
}
229-
set ..Select = ..Select _ path _ $select(path'="":$select($$$classIsSerial(objType):"_",$$$classIsPersistent(objType):"->") ,1:"") _ name
240+
241+
set ..Select = ..Select _ select
230242

231243
do ..FieldCount.SetAt(fieldCount, ..QueryCount)
232244
}
@@ -239,6 +251,7 @@ Method Selections(selections As %ListOfObjectsWithClassName, classname = "", pat
239251
{
240252
set selection = selections.GetAt(i)
241253
set arguments = selection.Arguments
254+
242255
if (selection.SelectionSet '= "")
243256
{
244257
if (classname = "")
@@ -253,17 +266,24 @@ Method Selections(selections As %ListOfObjectsWithClassName, classname = "", pat
253266
} else {
254267
// object fields
255268
set propertyName = selection.Name.Value
269+
270+
set ..IsRelationship = $$$comMemberKeyGet(classname,$$$cCLASSproperty,propertyName,$$$cPROPrelationship)
271+
set cardinality = $$$comMemberKeyGet(classname,$$$cCLASSproperty, propertyName, $$$cPROPcardinality)
272+
set ..IsManyCardinality = $s((cardinality = "many") || (cardinality = "children"): 1, 1: 0)
273+
256274
set propertyType = $$$comMemberKeyGet(classname,$$$cCLASSproperty,propertyName,$$$cPROPtype)
257275
do ..StartObject(propertyName)
258276
set:'arguments.%IsNull() sc = ..Arguments(arguments)
259-
set sc = ..SelectionSet(selection.SelectionSet, classname, path _ $select(path'="":"_" ,1:"") _ propertyName)
277+
set sc = ..SelectionSet(selection.SelectionSet, propertyType, path _ $select(path'="":$select($$$classIsSerial(classname):"_",$$$classIsPersistent(classname):"->",$$$classIsDataType(classname):"_") ,1:"") _ propertyName)
260278
do ..EndObject()
261279
}
262280
}
263281
elseif ((selection.SelectionSet = "") && (classname '= ""))
264282
{
265-
// datatype fields
283+
//// datatype fields
266284
do ..AppendField(selection.Name.Value, classname, path)
285+
set ..IsRelationship = $$$NO
286+
set ..IsManyCardinality = $$$NO
267287
}
268288
}
269289
quit sc
@@ -276,22 +296,23 @@ Method Arguments(arguments As GraphQL.AST.GraphQLArgument) As %Status
276296

277297
for i=1:1:arguments.Size
278298
{
299+
set ..ArgCount = ..ArgCount + 1
279300
set argument = arguments.GetAt(i)
280301
set name = argument.Name.Value
281-
set value = argument.Value.Value
302+
set value = ":arg"_..ArgCount
282303

283-
set ..ModifierFlag = $LF(modifier, name)
304+
set modifierFlag = $LF(modifier, name)
284305

285-
if ..ModifierFlag '= 0
306+
if modifierFlag '= 0
286307
{
287-
if ((..ModifierFlag = 1) || (..ModifierFlag = 2)) {set ..Modifier = ..Modifier _" TOP " _ value}
288-
set:..ModifierFlag=2 ..OrderBy = ..OrderBy _ "%ID DESC"
289-
set:..ModifierFlag=3 ..Where = ..Where _ " %ID > '" _ value _ "' AND "
290-
set:..ModifierFlag=4 ..Where = ..Where _ " %ID < '" _ value _ "' AND "
308+
if ((modifierFlag = 1) || (modifierFlag = 2)) {set ..Modifier = ..Modifier _" TOP " _ value}
309+
set:modifierFlag=2 ..OrderBy = ..OrderBy _ "%ID DESC"
310+
set:modifierFlag=3 ..Where = ..Where _ " %ID > " _ value _ " AND "
311+
set:modifierFlag=4 ..Where = ..Where _ " %ID < " _ value _ " AND "
291312
continue
292313
}
293314

294-
set ..Where = ..Where _ name _ "= '" _ value _ "' AND "
315+
set ..Where = ..Where _ name _ "= " _ value _ " AND "
295316
}
296317
set ..Where = $Extract(..Where, 1, * - 4)
297318

@@ -303,4 +324,18 @@ Method Alias(alias As GraphQL.AST.GraphQLFieldSelection) As %Status
303324
quit $$$OK
304325
}
305326

306-
}
327+
ClassMethod GetPosition(class As %Dictionary.CacheClassname, property As %Dictionary.CacheIdentifier) As %Integer
328+
{
329+
set strategy = $$$comClassKeyGet(class, $$$cCLASSstoragestrategy)
330+
set strategyId = class _ "||" _ strategy
331+
&sql(SELECT Name INTO :position
332+
FROM %Dictionary.StorageDataValueDefinition
333+
WHERE parent = (SELECT ID
334+
FROM %Dictionary.StorageDataDefinition
335+
WHERE parent = :strategyId AND Structure = 'listnode')
336+
AND Value = :property)
337+
quit position
338+
}
339+
340+
}
341+

0 commit comments

Comments
 (0)