Skip to content
New issue

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

Prisma 5.12 client for edge runtime disabled the [Prisma.dmmf] property for wasm client #23913

Open
alexdoan102 opened this issue Apr 21, 2024 · 8 comments
Labels
kind/improvement An improvement to existing feature and code. team/client Issue for team Client. topic: dmmf topic: driverAdapters topic: wasm

Comments

@alexdoan102
Copy link

alexdoan102 commented Apr 21, 2024

Bug description

Prisma 5.12 client for edge runtime disabled the [Prisma.dmmf] property for wasm client.

for Pothos Graphql client, they need access to [Prisma.dmmf] property to render the graphql.

reference: #22962 (comment)

here is the code in prisma runtime core [defineDmmfProperty].
=> The runtimeDatamodel is already generated for the edge client anyways.
=> you are only disallowing access to this property for wasm/edge. (the datamodel value is generated...just not accessible)
=> please remove the wasm check, and allow the Prisma.dmmf property to be accessed by 3rd party Pothos graphql plugin.

image

How to reproduce

Expected behavior

  1. create cloudflare project and use Prisma 5.12.1
  2. Use the previewFeatures = ["driverAdapters"]
  3. use the PrismaClient with Pothos Graphql library
  4. try to access the [Prisma.dmmf] property

you will get error ' Prisma.dmmf is not available when running in edge runtimes.

Prisma information

any prisma schema

Environment & setup

OS: windows 10
Database: [PostgreSQL]
Node.js version: v18.16.0

Prisma Version

prisma 5.12.1
@prisma/client 5.12.1
@prisma/adapter-pg 5.12.1

@alexdoan102 alexdoan102 added the kind/bug A reported bug. label Apr 21, 2024
@janpio janpio added topic: driverAdapters kind/improvement An improvement to existing feature and code. team/client Issue for team Client. topic: wasm topic: dmmf and removed kind/bug A reported bug. labels Apr 23, 2024
@SevInf
Copy link
Contributor

SevInf commented Apr 24, 2024

Michael is right here, we've removed a property from edge build to save on the bundle size, since most of our users don't use Prisma.dmmf. Edge builds with driver adapters on don't have enough information to re-create it 1:1 anymore - we kept only the information Prisma client itself needs to function.

Generally, ideal way to proceed for pothos would be using dmmf from generator. It is guaranteed to stay complete and reasonably backward compatible for a long time.
Another option would be using prisma._runtimeDataModel private property of the client. It's a private property with no backward compatibility guarantees, but it contains similar information to what Prisma.dmmf had.
Finally, if we get confirmation from @hayes that information in prisma._runtimeDataModel is enough for pothos to function, we might re-create reduced Prisma.dmmf from runtimeDataModel. If it is not, we will be pretty hesitant to restore the information we don't use ourselves - we are on a pretty tight size budget when it comes to edge deployments.

@hayes
Copy link
Contributor

hayes commented Apr 24, 2024

Pothos already uses prisma._runtimeDataModel by default. I think the issue is that it was reduced further for edge environments in the latest version. I think the things removed were the relations and indexes (but I haven't looked closely)

@hayes
Copy link
Contributor

hayes commented Apr 24, 2024

This is the trimmed down version of what Pothos needs to function (omitting documentation just removes the comments from the schema, and probably isn't needed by most people)
Screenshot 2024-04-24 at 3 40 55 PM

@hayes
Copy link
Contributor

hayes commented Apr 24, 2024

this data was available in Prisma.dmmf.datamodel, client.dmmf.datamodel, client._baseDmmf?.datamodel, and client._runtimeDataModel, but some of the information was removed from the new PrunedRuntimeModel

@hayes
Copy link
Contributor

hayes commented Apr 24, 2024

It would be relatively straightforward to write a generator that generates all the needed data in the existing format. I'm open to suggestions here

@alexdoan102
Copy link
Author

@SevInf @hayes i tried the [runtimeDataMdel] from the edge.js that is generated for the prisma client, and pothos works with this.

@SevInf pothos this will work with [runtimeDataMdel]. If you can allow Prisma.dmmf to be accessible from edge runtime, and get this [runtimeDataMdel] value, it will work.

@hayes i dont see a need to generate this twice. IMHO, i think Prisma should allow access to this value, and we should be good to go.

image

image

@SoraKumo001
Copy link

I am using runtimeDataMdel for automatic GraphQL generation.
https://github.com/SoraKumo001/cloudflare-graphql-d1

Currently, we are using this to work around the problem.

import fs from 'fs';

const srcPath = 'node_modules/.prisma/client/index.js';
const destPath = 'node_modules/.prisma/client/wasm.js';

const src = fs.readFileSync(srcPath);
const runtimeDataModel = String(src).match(/config\.runtimeDataModel = JSON\.parse\(".*"\)/)?.[0];
if (runtimeDataModel) {
	const dist = fs.readFileSync(destPath);
	const newRuntimeDataModel = String(dist).replace(/config\.runtimeDataModel = JSON\.parse\(".*"\)/, runtimeDataModel);
	fs.writeFileSync(destPath, newRuntimeDataModel);
}

@alexdoan102
Copy link
Author

@SevInf i tried the [runtimeDataMdel] from the edge.js that is generated for the prisma client, and pothos works with this.

can we get the edge to allow access to Prisma.dmmf ? please advise. thx.

cc: @hayes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/improvement An improvement to existing feature and code. team/client Issue for team Client. topic: dmmf topic: driverAdapters topic: wasm
Projects
None yet
Development

No branches or pull requests

5 participants