Skip to content

How to automatically create a Flop.Schema for all fields? #328

Answered by woylie
egze asked this question in Q&A
Discussion options

You must be logged in to vote

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…

Replies: 2 comments 7 replies

Comment options

You must be logged in to vote
1 reply
@egze
Comment options

Answer selected by egze
Comment options

You must be logged in to vote
6 replies
@egze
Comment options

@woylie
Comment options

@egze
Comment options

@woylie
Comment options

@egze
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants