Skip to content

Commit ef76e4b

Browse files
committed
add new scope class and schema bugs fixed
1 parent 93da6a5 commit ef76e4b

File tree

6 files changed

+83
-7
lines changed

6 files changed

+83
-7
lines changed

cls/GraphQL/REST/Main.cls

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,14 @@ ClassMethod GraphQL()
2020
set sc = $$$OK
2121
#dim %request as %CSP.Request
2222
set query = %request.Content.query
23-
set GiQLHASH = $system.Encryption.MD5Hash(query)
24-
25-
if GiQLHASH = "ú60t—·š}RŒÌë"
23+
set GiQLHASH = $system.Encryption.Base64Encode($system.Encryption.MD5Hash(query))
24+
if GiQLHASH = "ABURmBQ3tap6wGcPz3hLSw=="
2625
{
27-
w ##class(GraphQL.Utils.Schema).GetSchema().%ToJSON()
26+
try{
27+
w ##class(GraphQL.Utils.Schema).GetSchema().%ToJSON()
28+
}catch ex{
29+
set sc = ex.AsStatus()
30+
}
2831
}else{
2932
try{
3033
set parser = ##class(GraphQL.Parser).%New()

cls/GraphQL/Scope/All.cls

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ ClassMethod GetClasses() As %List
1010
{
1111
set classname = rs.Name
1212
continue:$e(classname)="%"
13+
continue:$$$defClassKeyGet(classname,$$$cCLASSgeneratedby)'=""
1314
continue:$$$defClassKeyGet(classname, $$$cCLASSsystem)'=0 // Skip system classes
1415
continue:'$$$comClassDefined(classname) // TODO fix for mapped classes
1516
set list = list _ $lb(classname)
@@ -18,6 +19,7 @@ ClassMethod GetClasses() As %List
1819
}
1920

2021
/// This method should return a list of class fields, available for GraphQL
22+
/// zw ##class(GraphQL.Scope.All).GetProperties()
2123
ClassMethod GetProperties(classname As %Dictionary.CacheClassname) As %List
2224
{
2325
if ($$$classIsPersistent(classname) || $$$classIsSerial(classname))
@@ -26,8 +28,12 @@ ClassMethod GetProperties(classname As %Dictionary.CacheClassname) As %List
2628
set class = ##class(%Dictionary.CompiledClass).%OpenId(classname)
2729
for i=1:1:class.Properties.Count()
2830
{
31+
2932
set property = class.Properties.GetAt(i)
33+
set type = property.Type
3034
if property.Internal || property.Calculated || property.ReadOnly || property.Private || property.Identity continue
35+
continue:'($$$classIsPersistent(type) || $$$classIsSerial(type) || $$$classIsStream(type) || $$$classIsDataType(type))
36+
continue:type="%Library.RegisteredObject"
3137
set list = list _ $lb(property.Name)
3238
}
3339
}else{

cls/GraphQL/Scope/Package.cls

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
Class GraphQL.Scope.Package Extends Abstract
2+
{
3+
4+
Parameter Package = {"DeepSee"};
5+
6+
/// This method should return a list of classes, available for GraphQL
7+
ClassMethod GetClasses() As %List
8+
{
9+
set list = ""
10+
set rs = ..SubclassesListFunc()
11+
while rs.%Next()
12+
{
13+
set classname = rs.Name
14+
continue:$e(classname)="%"
15+
continue:$$$defClassKeyGet(classname,$$$cCLASSgeneratedby)'=""
16+
continue:$$$defClassKeyGet(classname, $$$cCLASSsystem)'=0 // Skip system classes
17+
continue:'$$$comClassDefined(classname) // TODO fix for mapped classes
18+
set list = list _ $lb(classname)
19+
}
20+
quit list
21+
}
22+
23+
/// This method should return a list of class fields, available for GraphQL
24+
ClassMethod GetProperties(classname As %Dictionary.CacheClassname) As %List
25+
{
26+
if ($$$classIsPersistent(classname))
27+
{
28+
set list = ""
29+
set class = ##class(%Dictionary.CompiledClass).%OpenId(classname)
30+
for i=1:1:class.Properties.Count()
31+
{
32+
set property = class.Properties.GetAt(i)
33+
set type = property.Type
34+
if property.Internal || property.Calculated || property.ReadOnly || property.Private || property.Identity continue
35+
continue:'($$$classIsPersistent(type) || $$$classIsSerial(type) || $$$classIsStream(type) || $$$classIsDataType(type))
36+
continue:type="%Library.RegisteredObject"
37+
set list = list _ $lb(property.Name)
38+
}
39+
}else{
40+
quit $$$ERROR($$$GeneralError,"Class: "_classname_" must by %Persystent")
41+
}
42+
quit list
43+
}
44+
45+
Query SubclassesList(Package = {..#Package}) As %SQLQuery
46+
{
47+
SELECT DISTINCT name
48+
FROM %Dictionary.ClassDefinitionQuery_SubclassOf('%Library.Persistent')
49+
where $piece(name,'.',1)= :Package
50+
}
51+
52+
}
53+

cls/GraphQL/Scope/Superclass.cls

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ ClassMethod GetClasses() As %List
1212
{
1313
set classname = rs.Name
1414
continue:$e(classname)="%"
15+
continue:$$$defClassKeyGet(classname,$$$cCLASSgeneratedby)'=""
1516
continue:$$$defClassKeyGet(classname, $$$cCLASSsystem)'=0 // Skip system classes
1617
continue:'$$$comClassDefined(classname) // TODO fix for mapped classes
1718
set list = list _ $lb(classname)
@@ -24,12 +25,17 @@ ClassMethod GetProperties(classname As %Dictionary.CacheClassname) As %List
2425
{
2526
if ($$$classIsPersistent(classname))
2627
{
28+
set list = ""
2729
set class = ##class(%Dictionary.CompiledClass).%OpenId(classname)
2830
for i=1:1:class.Properties.Count()
2931
{
32+
3033
set property = class.Properties.GetAt(i)
34+
set type = property.Type
3135
if property.Internal || property.Calculated || property.ReadOnly || property.Private || property.Identity continue
32-
set list = list _ $lb(property)
36+
continue:'($$$classIsPersistent(type) || $$$classIsSerial(type) || $$$classIsStream(type) || $$$classIsDataType(type))
37+
continue:type="%Library.RegisteredObject"
38+
set list = list _ $lb(property.Name)
3339
}
3440
}else{
3541
quit $$$ERROR($$$GeneralError,"Class: "_classname_" must by %Persystent")

cls/GraphQL/Utils/Schema.cls

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,13 @@ ClassMethod GetArgsOrFields(class As %Dictionary.CompiledClass, flag As %Boolean
6464
do argsOrFields.%Push(..GetIDforFields())
6565
}
6666
}
67+
set propList = $classmethod(##class(GraphQL.Settings).GetSetting("SCOPECLASS"), "GetProperties", class.Name)
6768
for i=1:1:class.Properties.Count()
6869
{
6970
set property = class.Properties.GetAt(i)
7071

7172
if property.Internal || property.Calculated || property.ReadOnly || property.Private || property.Identity continue
73+
continue:$lf(propList,property.Name)=0
7274

7375
if ((flag = $$$Args) && (..GetKind(property.Type) = $$$SCALAR))
7476
{
@@ -224,9 +226,13 @@ ClassMethod GetRootField(classname As %String) As %DynamicObject [ CodeMode = ex
224226
/// zw ##class(GraphQL.Utils.Schema).GetClassRelatedTypes("Sample.Employee")
225227
ClassMethod GetClassRelatedTypes(classname As %Dictionary.CacheClassname) As %List
226228
{
229+
set relatedTypes = ""
230+
set propList = $classmethod(##class(GraphQL.Settings).GetSetting("SCOPECLASS"), "GetProperties", classname)
227231
&sql(SELECT
228232
%DLIST(Distinct Type) INTO :relatedTypes
229-
FROM %Dictionary.CompiledProperty where parent = :classname)
233+
FROM %Dictionary.CompiledProperty
234+
where parent = :classname and name %InList :propList
235+
)
230236
quit relatedTypes
231237
}
232238

mac/ForBebug.MAC

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
ROUTINE ForBebug
22
set parser = ##class(GraphQL.Parser).%New()
3-
set ast = parser.Parse(##class(GraphQL.Source).%New("query { Sample_Person {Name Home {State} Id}} Sample_Employee {id}}"))
3+
#dim ast As GraphQL.AST.ASTNode = parser.Parse(##class(GraphQL.Source).%New("{Sample_Company{id Name}}"))
4+
w ##class(GraphQL.Query.Executor).Execute(ast).%ToJSON()
5+

0 commit comments

Comments
 (0)