Skip to content

API tests assume api/src/lib/db to export a Prisma client #3707

@olance

Description

@olance

... and pretty much any Redwood command for that matter.

In my current project, I decided to go with Firebase's Firestore database.
So I'm building a Redwood app with an API side but where the exported db is just:

export const db = app.firestore()

I've got my services working well with this, so I can take advantage of all the GraphQL niceties from the web side.

However, on the API side, I'm facing a roadblock when writing/running tests for a custom function:
image

It appears that, deep within Redwood, it is assumed that a Prisma client will always be used.
Given the line that's failing (await db.$executeRawUnsafe(`DELETE from "${model}"`)) and the nature of supported databases from Prisma, I'd even say Redwood assumes a relational/SQL database is being used.

I'm aware that Prisma is the tool of choice for DB access/"ORM" in Redwood, but the fact that the DB connection object is actually part of the application code makes me want to be able to use something different all together (and since Prisma does not support Firestore, I actually don't have much of a choice).

So I'm wondering if something could be done to have the tests setup be agnostic of the nature of db?

Also, FWIW:

  • I also had to declare a Dummy model in my schema.prisma file so that common Redwood commands could run at all, since many of them always start with generating a Prisma client.
  • I've had a look at scenarios for testing, and I'm wondering if it's also "hardwired" to Prisma or if it's using declared services for the different models to generate the scenario data?

@ajcwebdev I saw your tutorial on Redwood + FaunaDB; did you get API side tests to work in any way?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions