@@ -30,6 +30,8 @@ class QuerySetList(graphene.List):
3030 * ``limit``
3131 * ``offset``
3232 * ``search_query``
33+ * ``search_operator``
34+ * ``search_fields``
3335 * ``order``
3436
3537 :param enable_limit: Enable limit argument.
@@ -38,6 +40,10 @@ class QuerySetList(graphene.List):
3840 :type enable_offset: bool
3941 :param enable_search: Enable search query argument.
4042 :type enable_search: bool
43+ :param enable_search_fields: Enable search fields argument, enable_search must also be True
44+ :type enable_search_fields: bool
45+ :param enable_search_operator: Enable search operator argument, enable_search must also be True
46+ :type enable_search_operator: bool
4147 :param enable_order: Enable ordering via query argument.
4248 :type enable_order: bool
4349 """
@@ -46,6 +52,8 @@ def __init__(self, of_type, *args, **kwargs):
4652 enable_limit = kwargs .pop ("enable_limit" , True )
4753 enable_offset = kwargs .pop ("enable_offset" , True )
4854 enable_search = kwargs .pop ("enable_search" , True )
55+ enable_search_fields = kwargs .pop ("enable_search_fields" , True )
56+ enable_search_operator = kwargs .pop ("enable_search_operator" , True )
4957 enable_order = kwargs .pop ("enable_order" , True )
5058
5159 # Check if the type is a Django model type. Do not perform the
@@ -91,6 +99,22 @@ def __init__(self, of_type, *args, **kwargs):
9199 graphene .String ,
92100 description = _ ("Filter the results using Wagtail's search." ),
93101 )
102+ if enable_search_operator :
103+ kwargs ["search_operator" ] = graphene .Argument (
104+ graphene .Enum ("SearchOperatorEnum" , ["and" , "or" ]),
105+ description = _ (
106+ "Specify search operator (and/or), see: https://docs.wagtail.org/en/stable/topics/search/searching.html#search-operator"
107+ ),
108+ default_value = "and" ,
109+ )
110+
111+ if enable_search_fields :
112+ kwargs ["search_field" ] = graphene .Argument (
113+ graphene .List (graphene .String ),
114+ description = _ (
115+ "A list of fields to search in. see: https://docs.wagtail.org/en/stable/topics/search/searching.html#specifying-the-fields-to-search"
116+ ),
117+ )
94118
95119 if "id" not in kwargs :
96120 kwargs ["id" ] = graphene .Argument (graphene .ID , description = _ ("Filter by ID" ))
@@ -137,21 +161,29 @@ def PaginatedQuerySet(of_type, type_class, **kwargs):
137161 """
138162 Paginated QuerySet type with arguments used by Django's query sets.
139163
140- This type setts the following arguments on itself:
164+ This type sets the following arguments on itself:
141165
142166 * ``id``
143167 * ``page``
144168 * ``per_page``
145169 * ``search_query``
170+ * ``search_operator``
171+ * ``search_fields``
146172 * ``order``
147173
148174 :param enable_search: Enable search query argument.
149175 :type enable_search: bool
176+ :param enable_search_fields: Enable search fields argument, enable_search must also be True
177+ :type enable_search_fields: bool
178+ :param enable_search_operator: Enable search operator argument, enable_search must also be True
179+ :type enable_search_operator: bool
150180 :param enable_order: Enable ordering via query argument.
151181 :type enable_order: bool
152182 """
153183
154184 enable_search = kwargs .pop ("enable_search" , True )
185+ enable_search_fields = kwargs .pop ("enable_search_fields" , True )
186+ enable_search_operator = kwargs .pop ("enable_search_operator" , True )
155187 enable_order = kwargs .pop ("enable_order" , True )
156188 required = kwargs .get ("required" , False )
157189 type_name = type_class if isinstance (type_class , str ) else type_class .__name__
@@ -198,6 +230,22 @@ def PaginatedQuerySet(of_type, type_class, **kwargs):
198230 kwargs ["search_query" ] = graphene .Argument (
199231 graphene .String , description = _ ("Filter the results using Wagtail's search." )
200232 )
233+ if enable_search_operator :
234+ kwargs ["search_operator" ] = graphene .Argument (
235+ graphene .Enum ("SearchOperatorEnum" , ["and" , "or" ]),
236+ description = _ (
237+ "Specify search operator (and/or), see: https://docs.wagtail.org/en/stable/topics/search/searching.html#search-operator"
238+ ),
239+ default_value = "and" ,
240+ )
241+
242+ if enable_search_fields :
243+ kwargs ["search_field" ] = graphene .Argument (
244+ graphene .List (graphene .String ),
245+ description = _ (
246+ "A list of fields to search in. see: https://docs.wagtail.org/en/stable/topics/search/searching.html#specifying-the-fields-to-search"
247+ ),
248+ )
201249
202250 if "id" not in kwargs :
203251 kwargs ["id" ] = graphene .Argument (graphene .ID , description = _ ("Filter by ID" ))
0 commit comments