You can add sorting criteria to your query by calling the
The following sort directions are valid:
Sorting by related model fields
You can sort by any of the related model's fields.
One-to-many and many-to-many relationships
You can also sort by aggregate values of the related model's fields. For example, using count
or the 'avg', 'sum', 'min' or 'max' of a field:
If you're writing a resolver, it's feasible to just transform whatever arguments you expose for the field into an object that can then be passed to the
orderBy method. For example:
However, you may want to support all of the functionality shown above. In this case, you can just use the
@orderBy directive to create the appropriate
orderBy argument on your field for you.
If you use the
resolveInfo method, you don't have to call the
orderBy method at all. Sqlmancer will look for an argument named
orderBy and modify your query builder appropriately.
If the type of your field is not the model you want to use to generate the
orderBy argument, you can specify the model to be used.
You can also use the
@many directive instead of applying the
@offset directives separately.