-
Notifications
You must be signed in to change notification settings - Fork 199
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
Add Embeddable type to store schema info for custom types #539
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall I think the approach is mostly correct but we should not duplicate all the *Schema
, *Field
types we have for models.
We should either:
- Extract that to a protocol and make it more generic
- or use the
ModelSchema
,ModelField
for the custom types as well and add a modifier saying it's not a model (or it's an embedded type)
// MARK: - CustomCodable | ||
|
||
/// All persistent custom types should conform to the CustomCodable protocol. | ||
public protocol CustomCodable: Codable { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we need a better name for CustomCodable
. ORMs typically call these "Embedded" types, maybe we could follow that?
@jpignata also mentioned the non-model thing we keep talking about is not clear, and I agree.
577b0fe
to
376774f
Compare
376774f
to
d93b957
Compare
saw an issue (that doesn't seem critical to this PR) while testing, opening issue #541 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good! I left a couple of minor comments, but overall it looks great :)
|
||
// MARK: - CustomCodable | ||
|
||
/// All persistent custom types should conform to the CustomCodable protocol. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
update description.
also, maybe it would be good to expand on this a bit and explain the different between Embedded
and Model
if case .embedded = type { | ||
return true | ||
} | ||
if case .embeddedCollection = type { | ||
return true | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you could potentially combine both using a ,
in the same if
clause, or also use a switch
where the default returns false.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i think if case .x = type, case .y = type
is checking for both case and will never be true. not completely sure if that is the case when i saw a test failed, so i switched to using the switch statement instead
// MARK: - CustomCodable | ||
|
||
/// All persistent custom types should conform to the CustomCodable protocol. | ||
public protocol Embedded: Codable { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
minor: maybe worth considering calling the protocol Embeddable
.
It suits well what the industry usually uses (see Hibernate approach) and also the iOS naming patterns.
An Embeddable
is .embedded(type:)
in a Model
. I can see that making way more sense than "custom type" or "non-model type". =)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
that sounds good, i will make this change!
related Codegen aws-amplify/amplify-cli#4545 |
Issue #, if available:
Description of changes:
Embbeded
protocol to return the schema information for embedded types. This means the code generated schema for an embedded type should look something like this:.embeddedCollection
case to hold embbeded types which are arrays. This was required when checking type at runtime.Testing done so far
graphQLInput
API.create
DataStore.save
is successfully and is synced to the cloudBy submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.