ynput / ayon-python-api

Apache License 2.0
8 stars 3 forks source link

Add support to filter queries by nested fields #137

Closed fabiaserra closed 4 months ago

fabiaserra commented 4 months ago

Doing any queries in the API that filter by a field that contains nested attributes result in the following error:

> ayon_api.get_project(project_name, fields=["code", "taskTypes"])?
ayon_api.exceptions.GraphQlQueryFAILED: GraphQl query FAILED: Field 'taskTypes' of type '[ TaskType! ]!' must have a selection of subfields. Did you mean 'taskTypes { ... }'? (Line 4 Column 5)

This is a core functionality that should be easy to use to speed up queries. However, if you are going to implement it by querying everything and then filtering out don't even bother, the point should be to make queries faster or improve I/O because of using less memory, and if that's not the case, just document in the API that there's no point in specifying fields on the args, I would even argue that fields shouldn't even be exposed in that case.

BigRoy commented 4 months ago

Doing any queries in the API that filter by a field that contains nested attributes result in the following error:

I know that nested queries is currently support for attrib access, like e.g. a folder entity query with get_folders(..., fields={"attrib.frameStart"}). Whether that works for other fields I have no idea.

Example code in codebase

That nested filtering format (by dot) matches how it was in OpenPype in pymongo. I'm not sure if that works for all keys - but just wanted to state there is some nested filtering in the codebase currently.

fabiaserra commented 4 months ago

Doing any queries in the API that filter by a field that contains nested attributes result in the following error:

I know that nested queries is currently support for attrib access, like e.g. a folder entity query with get_folders(..., fields={"attrib.frameStart"}). Whether that works for other fields I have no idea.

Example code in codebase

That nested filtering format (by dot) matches how it was in OpenPype in pymongo. I'm not sure if that works for all keys - but just wanted to state there is some nested filtering in the codebase currently.

Yeah and in the OpenPype Ayon addon there were these conversion utilities to convert that notation to something compatible https://github.com/ynput/OpenPype/blob/2671534de9a9184af55379344d74879edee9b462/openpype/client/server/conversion_utils.py#L72 although I'm wondering if I actually get any benefit from doing those stricter field queries if everytime it has to run that prep code