Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: upgrade prisma to 2.19.0 #130

Merged
merged 11 commits into from
Apr 2, 2021
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,14 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.

### 1.9.16-canary.0 (2020-12-30)

**Note:** Version bump only for package root





### [1.9.15](https://github.com/echobind/bisonapp/compare/v1.9.14...v1.9.15) (2020-12-30)

**Note:** Version bump only for package root
Expand Down
2 changes: 1 addition & 1 deletion lerna.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "1.9.15",
"version": "1.9.16-canary.0",
"npmClient": "yarn",
"useWorkspaces": true,
"packages": [
Expand Down
8 changes: 8 additions & 0 deletions packages/create-bison-app/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,14 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.

### 1.9.16-canary.0 (2020-12-30)

**Note:** Version bump only for package create-bison-app





### [1.9.15](https://github.com/echobind/bisonapp/compare/v1.9.14...v1.9.15) (2020-12-30)

**Note:** Version bump only for package create-bison-app
Expand Down
2 changes: 1 addition & 1 deletion packages/create-bison-app/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "create-bison-app",
"version": "1.9.14",
"version": "1.9.16-canary.0",
"description": "Creates a production-ready full-stack Jamstack app",
"license": "MIT",
"repository": "echobind/bisonapp",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ to: graphql/modules/<%= name %>.ts
---
<% camelized = h.inflection.camelize(name) -%>
<% plural = h.inflection.pluralize(camelized) -%>
import { objectType, extendType } from '@nexus/schema';
import { objectType, extendType } from 'nexus';
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Library @nexus/schema was deprecated and moved to nexus

import { UserInputError, /*ForbiddenError*/ } from 'apollo-server-micro';

// import { isAdmin } from '../services/permissions';
Expand Down
2 changes: 1 addition & 1 deletion packages/create-bison-app/template/graphql/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export async function createContext(context: ApolloApiContext): Promise<Context>
let user: User | null = null;

if (authHeader) {
user = await prisma.user.findOne({ where: { id: authHeader.userId } });
user = await prisma.user.findUnique({ where: { id: authHeader.userId } });
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a syntax change with the newest Prisma

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💯 had to do this recently in the CITJS repo as well

}

return {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { objectType } from '@nexus/schema';
import { objectType } from 'nexus';

// Profile Type
export const Profile = objectType({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { DateTimeResolver, JSONObjectResolver } from 'graphql-scalars';
import { asNexusMethod } from '@nexus/schema';
import { asNexusMethod } from 'nexus';

export const jsonScalar = asNexusMethod(JSONObjectResolver, 'json');
export const dateTimeScalar = asNexusMethod(DateTimeResolver, 'date');
10 changes: 5 additions & 5 deletions packages/create-bison-app/template/graphql/modules/user.ts.ejs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { objectType, extendType, inputObjectType, stringArg, arg } from '@nexus/schema';
import { objectType, extendType, inputObjectType, stringArg, arg } from 'nexus';
import { Role } from '@prisma/client';
<% if (host.name === 'vercel') { -%>
import { UserInputError, ForbiddenError } from 'apollo-server-micro';
Expand Down Expand Up @@ -84,7 +84,7 @@ export const Mutations = extendType({
},
resolve: async (_root, args, ctx) => {
const { email, password } = args;
const user = await ctx.db.user.findOne({ where: { email } });
const user = await ctx.db.user.findUnique({ where: { email } });

if (!user) {
throw new UserInputError(`No user found for email: ${email}`, {
Expand Down Expand Up @@ -117,7 +117,7 @@ export const Mutations = extendType({
throw new ForbiddenError('Not authorized');
}

const user = await ctx.db.user.findOne({ where: { email: args.data.email } });
const user = await ctx.db.user.findUnique({ where: { email: args.data.email } });

if (user) {
throw new UserInputError('Email already exists.', {
Expand All @@ -144,7 +144,7 @@ export const Mutations = extendType({
data: arg({ type: 'SignupInput', required: true }),
},
resolve: async (_root, args, ctx) => {
const existingUser = await ctx.db.user.findOne({ where: { email: args.data.email } });
const existingUser = await ctx.db.user.findUnique({ where: { email: args.data.email } });

if (existingUser) {
throw new UserInputError('Email already exists.', {
Expand Down Expand Up @@ -178,6 +178,6 @@ export const SignupInput = inputObjectType({
definition: (t) => {
t.string('email', { required: true });
t.string('password', { required: true });
t.field('profile', { type: 'ProfileCreateOneWithoutUserInput' });
t.field('profile', { type: 'ProfileCreateNestedOneWithoutUserInput' });
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another syntax change with latest Prisma, discovered through build error and tracking down type generations

},
});
12 changes: 6 additions & 6 deletions packages/create-bison-app/template/graphql/schema.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import path from 'path';

import { fieldAuthorizePlugin, makeSchema } from '@nexus/schema';
import { declarativeWrappingPlugin, fieldAuthorizePlugin, makeSchema } from 'nexus';
import { nexusPrisma } from 'nexus-plugin-prisma';

import prettierConfig from '../prettier.config';
Expand All @@ -13,6 +13,7 @@ export const schema = makeSchema({
types,
plugins: [
fieldAuthorizePlugin(),
declarativeWrappingPlugin(),
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was required to add to the configuration in order to satisfy some of the current schema definitions we had.
https://nexusjs.org/docs/plugins/declarativeWrapping

nexusPrisma({
experimentalCRUD: true,
outputs: {
Expand All @@ -27,18 +28,17 @@ export const schema = makeSchema({
schema: path.join(currentDirectory, 'api.graphql'),
typegen: path.join(currentDirectory, 'node_modules/@types/nexus-typegen/index.d.ts'),
},
typegenAutoConfig: {
sources: [
sourceTypes: {
modules: [
{
source: path.join(currentDirectory, 'node_modules/.prisma/client/index.d.ts'),
module: path.join(currentDirectory, 'node_modules/.prisma/client/index.d.ts'),
alias: 'db',
},
{
source: path.join(currentDirectory, 'graphql', 'context.ts'),
module: path.join(currentDirectory, 'graphql', 'context.ts'),
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the updated config Syntax, not documented well for the migration

alias: 'ContextModule',
},
],
contextType: 'ContextModule.Context',
},
prettierConfig,
});
28 changes: 14 additions & 14 deletions packages/create-bison-app/template/package.json.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
"build:nexus": "NODE_ENV=development ts-node -P tsconfig.cjs.json --transpile-only graphql/schema.ts",
"cypress:open": "cypress open",
"cypress:run": "cypress run",
"db:migrate": "yarn -s prisma migrate up --experimental && yarn build:prisma",
"db:rollback": "yarn prisma migrate down --experimental && yarn build:prisma",
"db:migrate": "yarn -s prisma migrate deploy && yarn build:prisma",
"db:rollback": "yarn prisma migrate reset && yarn build:prisma",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is reset correct here?
I think of reset as a Full Reset, not a single rollback?

e.g.
db:reset
db:rollback

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is great feedback! I think we should rename it. It does actually do a full reset and replays migrations. I need to dig back through but there wasn't a rollback per say, I think you literally need to reverse the SQL migration or do via a migration.

Copy link
Contributor

@mthomps4 mthomps4 Mar 26, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cmejet

Weird... that seems like an oversight on their part.

--

Actually just realized the new SQL migrations aren't in an up/down flow.
Maybe they add that in the next run... 🙏🏼

--

I would def rename this to reset if that is the case.
We can figure out what a true rollback looks like later. 👍🏼

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A good article I found as well about this specifically. I also like that they made a change that when you call reset it will run the seed file if it detects it there.

https://www.prisma.io/docs/concepts/components/prisma-migrate/prisma-migrate-limitations-issues#lack-of-rollbacks--down-migrations

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After thinking about this more and chatting with Cory on Nest/CS work -- I get the reasoning... Still feels odd, but I get it.

"db:setup": "yarn db:migrate && yarn prisma generate",
"db:drop": "DOTENV_CONFIG_PATH=./prisma/.env ts-node -r dotenv/config ./scripts/dropDatabase",
"dev": "concurrently -n \"WATCHERS,NEXT\" -c \"black.bgYellow.dim,black.bgCyan.dim\" \"yarn watch:all\" \"next dev\"",
Expand All @@ -22,7 +22,7 @@
"g:component": "hygen component new --name",
"g:graphql": "hygen graphql new --name",
"g:page": "hygen page new --name",
"g:migration": "yarn -s prisma migrate save --experimental",
"g:migration": "yarn -s prisma migrate dev",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated syntax for prisma 2.19.0

"g:test:component": "hygen test component --name",
"g:test:factory": "hygen test factory --name",
"g:test:request": "hygen test request --name",
Expand All @@ -44,44 +44,43 @@
"@apollo/client": "^3.0.2",
"@chakra-ui/core": "^1.0.0-rc.5",
"@chakra-ui/theme": "^1.0.0-rc.5",
"@nexus/schema": "^0.16.0",
"@prisma/client": "2.8.1",
"@prisma/client": "^2.19.0",
<% if (host.name === 'vercel') { -%>
"apollo-server-micro": "^2.18.1",
<% } -%>
<% if (host.name === 'heroku') { -%>
"apollo-server-express": "^2.18.1",
<% } -%>
"bcryptjs": "^2.4.3",
"cross-fetch": "^3.0.5",
"cross-fetch": "3.0.5",
"framer-motion": "^2.9.4",
"graphql": "^15.3.0",
"graphql-scalars": "^1.3.0",
"graphql-type-json": "^0.3.1",
"jsonwebtoken": "^8.5.1",
"next": "9.5.3",
"nexus-plugin-prisma": "^0.21.0",
"nexus": "^1.0.0",
"nexus-plugin-prisma": "^0.33.0",
"react": "16.13.1",
"react-dom": "16.13.1",
"react-hook-form": "^6.1.0",
"universal-cookie": "^4.0.3"
},
"devDependencies": {
"@apollo/react-testing": "^4.0.0",
"@graphql-codegen/cli": "1.17.6",
"@graphql-codegen/typescript": "1.17.6",
"@graphql-codegen/cli": "^1.21.3",
"@graphql-codegen/typescript": "^1.17.6",
"@graphql-codegen/typescript-operations": "^1.17.6",
"@graphql-codegen/typescript-react-apollo": "1.17.6",
"@graphql-codegen/typescript-resolvers": "1.17.4",
"@prisma/cli": "2.8.1",

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👏

"@graphql-codegen/typescript-react-apollo": "^1.17.6",
"@graphql-codegen/typescript-resolvers": "^1.17.4",
"@testing-library/cypress": "^7.0.2",
"@testing-library/dom": "^7.21.7",
"@testing-library/jest-dom": "^5.11.2",
"@testing-library/react": "^10.4.7",
"@testing-library/user-event": "^12.0.17",
"@types/bcryptjs": "^2.4.2",
"@types/jest": "^26.0.6",
"@types/node": "^14.0.26",
"@types/node": "^14.14.21",
"@types/react": "^16.9.43",
"@types/supertest": "^2.0.10",
"@vercel/node": "^1.7.3",
Expand All @@ -102,11 +101,12 @@
"nanoid": "^3.1.10",
"pg": "^8.3.0",
"prettier": "^2.0.5",
"prisma": "^2.19.0",
"start-server-and-test": "^1.11.2",
"supertest": "^4.0.2",
"ts-jest": "^26.1.3",
"ts-node-dev": "^1.0.0",
"typescript": "^3.9.7"
"typescript": "^4.1.3"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated to match peer dependencies.

},
"bison": {
"version": "<%= bisonVersion %>",
Expand Down

This file was deleted.

This file was deleted.

Loading