✨ New Automated Codemods

Many of the upgrade steps below can be completed using the new @redwoodjs/codemods package. Amazing! You'll run the codemods using the npm subcommand npx, which allows you to run a package without needing to install either locally or globally. Here's an example codemod you'll run from your project root directory:

<aside> 🚀 Codemod Available

npx @redwoodjs/codemods update-graphql-function

</aside>

Here are the only other things you should know in order to get the most out of this preview feature:

  1. Start by saving the current state of your project with git — there should be no uncommitted changes. This way, if you ever need to re-try or rollback a codemod step, you can easily revert using git.
  2. Always review the file changes after you run a codemod. They're going to be accurate 90% of the time. The remaining 10% is on you.
  3. Heads up 👷 Codemods currently work with npm v6, which is included with Node.js v14. (npx is a subcommand of the npm command.) If you encounter errors, you are likely using npm v7 (Node.js v16). Confirm by running npm --version.

Need to switch versions? Try nvm for Mac or Windows.

<aside> 💡 Helpful Typescript Commands These tips only apply after you have upgraded to the latest release.

You might notice type errors that don't seem right or up-to-date. Try:

If you see Prisma type errors, you might need to re-generate the Prisma client:

Table of Contents

v0.37 Upgrade Guide

This is the upgrade guide the v0.37 Release Notes <link here>

A. Change imports and graphql.js handler function

We've done some house keeping, and now your API-side packages are split across two packages:

<aside> 💡 Have you already upgraded your project to use Envelop+Helix? If you are already using @redwoodjs/graphql as an experimental feature via these instructions, you will not need to complete steps 1 through 3 below. However, verify your implementation is correct — some aspects may have changed.

</aside>

1. Add @redwoodjs/graphql-server as a dependency to your api side

yarn workspace api add @redwoodjs/graphql-server

Your ./api/package.json should look like this:

{
  "name": "api",
  "version": "0.0.0",
  "private": true,
  "dependencies": {
    "@redwoodjs/api": "0.36.4" // your current version may be different
+   "@redwoodjs/graphql-server": "0.37.0"
  }
}

2. Change imports in ./api/src/functions/graphql.{js/ts} - and how you call the function

<aside> 🚀 Codemod Available To implement this step via automated codemod, run:

npx @redwoodjs/codemods update-graphql-function

</aside>

You only need createGraphQLHandler now.

<aside> 💡 Reference template file: api/src/functions/graphql.ts

</aside>

-import {
-  createGraphQLHandler,
-  makeMergedSchema,
-  makeServices,
- } from '@redwoodjs/api'

// We only need this import 👇
+ import { createGraphQLHandler } from '@redwoodjs/graphql-server' 

// We now use glob imports for services, directives and sdls 👇
import services from 'src/services/**/*.{js,ts}'
- import schemas from 'src/graphql/**/*.{js,ts}'
+ import directives from 'src/directives/**/*.{js,ts}'
+ import sdls from 'src/graphql/**/*.sdl.{js,ts}'

import { getCurrentUser } from 'src/lib/auth.js' // may not exist in your application
import { db } from 'src/lib/db'
import { logger } from 'src/lib/logger'

export const handler = createGraphQLHandler({
  loggerConfig: { logger, options: {} },
	getCurrentUser, // may not exist in your application
-  schema: makeMergedSchema({
-    schemas,
-    services: makeServices({ services }),
-  }),
// Just pass them in 👇
+ directives,
+ sdls,
+ services,
  onException: () => {
    // Disconnect from your database with an unhandled exception.
    db.$disconnect()
  },
})

3. Update imports for Errors and Context

<aside> 🚀 Codemod Available To implement this step via automated codemod, run:

npx @redwoodjs/codemods update-api-imports

</aside>

Errors

In your services, or in ./api/src/lib/auth if you are using AuthenticationError or ForbiddenError - change where these are imported from.

<aside> 💡 An easy way to check this is to search for the string "from '@redwoodjs/api'", then check the imports for imports - like AuthenticationError, ForbiddenError - and move them across as necessary.

</aside>

- import { AuthenticationError } from '@redwoodjs/api'
+ import { AuthenticationError } from '@redwoodjs/graphql-server'

Context

Search and replace imports of context, so it's imported from graphql-server instead

- import { context } from '@redwoodjs/api'
+ import { context } from '@redwoodjs/graphql-server'

If you have a typescript project, you can validate your project using a typescript check

yarn rw type-check api
# or 
yarn rw tsc api