-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Please allow to pass page
and size
directly to the query instead of having to instantiate a QueryParameter object
#185
Comments
Passing atomic parameters directly to For FastAPI apps this is best practice, but the solution is still compatible with other backend frameworks. Alternative frameworks will need to instantiate a Apart from being able to exert more fine-grained control over query parameters and parameter validation, using a Query Parameter Model also results in better OpenAPI documentation. So I am much in favor of sticking with Query Parameter Models. Also there is an interesting metaclass hack that is only possible with a Query Parameter Model. This is not a strong argument of course, but shows that using a model for parameters potentially opens many interesting possibilities. |
This means I have to either instantiate exactly I tried using |
I've decided to let my |
Hm, one of the ideas of using Query Parameters is that implementers should control |
Sorry I think I don't get it. The expected interface for code handling |
I'm not sure who are "implementers" and who are "users", but filtering is one of our main usecases |
I am aware that filtering is a very basic and very important feature, nonetheless it currently is not yet implemented. Of course you can implement a filtering solution yourself. but available filter options won't be visible in the OpenAPI docs and care must be taken to not interfere with RDFProxy query modification. In the case of filtering this should be doable, but it requires custom query construction within the route; ultimately, RDFProxy aims to provide a neat and standardized interface for filtering that is entirely controlled by the library. |
no, the type annotation does not define the interface. it defines the type. so the type has to be exactly |
I wasn't aware that Emacs with an LSP backend was hip, but if typing is hip then I guess I'm a hipster! :D A type generally denotes an upper bound of a type, so even the hippest of IDEs wouldn't panic if you passed a |
oh, wow. thats ... interesting |
oke, back to this statement: this should be discussed with the users. as the discussion above shows, rdfproxy already makes design decisions that force us into doing it the rdproxy way. it would be great if the filtering would keep working as it is now, and would not be "entirely controlled by the library". |
Just a quick follow up: Users can define whatever route parameters they want, e.g.: @app.rout("/")
def some_route(page: int = 1, size: int = 100, whatever: Any | None = None)
something = do_whatever(whatever)
query_parameteres = QueryParameters(page=page, size=size)
return adapter.query(query_parameters=query_parameteres) The interface of |
So, I strongly feel that there should be an RDFProxy-way of doing things. But if you want to do your own thing or implement functionality currently not (yet!) supported, this is of course possible. |
What do you mean by filtering "working as it is now"? If you mean
This doesn't really make sense -- the |
I'm closing this. It is clear that rdproxy does not suit our usecase in the long run and we'll find another solution |
It would be good if you provided feedback and if you would explain, why exactly RDFProxy does not meet your usecase. RDFProxy simply does not support filtering YET. You can inject FILTER clauses yourself and make it work. But once RDFProxy filtering is implemented, it will allow to filter by model fields which will also be visible in the OpenAPI docs. RDFPRoxy aims to provide a high level framework, so that users don't need to mess with query construction if they don't want to. |
Yes. RDFProxy expects a |
As mentioned, there is a scenario where subclassing Again, see Query Parameter Models |
What would the code to achieve that look like in practice? class MyParams(QueryParameters):
do_something_special: bool = False
@app.get("/written_work")
def written_work(params: Annotated[ MyParams, ??whatgoeshere?? ]) -> Page[WrittenWork]:
adapter = SPARQLModelAdapter(
target="...",
query="...",
model=WrittenWork,
)
return adapter.query(params) |
Kevin and I discussed the case of a custom A primitive route definition using a custom class MyCustomQueryParameters(QueryParameters):
custom_parameter: int = Field(default=1000, ge=999)
@app.get("/")
def base_route(
query_parameters: Annotated[MyCustomQueryParameters, Query()],
) -> Page[SomeModel]:
return adapter.query(query_parameters) This would result in the following OpenAPI docs: Again, this follows the FastAPI best practice of Query Parameter models while still allowing backend implementers to instantiate E.g. it is also possible to define a route with whatever arguments, as long as The benefit of Query Parameter models are, 1. a well defined interface for code that processes parameters, in that case rdfproxy internals, 2. FastAPI treats parameter models specially and genereates enhanced API docs. FastAPI uses additional arguments of typing.Annotated for triggering that behavior, as mentioned in the docs, the first argument of |
No description provided.
The text was updated successfully, but these errors were encountered: