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

Upgrade Blitz.js and Prisma #25

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ All slack tokens and secrets you can get them from Slack upon app creation. If t
The easiest way to get your `SLACK_TEAM_ID` is following what's described in [this Stack Overflow answer](https://stackoverflow.com/a/57246565).

```bash
$ yarn blitz db migrate
$ yarn blitz prisma migrate dev --preview-feature
$ yarn start
```

Expand Down
2 changes: 1 addition & 1 deletion app/messages/queries/getMessage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import Guard from "app/guard/ability"
import { Ctx, NotFoundError } from "blitz"
import db, { Prisma } from "db"

export type GetMessageInput = Pick<Prisma.FindFirstMessageArgs, "where" | "include">
export type GetMessageInput = Pick<Prisma.MessageFindFirstArgs, "where" | "include">

async function getMessage({ where }: GetMessageInput, ctx: Ctx) {
ctx.session.authorize()
Expand Down
5 changes: 4 additions & 1 deletion app/reactions/mutations/createReaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,11 @@ async function createReaction({ data }: CreateReactionInput, ctx: Ctx) {
})
if (existingReaction) return existingReaction

// Add the user connection to data
data.user = { connect: { id: ctx.session.userId } }
Copy link

Choose a reason for hiding this comment

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

Why this instead of spreading? Just curious...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't know exactly why, but when the spreading is used, the ide throws a types error. I suspect that something new about blitz + spreading data onto a non typed object makes typescript confused, but I got surprised of this too.
image

Copy link

Choose a reason for hiding this comment

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

Spookie 👻


const reaction = await db.reaction.create({
data: { ...data, user: { connect: { id: ctx.session.userId } } },
data: data,
include: { message: { include: { user: true } } },
})

Expand Down
2 changes: 1 addition & 1 deletion app/reactions/queries/getReaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import Guard from "app/guard/ability"
import { Ctx, NotFoundError } from "blitz"
import db, { Prisma } from "db"

type GetReactionInput = Pick<Prisma.FindFirstReactionArgs, "where">
type GetReactionInput = Pick<Prisma.ReactionFindFirstArgs, "where">

async function getReaction({ where }: GetReactionInput, ctx: Ctx) {
ctx.session.authorize()
Expand Down
2 changes: 1 addition & 1 deletion app/reactions/queries/getReactions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import Guard from "app/guard/ability"
import { Ctx } from "blitz"
import db, { Prisma } from "db"

type GetReactionsInput = Pick<Prisma.FindManyReactionArgs, "where" | "orderBy" | "skip" | "take">
type GetReactionsInput = Pick<Prisma.ReactionFindManyArgs, "where" | "orderBy" | "skip" | "take">

async function getReactions({ where, orderBy, skip = 0, take }: GetReactionsInput, ctx: Ctx) {
ctx.session.authorize()
Expand Down
4 changes: 2 additions & 2 deletions blitz.config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { sessionMiddleware, unstable_simpleRolesIsAuthorized } = require("@blitzjs/server")
const { sessionMiddleware, simpleRolesIsAuthorized } = require("@blitzjs/server")
const { BlitzGuardMiddleware } = require("@blitz-guard/core/dist/middleware.js")

module.exports = {
Expand All @@ -12,7 +12,7 @@ module.exports = {
],
}),
sessionMiddleware({
unstable_isAuthorized: unstable_simpleRolesIsAuthorized,
isAuthorized: simpleRolesIsAuthorized,
}),
],
/* Uncomment this to customize the webpack config
Expand Down
Empty file removed db/migrations/.keep
Empty file.
87 changes: 0 additions & 87 deletions db/migrations/20201231214134-initial-migration/README.md

This file was deleted.

38 changes: 0 additions & 38 deletions db/migrations/20201231214134-initial-migration/schema.prisma

This file was deleted.

Loading