Skip to content
This repository has been archived by the owner on Jul 10, 2024. It is now read-only.

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

Open
asaadawey opened this issue Nov 2, 2020 · 1 comment
Open

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

asaadawey opened this issue Nov 2, 2020 · 1 comment

Comments

@asaadawey
Copy link

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
Copy link
Author

asaadawey commented Nov 2, 2020

fixed by deleting ?schema from managment url

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant