Prisma Docs Generator Quick Start

@drigger / @pantharshit00 (on Twitter) released a Prisma docs generator:

Steps to get going:

Generate Docs

  1. yarn workspace api add prisma-docs-generator
  2. Add to api/prisma/schema.prisma
generator docs {
  provider = "node node_modules/prisma-docs-generator"
}
  1. 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

  1. cd api/prisma/docs
  2. npx prisma-docs-generator serve currently has an error because needs a path to the schema
  3. Workaround is to launch a local webserver like:

python3 -m http.server 8000

Example

2 Likes

Thanks for sharing @dthyresson :slight_smile:

I will work on reducing the friction with the CLI with redwood.

3 Likes

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?

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:

  1. yarn create redwood-app rw-153-auth
  2. cd rw-153-auth
  3. yarn install
  4. edited schema to be
model User {
  id    Int     @id @default(autoincrement())
  email String  @unique
  name  String?
}
  1. yarn rw db save
  2. yarn rw db up
  3. yarn rw db studio
  4. added a User record and saved; exited studio
  5. yarn workspace api add prisma-docs-generator
  6. npx prisma generate --schema api/prisma/schema.prisma
  7. see new api/prisma/docs folder created
  8. cd api/prisma/docs
  9. Important: we cannot use the npx prisma-docs-generator serve because missing path to schema
  10. so instead,
  11. inside api/prisma/docs
  12. python3 -m http.server 8000 to launch a simple http server
  13. visit http://localhost:8000/

I can reproduce your error, though by:

  1. cd api/prisma
  2. 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”.

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.