-
I'm trying to add Flop to all my schemas, and I don't want to manually What else can I do? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 7 replies
-
First of all, I hope you know what you're doing, since allowing all schema fields by default for filtering and sorting can pose a security risk if the parameters you pass to the Flop query functions come from untrusted sources (HTML forms, JSON APIs, GraphQL APIs...) and you don't have additional validation. I would advice against this and recommend being explicit. If you're still sure you want to do this, you can try to derive the protocol somewhere separate from the schema module. That way, the schema module may be compiled before, and you might be able to use |
Beta Was this translation helpful? Give feedback.
-
Just curious, have you ever thought about making a library based on Flop to create contexts with built-in filtering, pagination capability? Because it's always a lot of boilerplate to have it. Usually it involves reducing params into an Ecto.Query and it's the same for every context. |
Beta Was this translation helpful? Give feedback.
First of all, I hope you know what you're doing, since allowing all schema fields by default for filtering and sorting can pose a security risk if the parameters you pass to the Flop query functions come from untrusted sources (HTML forms, JSON APIs, GraphQL APIs...) and you don't have additional validation. I would advice against this and recommend being explicit.
If you're still sure you want to do this, you can try to derive the protocol somewhere separate from the schema module. That way, the schema module may be compiled before, and you might be able to use
__MODULE__.schema(:fields)
in the protocol derivation. See https://hexdocs.pm/elixir/1.14.4/Protocol.html#derive/3. I haven't tr…