You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When generating code for GraphQL schemas on iOS, some features are missing, such as enum and non-model types. This ticket highlights the required changes for the upcoming iOS release of Amplify DataStore.
Enums:
Given the GraphQL schema:
enumPostStatus {
active inactive draft
}
The expected iOS code is:
import Amplify
publicenumPostStatus:String,EnumPersistable{case active
case inactive
case draft
}
Notes:
Enum values in Swift should be camelCase
The protocol being added (EnumPersistable)
Some enum values might clash with reserved keywords in Swift, in that case it needs to be escaped. To escape in Swift use back-ticks: `public`
it's not necessary to register Enums in the ModelRegistry
Non-model types (aka Nested or Embedded types)
For non-model types, the codegen should generate Swift structs that follow the same semantic of the model types minus the Model-specific rules such as : Model and using List<M> for associations (since associations are not supported in non-model types).
models cannot be used as property types of non-model types (I believe this is enforced at the transformer level already, is that correct?)
Schema definition
On the schema definition (e.g. Post+Schema.swift) when dealing with non-model types and arrays of non-model/scalar types the definition should be like:
.customType(Location.self).customType([String].self)
// complete definition of a field:
.field(example.nonModelField, is:.required, ofType:.customType(ExampleNonModelType.self))
// .collection(of) is only used for Model types
.field(example.arrayOfStringsField, is:.required, ofType:.customType([String].self))
Description
When generating code for GraphQL schemas on iOS, some features are missing, such as enum and non-model types. This ticket highlights the required changes for the upcoming iOS release of Amplify DataStore.
Enums:
Given the GraphQL schema:
The expected iOS code is:
Notes:
camelCase
EnumPersistable
)`public`
ModelRegistry
Non-model types (aka Nested or Embedded types)
For non-model types, the codegen should generate Swift structs that follow the same semantic of the model types minus the Model-specific rules such as
: Model
and usingList<M>
for associations (since associations are not supported in non-model types).The expected iOS code is:
Notes:
Model
Codable
List<M>
Schema definition
On the schema definition (e.g.
Post+Schema.swift
) when dealing with non-model types and arrays of non-model/scalar types the definition should be like:Related issues:
Edit: added information about how to define the schema for the non-model types
Edit 2:
EnumPersistable
.customType
(code samples above updated accordingly)The text was updated successfully, but these errors were encountered: