-
Notifications
You must be signed in to change notification settings - Fork 78
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
Query Parser infer view #345
Comments
The That said, it doesn't seem unreasonable to me to desire to use the query parser on its own without a view given that you can also explicitly list allowed includes (although not fields). Still, it would be a pretty unusual desire I would think. Have you considered specifying a "null view" for your use-case? Just any old view you want to define with no attributes or relationships on it that you can use to satisfy the view needed by the plug currently. |
Given this contrived example: Controller: defmodule App.Api.PostController do
use RichWeb, :controller
alias App.Repo
alias App.Post
def index(conn, _params) do
posts = Repo.all(Post)
render(conn, :index, data: post)
end
end View: defmodule App.Api.PostJSON do
use JSONAPI.View, type: "posts"
def fields do
[:title, :body]
end
end I dont need to specify a view in the controller because the phoenix controller already knows which view to use (I think). I was wondering if the QueryParser could infer the view similarly? I am not a phoenix / elixir expert so I dont know how this is done but perhaps I could find out. |
I see, it’s not that you want the query parser to operate without knowledge of the view, it’s that you want the query parser not to need to take the view explicitly. |
Yes, sorry if I worded that poorly. |
It would reduce the boiler plate I have to write. |
Yeah, that makes sense to me. I’ve not looked at how this is implemented for Phoenix either but it should be workable here you would think. |
Do you think it would be possible to use the QueryParser without specifying the view? The view is inferred (I think) if you dont use the QueryParser.
This is a code snippet that I thought we could try for:
I am happy to try to write the code if this makes sense
The text was updated successfully, but these errors were encountered: