maoosi / prisma-appsync

⚡ Turns your ◭ Prisma Schema into a fully-featured GraphQL API, tailored for AWS AppSync.
https://prisma-appsync.vercel.app
BSD 2-Clause "Simplified" License
226 stars 18 forks source link

Fields defined as arrays of enums generate incorrect GraphQL #76

Closed Tenrys closed 1 year ago

Tenrys commented 1 year ago

As seen here:

model User {
  uuid      String   @id @default(uuid())
  createdAt DateTime @default(now())
  updatedAt DateTime @updatedAt
  crmId     Int?

  email         String      @unique
  firstName     String
  lastName      String
  lastLoginDate DateTime // Managed by Cognito Lambda
  roles         UserRoles[]

  phoneUuid String?
  phone     Phone?  @relation(fields: [phoneUuid], references: [uuid])

  salesManagers Agent[]
  valuations    Valuation[]
}

In these 3 spots:

image

However it does seem like the proper input type exists and is used correctly elsewhere, so maybe it's not that hard of a fix?

  input UserRolesEnumFilter {
      equals: UserRoles
      in: [UserRoles!]
      not: UserRolesEnumFilter
      notIn: [UserRoles!]
  }
Tenrys commented 1 year ago

https://github.com/maoosi/prisma-appsync/blob/main/packages/generator/templates/schema.gql.njk#L52-L101

It looks like you'd need to simply replace regexp out the []! characters that getFieldScalar adds where field.scalar is used when checking for enums, but I don't know how clean that is for the codebase as a whole.

I'll try making a PR tomorrow, maybe a little cleaner than that.

maoosi commented 1 year ago

Fix released in 1.0.0-rc.4.