@drigger / @pantharshit00 (on Twitter) released a Prisma docs generator:
Steps to get going:
Generate Docs
yarn workspace api add prisma-docs-generator
Add to api/prisma/schema.prisma
generator docs {
provider = "node node_modules/prisma-docs-generator"
}
npx prisma generate --schema api/prisma/schema.prisma
If you get an error:
Error: Get config {"is_panic":false,"message":"error: Environment variable not found: BINARY_TARGET.\n --> schema.prisma:8\n | \n 7 | provider = \"prisma-client-js\"\n 8 | binaryTargets = env(\"BINARY_TARGET\")\n | \n\nValidation Error Count: 1","meta":{"full_error":"error: Environment variable not found: BINARY_TARGET.\n --> schema.prisma:8\n | \n 7 | provider = \"prisma-client-js\"\n 8 | binaryTargets = env(\"BINARY_TARGET\")\n | \n\nValidation Error Count: 1"},"error_code":"P1012"}
then set binaryTargets = "native"
in schema.prisma
generator client {
provider = "prisma-client-js"
binaryTargets = "native"
}
Serve Docs
cd api/prisma/docs
npx prisma-docs-generator serve
currently has an error because needs a path to the schema
Workaround is to launch a local webserver like:
python3 -m http.server 8000
Example
2 Likes
Thanks for sharing @dthyresson
I will work on reducing the friction with the CLI with redwood.
3 Likes
danny
August 5, 2020, 11:54pm
3
Hi @pantharshit00 , I’m trying to set this up, but seem to be getting an error.
Error: Generator at node node_modules/prisma-docs-generator could not start:
internal/modules/cjs/loader.js:1017
throw err;
^
Error: Cannot find module '/xxx/node_modules/prisma-docs-generator'
I’ve followed @dthyresson ’s instructions above, and also tried installing on the root of the workspace. It seems there isn’t a folder of that name (in either the api folder, or the root node_modules)
Any tips?
danny:
Any tips?
I think I saw that error; let me try again in the morning from scratch in a new app and see if I can reproduce.
I think it had something to do with the directory I was in when generating.
1 Like
@danny
I followed my instructions above with a completely new app.
Here’s what I did:
yarn create redwood-app rw-153-auth
cd rw-153-auth
yarn install
edited schema to be
model User {
id Int @id @default(autoincrement())
email String @unique
name String?
}
yarn rw db save
yarn rw db up
yarn rw db studio
added a User
record and saved; exited studio
yarn workspace api add prisma-docs-generator
npx prisma generate --schema api/prisma/schema.prisma
see new api/prisma/docs
folder created
cd api/prisma/docs
Important: we cannot use the npx prisma-docs-generator serve
because missing path to schema
so instead,
inside api/prisma/docs
python3 -m http.server 8000
to launch a simple http server
visit http://localhost:8000/
I can reproduce your error, though by:
cd api/prisma
npx prisma-docs-generator serve
rw-153-auth % cd api/prisma
prisma % npx prisma-docs-generator serve
AggregateError:
Error: Generator at node node_modules/prisma-docs-generator could not start:
internal/modules/cjs/loader.js:716
throw err;
^
Error: Cannot find module 'somewhere/rw-153-auth/api/prisma/node_modules/prisma-docs-generator'
at internal/main/run_main_module.js:17:11 {
code: 'MODULE_NOT_FOUND',
requireStack: []
}
I believe @pantharshit00 will try to update
npx prisma-docs-generator serve
so that it can specify a --schema
and that should help with the “serve”.
danny
August 6, 2020, 11:22am
6
Thanks I didn’t get to that step, because I was getting the error I posted above when I run yarn rw db up
(which means I can’t have it in the codebase, because it’ll mess with dev and deployment). Definitely wasn’t trying serve, because it didn’t even generate first.