blitz-js / legacy-framework

MIT License
2 stars 2 forks source link

Query / Mutation resolve can't refer templates #164

Closed dhythm closed 2 years ago

dhythm commented 2 years ago

What is the problem?

Thanks guys to maintain this awesome framework!! I face with an issue as the below.

Create queries / mutations templates like utils/templates/queriesTemplates/getCurrentUser.ts and use it from rpc/user/queries/getCurrentUser.ts and rpc/user2/queries/getCurrentUser.ts. Then, I caught a warning as Duplicate page detected.

The template doesn't have the name of queries / mutations. (https://blitzjs.com/docs/rpc-specification#url) However, it would be treated as /api/rpc/getCurrentUser

Paste all your error logs here:

ready - started server on 0.0.0.0:3000, url: http://localhost:3000
info  - Using webpack 5. Reason: Enabled by default https://nextjs.org/docs/messages/webpack5
warn  - Duplicate page detected. /app/rpc/user/queries/getCurrentUser.ts and /app/rpc/user2/queries/getCurrentUser.ts both resolve to /api/rpc/getCurrentUser.
event - compiled successfully
warn  - Duplicate page detected. /app/rpc/user/queries/getCurrentUser.ts and /app/rpc/user2/queries/getCurrentUser.ts both resolve to /api/rpc/getCurrentUser.

Paste all relevant code snippets here:

app/utils/server/templates/queriesTemplates/getCurrentUser.ts

import { Ctx } from "blitz"
import db from "db"

export default async function getCurrentUser(_ = null, { session }: Ctx) {
  if (!session.userId) return null

  const user = await db.user.findFirst({
    where: { id: session.userId },
    select: { id: true, name: true, email: true, role: true },
  })

  return user
}

app/rpc/user/queries/getCurrentUser.ts

import getCurrentUser from "app/utils/server/templates/queriesTemplates/getCurrentUser"

export default getCurrentUser

app/rpc/user2/queries/getCurrentUser.ts

import getCurrentUser from "app/utils/server/templates/queriesTemplates/getCurrentUser"

export default getCurrentUser

What are detailed steps to reproduce this?

  1. create a blitz app via blitz new
  2. create RPC template and use it from two queries
  3. run blitz dev

Run blitz -v and paste the output here:

Loaded env from /Users/y-okada/local/blitz-sample/.env.local
Loaded env from /Users/y-okada/local/blitz-sample/.env
macOS Catalina | darwin-x64 | Node: v14.15.4

blitz: 0.44.4 (local)

  Package manager: npm 
  System:
    OS: macOS 10.15.7
    CPU: (16) x64 Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
    Memory: 372.25 MB / 16.00 GB
    Shell: 5.7.1 - /bin/zsh
  Binaries:
    Node: 14.15.4 - ~/.anyenv/envs/nodenv/versions/14.15.4/bin/node
    Yarn: 1.22.11 - ~/.anyenv/envs/nodenv/versions/14.15.4/bin/yarn
    npm: 6.14.10 - ~/.anyenv/envs/nodenv/versions/14.15.4/bin/npm
    Watchman: 2021.06.07.00 - /usr/local/bin/watchman
  npmPackages:
    @prisma/client: 3.7.0 => 3.7.0 
    blitz: 0.44.4 => 0.44.4 
    prisma: 3.7.0 => 3.7.0 
    react: 18.0.0-beta-149b420f6-20211119 => 18.0.0-beta-149b420f6-20211119 
    react-dom: 18.0.0-alpha-5ca4b0433-20211020 => 18.0.0-alpha-5ca4b0433-20211020 
    typescript: ~4.5 => 4.5.4 

Please include below any other applicable logs and screenshots that show your problem:

https://github.com/dhythm/blitz-sample

dhythm commented 2 years ago

Oh, I just understood the URL specification,

File: app/products/queries/getProduct.ts
URL: /api/rpc/getProduct

File: app/products/mutations/createProduct.ts
URL: /api/rpc/createProduct

File: app/products/mutations/v2/createProduct.ts
URL: /api/rpc/v2/createProduct

So, app/rpc/user/queries/getCurrentUser.ts and app/rpc/user2/queries/getCurrentUser.ts are built to api/rpc/getCurrentUser 🤦‍♂️

beerose commented 2 years ago

Glad you solved it! Let us know if there are any other issues