prisma-multi-tenant icon indicating copy to clipboard operation
prisma-multi-tenant copied to clipboard

ERROR: zero-length delimited identifier at or near """"

Open asaadawey opened this issue 4 years ago • 1 comments

I have downloaded the latest pmt version V2.4.2

i have initated pmt , added a tenant . and added the prisma = await multiTenant.get('test')

inside the context (btw i use nexus , nexus-plugin-prisma , apollo)

here is the full error Invalid prisma.tenant.findOne() invocation:


  Error querying the database: db error: ERROR: zero-length delimited identifier at or near """"
    at PrismaClientFetcher.request (D:\7SSCarRentalProject2\CarRental-Backend\node_modules\.prisma-multi-tenant\management\runtime\
index.js:78543:15)
    at processTicksAndRejections (internal/process/task_queues.js:97:5) {
  clientVersion: '2.10.1'
}
PrismaClientInitializationError2:

Here is my full scenario

D:\7SSCarRentalProject2\CarRental-Backend>pmt init --verbose

  Installing `@prisma-multi-tenant/client` as a dependency in your app...
  $> yarn add --ignore-workspace-root-check @prisma-multi-tenant/[email protected]
warning " > @nexus/[email protected]" has unmet peer dependency "graphql@^15.3.0".
warning " > [email protected]" has unmet peer dependency "graphql@^0.12.0 || ^0.13.0 || ^14.0.0 || ^15.0.0".
warning "apollo-server > [email protected]" has unmet peer dependency "graphql@^0.12.0 || ^0.13.0 || ^14.0.0 || ^15.0.0".
warning "apollo-server > [email protected]" has unmet peer dependency "graphql@^0.12.0 || ^0.13.0 || ^14.0.0 || ^15.0.0"
.
warning "apollo-server > [email protected]" has unmet peer dependency "graphql@^0.10.5 || ^0.11.3 || ^0.12.0 || ^0.13.0 |
| ^14.0.0".
warning "apollo-server > [email protected]" has unmet peer dependency "graphql@^0.13.0 || ^14.0.0 || ^15.0.0".
warning "apollo-server > apollo-server-core > [email protected]" has unmet peer dependency "graphql@^0.12.0 || ^0.13.0 ||
 ^14.0.0 || ^15.0.0".
warning "apollo-server > apollo-server-core > [email protected]" has unmet peer dependency "graphql@^14.2.1 || ^15.0.0".
warning "apollo-server > apollo-server-core > [email protected]" has unmet peer dependency "graphql@^0.12.0 || ^0.13.0 ||
^14.0.0 || ^15.0.0".
warning "apollo-server > apollo-server-core > [email protected]" has unmet peer dependency "graphql@^0.12.0 || ^0.13
.0 || ^14.0.0 || ^15.0.0".
warning "apollo-server > apollo-server-core > [email protected]" has unmet peer dependency "graphql@^0.12.0 || ^0.13.0 || ^
14.0.0 || ^15.0.0".
warning "apollo-server > apollo-server-core > [email protected]" has unmet peer dependency "graphql@^0.12.0 || ^0.13.0 || ^14.0
.0 || ^15.0.0".
warning "apollo-server > apollo-server-core > [email protected]" has unmet peer dependency "graphql@^0.12.0 || ^0.13.0 || ^
14.0.0 || ^15.0.0".
warning "apollo-server > apollo-server-core > [email protected]" has unmet peer dependency "graphql@^0.9.0 || ^0.10.0 || ^0.11.0 |
| ^0.12.0 || ^0.13.0 || ^14.0.0 || ^15.0.0".
warning "apollo-server > apollo-server-core > [email protected]" has unmet peer dependency "[email protected] - 14".
warning "apollo-server > apollo-server-core > [email protected]" has unmet peer dependency "graphql@>=0.10.0".
warning "apollo-server > graphql-tools > [email protected]" has unmet peer dependency "graphql@^0.11.3 || ^0.12.3 || ^0.13.0 || ^1
4.0.0 || ^15.0.0".
warning "apollo-server > graphql-tools > [email protected]" has unmet peer dependency "graphql@^0.11.0 || ^0.12.0 || ^0.13.0 |
| ^14.0.0 || ^15.0.0".
warning " > [email protected]" has unmet peer dependency "graphql@^0.12.0 || ^0.13.0 || ^14.0.0".
warning " > [email protected]" has unmet peer dependency "graphql@^0.11.0 || ^0.12.0 || ^0.13.0 || ^14.0.0 || ^15.0.0".
warning " > [email protected]" has unmet peer dependency "@prisma/[email protected]".
warning " > [email protected]" has unmet peer dependency "graphql@^15.3.0".
warning " > [email protected]" has unmet peer dependency "request@^2.34".
warning "request-promise > [email protected]" has unmet peer dependency "request@^2.34".
warning " > [email protected]" has unmet peer dependency "[email protected] || 15.x".
warning " > @prisma-multi-tenant/[email protected]" has unmet peer dependency "@prisma/cli@^2.10.1".


  We will now configure the management database:

? Management database url: postgresql://postgres:123456@localhost:5432/managment?schema=public

? Are you sure of your inputs? Yes

  Updating .env and schema.prisma files...

  Generating prisma clients for both management and tenants...
  $> node "D:\7SSCarRentalProject2\CarRental-Backend\node_modules\@prisma\cli\build\index.js" generate --schema prisma/schema.prism
a
Environment variables loaded from D:\7SSCarRentalProject2\CarRental-Backend\.env
Environment variables loaded from prisma\.env
Prisma schema loaded from prisma\schema.prisma

✔ Generated Prisma Client (version: 2.10.1) to .\node_modules\@prisma\client in 426ms

You can now start using Prisma Client in your code:

import { PrismaClient } from '@prisma/client' // or const { PrismaClient } = require('@prisma/client')

const prisma = new PrismaClient()


Explore the full API: http://pris.ly/d/client

  $> node "D:\7SSCarRentalProject2\CarRental-Backend\node_modules\@prisma\cli\build\index.js" generate --schema="D:\7SSCarRentalPro
ject2\CarRental-Backend\node_modules\@prisma-multi-tenant\shared\build\prisma\schema.prisma"
Environment variables loaded from D:\7SSCarRentalProject2\CarRental-Backend\.env
Environment variables loaded from ./prisma/.env
Prisma schema loaded from node_modules\@prisma-multi-tenant\shared\build\prisma\schema.prisma

✔ Generated Prisma Client (version: 2.10.1) to .\node_modules\.prisma-multi-tenant\management in 97ms

You can now start using Prisma Client in your code:

import { PrismaClient } from './node_modules.prisma-multi-tenant\management' // or const { PrismaClient } = require('./node_modules.prisma-multi-tenant\management')

const prisma = new PrismaClient()


Explore the full API: http://pris.ly/d/client


  Setting up management database...
  $> node "D:\7SSCarRentalProject2\CarRental-Backend\node_modules\@prisma\cli\build\index.js" migrate up --create-db  --experimenta
l --schema="D:\7SSCarRentalProject2\CarRental-Backend\node_modules\@prisma-multi-tenant\shared\build\prisma\schema.prisma"
Environment variables loaded from D:\7SSCarRentalProject2\CarRental-Backend\.env
Environment variables loaded from ./prisma/.env
Prisma schema loaded from node_modules\@prisma-multi-tenant\shared\build\prisma\schema.prisma
migrate up

Datamodel that will initialize the db:

datasource management {
  provider = ["sqlite","mysql","postgresql"]
  url = "***"
}

generator client {
  provider      = "prisma-client-js"
  output        = env("PMT_OUTPUT")
  binaryTargets = ["native"]
}

model Tenant {
  name     String @id
  url      String
}

Checking the datasource for potential data loss...

Database Changes:

Migration            Database actions             Status

20200715225700-base  1 CreateTable statements.    Done

You can get the detailed db changes with prisma migrate up --experimental --verb
ose
Or read about them here:
      ./migrations/20200715225700-base/README.md


  Done with 1 migration in 237ms.



  Creating first tenant from your initial schema...

  Creating example script...

✅  Your app is now ready for multi-tenancy!

  Next step: Create a new tenant with `prisma-multi-tenant new`


D:\7SSCarRentalProject2\CarRental-Backend>pmt new --verbose

? Name of the tenant: test
? Database url: postgresql://postgres:123456@localhost:5432/managment?schema=test

? Are you sure of your inputs? Yes
  $> node "D:\7SSCarRentalProject2\CarRental-Backend\node_modules\@prisma\cli\build\index.js" migrate up --create-db --schema prism
a/schema.prisma  --experimental
Environment variables loaded from D:\7SSCarRentalProject2\CarRental-Backend\.env
Environment variables loaded from prisma\.env
Prisma schema loaded from prisma\schema.prisma
migrate up


Checking the datasource for potential data loss...

Database Changes:


Database Changes:


Database Changes:

Migration          Database actions              Status

20201031232715-t1  45 CreateTable statements.    Done
20201031232753-t3   statements.                  Done

You can get the detailed db changes with prisma migrate up --experimental --verb
ose
Or read about them here:
      ./migrations/20201031232715-t1/README.md

      ./migrations/20201031232753-t3/README.md


  Done with 2 migrations in 1.38s.



✅  Registered the new tenant into management and migrated up the database!


$ cross-env NODE_ENV=development tsnd --no-notify --respawn --transpile-only ./src
[INFO] 07:00:05 ts-node-dev ver. 1.0.0 (using ts-node ver. 9.0.0, typescript ver. 4.0.3)
Warning: [email protected] does not support @prisma/[email protected]. The supported range is: `2.10.0`. This could lead to un
defined behaviors and bugs.
� Server ready at http://localhost:4000/
� Subscriptions ready at ws://localhost:4000/graphql
PrismaClientInitializationError2:
Invalid `prisma.tenant.findOne()` invocation:


  Error querying the database: db error: ERROR: zero-length delimited identifier at or near """"
    at PrismaClientFetcher.request (D:\7SSCarRentalProject2\CarRental-Backend\node_modules\.prisma-multi-tenant\management\runtime\
index.js:78543:15)
    at processTicksAndRejections (internal/process/task_queues.js:97:5) {
  clientVersion: '2.10.1'
}


My code 👍

export const createContext = async (ctx: any): Promise<Context> => {
  let userId: number
  let prisma;
  try {
    let Authorization = ''
    try {
      // for queries and mutations
      Authorization = ctx.req.get('Authorization')
    } catch (e) {
      // specifically for subscriptions as the above will fail
      Authorization = ctx?.connection?.context?.Authorization
    }
    const multiTenant = new MultiTenant()
    const token = Authorization?.replace('Bearer ', '')
    const verifiedToken = token && verify(token, APP_SECRET) as Token
    prisma = await multiTenant.get('test')
    if (!verifiedToken.userId && verifiedToken.type !== tokens.access.name)
      userId = -1
    else userId = verifiedToken.userId
  } catch (e) {
    console.log(e)
    userId = -1
  }

  return {
    ...ctx,
    prisma ,
    pubsub,
    userId,
  }
}

asaadawey avatar Nov 02 '20 03:11 asaadawey

fixed by deleting ?schema from managment url

asaadawey avatar Nov 02 '20 04:11 asaadawey