GithubHelp home page GithubHelp logo

Comments (5)

palpatim avatar palpatim commented on May 19, 2024 1

There are actually 2 separate issues that you've correctly identified:

  1. Codegen isn't conforming enums to Codable
  2. DataStore expects the associated type to be a @model, which doesn't really make sense for enum values. We may in the end elect to treat them as models, but it doesn't seem right for a customer to have to tag an enum value with @model. We're working on this and will update when we have more info.

These two may end up devolving into a single root cause (again as you've correctly identified), but for now it makes sense to consider them separately.

from amplify-swift.

drochetti avatar drochetti commented on May 19, 2024

Quick update on this:

So far the best I could come up with was to introduce a new contract to enums, something like PersistableEnum:

enum PostStatus: String, PersistableEnum {
  case draft
  case published
}

protocol PersistableEnum {
    var enumValue: String { get }
}

extension PersistableEnum 
where Self: RawRepresentable, Self.RawValue == String {
    var enumValue: String { return rawValue }
}

if let value = PostStatus.draft as? PersistableEnum {
  print(value.enumValue)
}

that way we can always check Any for PersistableEnum conformance and call enumValue. Not 100% clear yet how I'm going to de-serialize a String back to PersistableEnum.

I tried using Swift built-in types only, like RawRepresentable<String>, StringRepresentable and CustomStringConvertible with no luck

from amplify-swift.

rodrigoelp avatar rodrigoelp commented on May 19, 2024

Hello, trying to understand this issue (as I think I have just hit it and I created a ticket that might be duplicate of this one with a different symptom)

Assuming my schema is:

enum Gender {
  male,
  female,
}

type Person @model 
  (mutations: { create: "newPerson", update: "updPerson", delete: "delPerson"  } ) {
  id: ID!
  name: String!
  gender: Gender!
}

The generated enum is not supported at the time of applying a mutation, right?

I created a ticket indicating the enum doesn't conform with the Codable protocol but reading this ticket (and based on my current code that is crashing Fatal error: Model with name Gender could not be found.: file) I assume it is the same root cause.

If that is the case, I can close the #246 ticket as duplicate.

from amplify-swift.

rodrigoelp avatar rodrigoelp commented on May 19, 2024

Fair enough.

Looking forward to the decision.

from amplify-swift.

drochetti avatar drochetti commented on May 19, 2024

This was resolved by PR #334

from amplify-swift.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.