We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
npm
v17.9.0
10.8.1
Mac
codegen models
Typescript generated from amplify codegen models does not correctly map field types of enum arrays in GraphQL to expected typescript type.
amplify codegen models
airends/amplify/backend/api/airends/schema.graphql
enum DayOfWeek { MONDAY TUESDAY WEDNESDAY THURSDAY FRIDAY SATURDAY SUNDAY } enum Frequency { YEARLY WEEKLY } type Recurrence { frequency: Frequency! interval: Int! daysOfWeek: [DayOfWeek!]! }
airends/src/models/index.d.ts
type EagerRecurrence = { readonly frequency: Frequency | keyof typeof Frequency; readonly interval: number; readonly daysOfWeek: DayOfWeek[] | keyof typeof DayOfWeek; } type LazyRecurrence = { readonly frequency: Frequency | keyof typeof Frequency; readonly interval: number; readonly daysOfWeek: DayOfWeek[] | keyof typeof DayOfWeek; } export declare type Recurrence = LazyLoading extends LazyLoadingDisabled ? EagerRecurrence : LazyRecurrence
I would expect the type for daysOfWeek field to be something like
readonly daysOfWeek: DayOfWeek[] | (keyof typeof DayOfWeek)[]
instead of
readonly daysOfWeek: DayOfWeek[] | keyof typeof DayOfWeek;
Which allows the field to be single value instead of forcing it to be an array.
Am I missing something here?
amplify codegen models --max-depth=3
# Put schemas below this line enum DayOfWeek { MONDAY TUESDAY WEDNESDAY THURSDAY FRIDAY SATURDAY SUNDAY } enum Frequency { YEARLY WEEKLY } type Recurrence { frequency: Frequency! interval: Int! daysOfWeek: [DayOfWeek!]! } type Duration { seconds: Int minutes: Int hours: Int days: Int weeks: Int months: Int years: Int } enum Sentiment { VERY_DISSATISFIED DISSATISFIED SATISFIED VERY_SATISFIED } enum Effort { EXTRA_SMALL SMALL MEDIUM LARGE EXTRA_LARGE } enum ResolutionType { ABANDONED COMPLETED } type Resolution { resolvedAt: AWSDateTime! type: ResolutionType! effort: Effort sentiment: Sentiment duration: Duration resolvedBy: String } enum TodoStatus { PENDING ACTIVE ABANDONED COMPLETED } enum Priority { LOW NORMAL HIGH CRITICAL } type Todo @model @auth(rules: [{ allow: owner }]) { effectiveAt: AWSDateTime dueAt: AWSDateTime priority: Priority! status: TodoStatus! task: Task! @belongsTo resolution: Resolution createdBy: String } type Task @model @auth(rules: [{ allow: owner }]) { id: ID! title: String summary: String tags: [Tag!] @manyToMany(relationName: "TaskTag") todos: [Todo!] @hasMany schedule: [Recurrence!] } type Tag @model @auth(rules: [{ allow: owner }]) { id: ID! name: String! description: String tasks: [Task!] @manyToMany(relationName: "TaskTag") color: String }
# Put your logs below this line
No response
The text was updated successfully, but these errors were encountered:
Successfully merging a pull request may close this issue.
Before opening, please confirm:
How did you install the Amplify CLI?
npm
If applicable, what version of Node.js are you using?
v17.9.0
Amplify CLI Version
10.8.1
What operating system are you using?
Mac
Amplify Codegen Command
codegen models
Describe the bug
Typescript generated from
amplify codegen models
does not correctly map field types of enum arrays in GraphQL to expected typescript type.airends/amplify/backend/api/airends/schema.graphql
airends/src/models/index.d.ts
Expected behavior
I would expect the type for daysOfWeek field to be something like
readonly daysOfWeek: DayOfWeek[] | (keyof typeof DayOfWeek)[]
instead of
readonly daysOfWeek: DayOfWeek[] | keyof typeof DayOfWeek;
Which allows the field to be single value instead of forcing it to be an array.
Am I missing something here?
Reproduction steps
amplify codegen models --max-depth=3
GraphQL schema(s)
Log output
Additional information
No response
The text was updated successfully, but these errors were encountered: