@@ -32,8 +32,9 @@ class Field:
3232 Attributes:
3333 field_type (Field.Type): The type of the field.
3434 name (str): name that the attribute has in client-side Python objects
35- grapgql_name (str): name that the attribute has in queries (and in
35+ graphql_name (str): name that the attribute has in queries (and in
3636 server-side database definition).
37+ result_subquery (str): graphql query result payload for a field.
3738 """
3839
3940 class Type (Enum ):
@@ -54,6 +55,25 @@ def __init__(self, enum_cls: type):
5455 def name (self ):
5556 return self .enum_cls .__name__
5657
58+ class ListType :
59+ """ Represents Field that is a list of some object.
60+ Args:
61+ list_cls (type): Type of object that list is made of.
62+ graphql_type (str): Inner object's graphql type.
63+ By default, the list_cls's name is used as the graphql type.
64+ """
65+
66+ def __init__ (self , list_cls : type , graphql_type = None ):
67+ self .list_cls = list_cls
68+ if graphql_type is None :
69+ self .graphql_type = self .list_cls .__name__
70+ else :
71+ self .graphql_type = graphql_type
72+
73+ @property
74+ def name (self ):
75+ return f"[{ self .graphql_type } ]"
76+
5777 class Order (Enum ):
5878 """ Type of sort ordering. """
5979 Asc = auto ()
@@ -91,10 +111,15 @@ def Enum(enum_cls: type, *args):
91111 def Json (* args ):
92112 return Field (Field .Type .Json , * args )
93113
114+ @staticmethod
115+ def List (list_cls : type , graphql_type = None , ** kwargs ):
116+ return Field (Field .ListType (list_cls , graphql_type ), ** kwargs )
117+
94118 def __init__ (self ,
95- field_type : Union [Type , EnumType ],
119+ field_type : Union [Type , EnumType , ListType ],
96120 name ,
97- graphql_name = None ):
121+ graphql_name = None ,
122+ result_subquery = None ):
98123 """ Field init.
99124 Args:
100125 field_type (Field.Type): The type of the field.
@@ -103,12 +128,14 @@ def __init__(self,
103128 graphql_name (str): query and server-side name of a database object.
104129 If None, it is constructed from the client-side name by converting
105130 snake_case (Python convention) into camelCase (GraphQL convention).
131+ result_subquery (str): graphql query result payload for a field.
106132 """
107133 self .field_type = field_type
108134 self .name = name
109135 if graphql_name is None :
110136 graphql_name = utils .camel_case (name )
111137 self .graphql_name = graphql_name
138+ self .result_subquery = result_subquery
112139
113140 @property
114141 def asc (self ):
0 commit comments