Replies: 1 comment
-
The 'nullable' problem is already solved by |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Motivation
I would like to use sea-orm alongside async-graphql. In GraphQL, one of the features it has is providing specific fields to select. This is helpful for reducing data transferred across the server to the client, but we can also use it to optimize our SQL queries. Deferring to the client which fields to select however comes with the drawback of all fields becoming optional. For example, this model may make sense to represent a table:
But, when performing a select where all of the column choices are deferred to the client:
The optionality of the original struct tends to not match.
Proposed Solutions
Initially I was thinking to derive an all-fields-optional struct from the model:
This might be somewhat tricky and I'm not too sure if it would entirely work. An easier way might be to add a method similar to
into_model
, but one that makes use of a default implementation to fill missing fields:It works well in the case of GraphQL since those defaulted fields aren't being returned anyway, and as long as it is opt-in, it shouldn't cause any confusion.
Beta Was this translation helpful? Give feedback.
All reactions