Skip to content
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

Codegen failure: Enum types generates an invalid type definition as enums do not implement Codable #246

Closed
rodrigoelp opened this issue Dec 10, 2019 · 5 comments
Labels
bug Something isn't working datastore Issues related to the DataStore category

Comments

@rodrigoelp
Copy link

Let's take the following example:

enum Gender {
  male,
  female,
  none,
  nonBinary,
  unspecified
}

type Person @model 
  (mutations: { create: "newPerson", update: "updatePerson", delete: null } ) {

  id: ID!
  name: String!
  gender: Gender!
}

I would expect this generation to be pretty straight forward, but building this code will generate an error indicating Person is not decodable. Checking the generated definition I can see a Person.swift, Person+Extensions.swift and a Gender.swift file without any extension.

Fixing this issue is simple, basically just add the extension file manually and type in:
extension Gender: Codable { }... But I would imagine this is the responsibility of the code generator to put in place.

@palpatim palpatim added bug Something isn't working datastore Issues related to the DataStore category labels Jan 13, 2020
drochetti added a commit that referenced this issue Feb 13, 2020
**Notes:**

- introduced a `PersistentModel` protocol to indicate enums that can be
persisted
- changed `ModelRegistry` to accept enum registration
- updated the DataStore plugin to handle `PersistentEnum`
drochetti added a commit that referenced this issue Mar 5, 2020
This fixes problems reported in several issues:  #111 #240 #246 #318 #314

**Notes:**

- added support for SQLite to handle Enums
- added support for SQLite to handle non-model types:
  - custom Codable structs
  - codable arrays
- added tests to make sure the right values are represented as SQLite
bindings
- remove field type string representation
- re-organized schema related files
- add support for Enum and non-model types
- remove commented code
- fix SQLite Int64 precision
- improve documentation and test cases
- better error handling and parameter naming
- addressed PR feedback
- add tests for `AnyEncodable`
- renamed variables for improved readability
- improved error message
- minor naming changes to address PR feedback
- update cocoapods version to be in sync with master

**Tests:**

- added a model that has all types of fields to make it easier to
visualize how data is represented on SQLite

**Pending:**

- More documentation
- GraphQL clenup on API category
@drochetti
Copy link
Contributor

Hi @rodrigoelp, support for codable enums just landed in master. We will release Amplify soon along with a new version of the Amplify CLI with the codegen updated. I'll keep this issue open until the release is out.

@AnruStander
Copy link

Has this been fixed yet? I have the same issue in my project at the moment.

@yosuke1985
Copy link

Still same issue..
@drochetti When it will be released?

@drochetti
Copy link
Contributor

drochetti commented May 29, 2020

Hey @rodrigoelp @yosuke1985 @AnruStander we just released a stable v1.0.0.

Enums should work correctly in 1.0.0. Can you try and let me know if that fixes the issue for you?


I appreciate your patience and the fact you tried our unstable preview and provided valuable feedback and insights with your issue report. I hope the stable release fixes things for you.

We also have a brand new Discord server for Amplify related topics. Feel free to hit me up there to talk about your use cases and challenges with the new APIs and docs. https://discord.gg/amplify

@drochetti
Copy link
Contributor

Closing this issue. Feel free to open a new one if you have problems with the stable version of Amplify.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working datastore Issues related to the DataStore category
Projects
None yet
Development

No branches or pull requests

6 participants