Blitz: DB is imported in generated api routes, even if it isn鈥檛 used

Created on 28 May 2020  路  3Comments  路  Source: blitz-js/blitz

What is the problem?

Even if I鈥檓 not using a database, Blitz still expects it to be there to use queries.

Steps to Reproduce

  1. Create a project

  2. Delete the db directory

  3. Create a query

  4. Output looks like this:

import {rpcHandler} from '@blitzjs/server'
import resolver from 'app/_rpc/queries/scrapeRecipe'
import db from 'db'
export default rpcHandler('query', 'scrapeRecipe', resolver, () => db.connect())

Versions

debug: local
debug: pkgPath: /Users/dylan/dev/recipes/node_modules/@blitzjs/cli 

macOS Catalina | darwin-x64 | Node: v14.0.0

blitz: 0.11.0 (global)
blitz: 0.11.0 (local)
good first issue kinbug scopcore scopserver statudone

All 3 comments

Ah yeah! This will move into the prisma plugin eventually, but for now we can probably just wrap a try/catch around require(db) and also change to db && db.connect()

Here's where this needs changed: https://github.com/blitz-js/blitz/blob/canary/packages/server/src/synchronizer/pipeline/rules/rpc/index.ts#L68

I'd like to take a stab at this if no one else is working on it!
seems like a good place to get started with contributing 馃槂

Go ahead @MykalMachon! 馃憤

Was this page helpful?
0 / 5 - 0 ratings