RedwoodJS v0.3.2 Available: Breaking Changes ⚠

Version v0.3.2 of RedwoodJS is now available! :tada:

Breaking Change Alert

See “How to upgrade to v0.3.2” below for more information.

Changed

  • Do not import db automatically. #334

Added

  • new command yarn rw info to get system environment #329
  • create redwood-app can be instantiated in an empty directory #315 @olance
  • Prisma is updated to preview24 #303
  • Added a way to change the webpack configuration #312 @Idered

Fixed

  • Fix Netlify deploy issue with src path #338
  • Fix scaffold and sdl generator `Routes.js’ insertion order #336
  • Fix yarn rw test #290
  • Change the way that routes are matched so that it works in Firefox #308
  • Fix ‘yarn rw help’ issue with output on Windows #331

:point_right: How to upgrade to v0.3.2

(1 of 3) Create a new folder and file api/src/lib/db.js

This adds a way to instantiate the database.

  • create api/src/lib/db.js file
  • copy and paste the following into db.js
// See https://github.com/prisma/prisma2/blob/master/docs/prisma-client-js/api.md#constructor 
// for options. 

import { PrismaClient } from '@prisma/client' export const db = new PrismaClient()

(2 of 3) Manually update Files

First, add an import and update the export in your api/src/functions/graphql.js file.

See this example of the updated template file.

  • Add this line to your list of imports:
import { db } from 'src/lib/db'
  • Export db in export const handler = createGraphQLHandler({...}). Add this to the end of the export after schema: makeMergedSchema({...}) (approx. line 18):
db,

Secondly, for each Services file within api/src/services/*, do the following:

  • add this line at the top:
// api/src/services/*
import { db } from 'src/lib/db'

For example, if you completed the RedwoodJS Tutorial you would have posts.js and contacts.js within api/src/services/posts/ and api/src/services/contacts/, respectively. You would add the import statement to the top of each of those files.

(3 of 3) Update your @redwoodjs/* packages.

Four packages should be updated to v0.3.2

Root directory package.json

  • "@redwoodjs/core": "^0.3.2”

web/package.json

  • "@redwoodjs/web": "^0.3.2”
  • "@redwoodjs/router": "^0.3.2”

api/package.json

  • "@redwoodjs/api": "^0.3.2”

After updating and saving the files, install the packages from the root directory:
$ yarn install

2 Likes

@thedavid Why not have the

import { PrismaClient } from '@prisma/client'

export const db = new PrismaClient()

on top of the api/src/services/posts/ instead of importing it like

import { db } from 'src/lib/db'

You loose a lot of the autocomplete from prisma by putting it on a seperate file?

That’s a great point. We wanted to give you a single place to initiate Prisma in case you wanted to modify the constructor’s options.

I think the reason why code completion isn’t working is because we’re aliasing ./api/src/ to src/ - I’ll do a bit of investigating to make this work properly.

@guledali I’ve come up with a solution! :confetti_ball:

  1. Move ./api/jsconfig.json to ./api/src/jsconfig.json
  2. Modify it to look like this:
{
  "compilerOptions": {
    "baseUrl": ".",
    "paths": {
      "src/*": ["*"]
    },
  },
}
  1. Intelli-sense should work now!

I’ll open an issue on GitHub to make this work properly on all apps moving forward.

I tried many variations with the paths and baseUrl in the original config to make it work properly, but nothing short of moving it worked. I believe that this was working, so perhaps figuring out what changed in VSCode is a route I should investigate.

2 Likes

@peterp Is this change going to be added?

I haven’t notice any of this change at all in the recent update.

@guledali You’re right, this bumped off of my radar. I also realised that you can either have a tsconfig.json or a jsconfig.json, but not both.

I need to do some additional exploration.