maoosi/prisma-appsync

Feature/Issue: AWSDate Type Serialization Issue with Override Decorator

Closed this issue · 3 comments

Description:

When using the AWSDate type inside the override decorator /// @gql(scalars: { asOfDate: "AWSDate" }), the package struggles with correctly serializing from an ISO8601 DateTime to a Date.

Expected Behavior:

  1. When the AWSDate type is employed, I anticipate an automatic conversion that adapts the Date object (as given by Prisma) into an appropriate format compatible with AWSDate.
  2. The filter functionality for this field should mirror the behavior observed with DateTime. Currently, it defaults to a StringFilter, which is inconsistent with expected behavior.

Schema Model Field:

asOfDate              DateTime          @db.Date @map("as_of_date")

Relevant Screenshot:
AWSDate Serialization Issue

The date format issue you're facing is due to Prisma Client. It always returns dates as DateTime, regardless of the database format used. Here are some open issues about it:

prisma/prisma#7490
prisma/prisma#4355

Prisma-AppSync only acts as a bridge that connects Prisma to AWS AppSync and doesn't alter the data. Supporting AWSDate like AWSDateTime can only happen after the Prisma team fixes this issue.

For your use case, I would suggest removing /// @gql(scalars: { asOfDate: "AWSDate" }) entirely, so the generated GraphQL field will fallback to AWSDateTime (similar format to Prisma Client). Even though the format returned will be a DateTime, it should still save as Date in your Database.

Hi @maoosi , Thanks for the response on this! I am aware of the Prisma issue which I dont think they will ever fix so thought it could be handled in this package potentially.

Although, I agree it is not an issue with this package!

We have a solution for this using the prisma middleware or extensions, is there anyway of overriding the prisma client in prisma-appsync that would allow us to carry over our extensions?

@d-e-a-n-f yes, absolutely! You can access the underlying Prisma Client instance like this:

// init prisma-appsync
const prismaAppSync = new PrismaAppSync()

// middleware
prismaAppSync.prismaClient.$use(async (params, next) => {
    return next(params)
})

// lambda resolver
export const main = async (event: AppSyncResolverEvent<any>) => {
    return await prismaAppSync.resolve({ event })
}