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

amplify codegen model generates Swift enums that don't conform to Codable #3299

Closed
cpiro opened this issue Jan 29, 2020 · 7 comments
Closed
Assignees

Comments

@cpiro
Copy link

cpiro commented Jan 29, 2020

In the latest version 4.13.1, generated Swift enums don't conform to Codable. For example:

type Post {
  kind: PostKind
}

enum PostKind {
  interesting
  boring
}

While attempting to build the generated output, the Swift compiler fails with the following errors:

  • Type Post does not conform to protocol Decodable
  • Type Post does not conform to protocol Encodable
  • Cannot automatically synthesize Encodable because PostKind? does not conform to Encodable

Expected behavior

The output enum should be declared to conform to Codable. By adding the following lines to amplify/generated/models/PostKind.swift by hand, the compiler succeeds at synthesizing Codable implementations for PostKind, and my project builds correctly:

extension PostKind: Codable {
}

Versions

$ uname
Darwin
$ amplify -v
4.13.1
$ node -v
v13.6.0
$ swift --version
Apple Swift version 5.1.3 (swiftlang-1100.0.282.1 clang-1100.0.33.15)
Target: x86_64-apple-darwin19.2.0

To Reproduce

Install the CLI, then run amplify init, amplify add api, and amplify codegen model, then compile the generated code. I choose ios as the "type of app that you're building".

$ npm install -g @aws-amplify/cli@latest
[...]
+ @aws-amplify/cli@4.13.1

$ amplify init
[...]
? Choose the type of app that you're building ios
[...]

$ cat > minimal.graphql
type Post {
  kind: PostKind
}
enum PostKind {
  interesting
  boring
}

$ amplify add api
[...]
? Provide your schema file path: minimal.graphql
[...]

$ amplify codegen model

GraphQL schema compiled successfully.

Edit your schema at [...] or place .graphql files in a directory at [...]
Successfully generated models. Generated models can be found [...]
@yuth
Copy link
Contributor

yuth commented Jan 30, 2020

What version of Amplify CLI is used to generate the swift code?

@cpiro
Copy link
Author

cpiro commented Jan 30, 2020

The latest, 4.13.1. See above:

$ amplify -v
4.13.1

@yuth yuth self-assigned this Jan 30, 2020
@yuth
Copy link
Contributor

yuth commented Jan 31, 2020

This needs changes in Amplify iOS Data store client which is tracked in aws-amplify/amplify-swift#246

@stale
Copy link

stale bot commented May 9, 2020

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale
Copy link

stale bot commented Jun 14, 2020

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale
Copy link

stale bot commented Jun 21, 2020

This issue has been automatically closed because of inactivity. Please open a new issue if you are still encountering problems.

@stale stale bot closed this as completed Jun 21, 2020
@github-actions
Copy link

This issue has been automatically locked since there hasn't been any recent activity after it was closed. Please open a new issue for related bugs.

Looking for a help forum? We recommend joining the Amplify Community Discord server *-help channels for those types of questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 26, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants