question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

AWS Datastore - Amplify codegen models creates always an id even when the schema does not contains thats

See original GitHub issue

Ik have a schema with these models, so without an ID field:

type User
  @model
  @key(fields: ["horecaID", "userID"])
  @auth(
    rules: [
      { allow: groups, groups: ["owner", "supervisor"] }
      { allow: owner, ownerField: "owner", identityClaim: "custom:horeca" }
    ]
  ) {
  horecaID: ID!
  userID: ID!
  owner: ID!
  name: String!
  lastDateLogin: String
  group: Group
}

type HorecaCategoryItems
  @model
  @auth(
    rules: [
      { allow: owner, ownerField: "owner", identityClaim: "custom:horeca" }
      { allow: groups, groups: ["owner", "supervisor"] }
      { allow: public, provider: iam, operations: [read] }
      { allow: groups, groups: ["servant", "kitchen"], operations: [read] }
    ]
  ) {
  horecaID: ID!
  category: [Category]!
  owner: ID!
}

when I run amplify codegen models and look into index.d.ts into the model dir I have these items with a readonly ID.

export declare class HorecaCategoryItems {
  readonly id: string;
  readonly horecaID: string;
  readonly category: Category[] | keyof typeof Category;
  readonly owner: string;
  constructor(init: ModelInit<HorecaCategoryItems>);
  static copyOf(source: HorecaCategoryItems, mutator: (draft: MutableModel<HorecaCategoryItems>) => MutableModel<HorecaCategoryItems> | void): HorecaCategoryItems;
}

export declare class User {
  readonly id: string;
  readonly horecaID: string;
  readonly userID: string;
  readonly owner: string;
  readonly name: string;
  readonly lastDateLogin?: string;
  readonly group?: Group | keyof typeof Group;
  constructor(init: ModelInit<User>);
  static copyOf(source: User, mutator: (draft: MutableModel<User>) => MutableModel<User> | void): User;
}

Then you get these type of errors:

Sync error, Connection failed: {"errors":[{"message":"Validation error of type FieldUndefined: Field 'id' in type 'User' is undefined @ 'onDeleteUser/id'"}]}

That is correct because I don’t have the ID field in my schema and so not in Dynamodb

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:8 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
rpostulartcommented, Oct 6, 2020

This one you mean?

export declare class User {
  readonly id: string;
  readonly horecaID: string;
  readonly owner: string;
  readonly name: string;
  readonly lastDateLogin?: string;
  readonly group?: Group | keyof typeof Group;
  constructor(init: ModelInit<User>);
  static copyOf(source: User, mutator: (draft: MutableModel<User>) => MutableModel<User> | void): User;
}

Nothing changed. Fyi: userID is now missing, but I am using now ID as the user id.

So it seems like that this is giving issues.

@manueliglesias has my project and code.

0reactions
github-actions[bot]commented, Oct 23, 2022

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 or Discussions for those types of questions.

Read more comments on GitHub >

github_iconTop Results From Across the Web

DataStore - Getting started - Swift - AWS Amplify Docs
The first step to create an app backed by a persistent datastore is to define a schema. DataStore uses GraphQL schema files as...
Read more >
Amplify DataStore: Use Cases and Implementation
The first step to create an application backed by a persistent datastore is to define a schema. DataStore uses GraphQL schema files as...
Read more >
AWS Amplify For Flutter Part 2: Amplify DataStore
DataStore creates platform-specific model classes using the Amplify CLI command: amplify codegen models . This command starts with the GraphQL ...
Read more >
Creating offline web apps with AWS Amplify DataStore
We won't use GraphQL directly but via the DataStore, and we already generated models for it in the last step. Only 4 CLI...
Read more >
AWS-Amplify/Lobby - Gitter
I can't find much online, and it's only a single lambda function that's ... I have a problem with 'amplify codegen models', it's...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found