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

Models named Query cause an internal GraphQL Parse Error #8153

Closed
Tracked by #7963
dkantereivin opened this issue Jul 8, 2021 · 3 comments · Fixed by #20299
Closed
Tracked by #7963

Models named Query cause an internal GraphQL Parse Error #8153

dkantereivin opened this issue Jul 8, 2021 · 3 comments · Fixed by #20299
Labels
bug/2-confirmed Bug has been reproduced and confirmed. kind/bug A reported bug. team/client Issue for team Client. topic: engine topic: Prisma's GraphQL protocol Prisma Client ↔ Query Engine communication protocol for queries topic: reserved words See https://www.prisma.io/docs/reference/api-reference/prisma-schema-reference#naming-conventions
Milestone

Comments

@dkantereivin
Copy link
Contributor

Bug description

When naming models any case of query, no operations can be performed. Originally discovered on an actual project of mine, and discussed with @janpio. Initial suspicion was that this was due to the actual content of my query, but once I managed to troubleshoot the begun, the name of the variable (which fixed the problem) became my theory.

Further confirmed by an extremely simple model with just one field producing the exact same error.

How to reproduce

Setup a basic prisma project using NPM. This means the standard:

npm init
npm i -D typescript ts-node @types/node prisma
npx prisma init
npx prisma migrate

Just use a simple sqlite3 database, it won't even query the DB because it'll crash first.

Expected behavior

This should work, and not cause this query error, or there should at least be a more descriptive error message which is specific to this error and indicates the troubleshooting step. The standard error (below) is totally useless.

C:\Users\david\Documents\Dev\prisma-querybug\node_modules\@prisma\client\runtime\index.js:33900
          throw new import_engine_core.PrismaClientUnknownRequestError(message, this.prisma._clientVersion);
                ^
Error:
Invalid `prisma.query.create()` invocation:


  Error parsing GraphQL query: query parse error: Parse error at 6:3
Unexpected `}[Punctuator]`
Expected `Name`

If the decision is made not to correct this behaviour, this should be documented.

Prisma information

Prisma Schema:

datasource db {
  provider = "sqlite"
  url      = "file:./test.db"
}

generator client {
  provider = "prisma-client-js"
}

model Query {
  id String @id @default(uuid())
  // literally not including anything else, its not because of the model contents...
}

Test Code:

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

async function main() {
    prisma.$connect();
    const qry = await prisma.query.create({
        data: {}
    });

    console.log(qry);
}

main();

with package.json:

  "devDependencies": {
    "@types/node": "^16.0.1",
    "prisma": "^2.26.0",
    "ts-node": "^10.0.0",
    "typescript": "^4.3.5"
  },
  "dependencies": {
    "@prisma/client": "^2.26.0"
  }

Environment & setup

  • OS: Windows, and likely all.
  • Database: PostgreSQL and SQLite verified, and likely all.
  • Node.js version: 15.3.0

Prisma Version

prisma               : 2.26.0
@prisma/client       : 2.26.0
Current platform     : windows
Query Engine         : query-engine 9b816b3aa13cc270074f172f30d6eda8a8ce867d (at node_modules\@prisma\engines\query-engine-windows.exe)
Migration Engine     : migration-engine-cli 9b816b3aa13cc270074f172f30d6eda8a8ce867d (at node_modules\@prisma\engines\migration-engine-windows.exe)
Introspection Engine : introspection-core 9b816b3aa13cc270074f172f30d6eda8a8ce867d (at node_modules\@prisma\engines\introspection-engine-windows.exe)
Format Binary        : prisma-fmt 9b816b3aa13cc270074f172f30d6eda8a8ce867d (at node_modules\@prisma\engines\prisma-fmt-windows.exe)
Default Engines Hash : 9b816b3aa13cc270074f172f30d6eda8a8ce867d
Studio               : 0.408.0
@dkantereivin dkantereivin added the kind/bug A reported bug. label Jul 8, 2021
@janpio janpio added bug/0-unknown Bug is new, does not have information for reproduction or reproduction could not be confirmed. team/client Issue for team Client. topic: engine topic: Prisma's GraphQL protocol Prisma Client ↔ Query Engine communication protocol for queries labels Jul 8, 2021
@pantharshit00
Copy link
Contributor

I can confirm this bug. This is can be part of #7963

@pantharshit00 pantharshit00 added bug/2-confirmed Bug has been reproduced and confirmed. process/candidate and removed bug/0-unknown Bug is new, does not have information for reproduction or reproduction could not be confirmed. labels Jul 22, 2021
@matthewmueller matthewmueller added topic: reserved words See https://www.prisma.io/docs/reference/api-reference/prisma-schema-reference#naming-conventions and removed process/candidate labels Aug 6, 2021
@matthewmueller
Copy link
Contributor

Added it to #7963, thanks @pantharshit00!

SevInf added a commit that referenced this issue Jul 19, 2023
`DMMFHelper` did not take namespaces into account and merged them all
into single map, based on the name. This is incorrect, since it is
possible to have different type with the same name in different
namespaces. In particular, this broke models named either `Query` or
`Mutation` since they match built in names from `prisma` namespace.

Now we have a separate map for each namespace.

Fix #5749
Fix #9307
Fix #8153
SevInf added a commit that referenced this issue Jul 19, 2023
`DMMFHelper` did not take namespaces into account and merged them all
into single map, based on the name. This is incorrect, since it is
possible to have different type with the same name in different
namespaces. In particular, this broke models named either `Query` or
`Mutation` since they match built in names from `prisma` namespace.

Now we have a separate map for each namespace.

Fix #5749
Fix #9307
Fix #8153
@Jolg42 Jolg42 added this to the 5.1.0 milestone Jul 19, 2023
SevInf added a commit that referenced this issue Jul 20, 2023
`DMMFHelper` did not take namespaces into account and merged them all
into single map, based on the name. This is incorrect, since it is
possible to have different type with the same name in different
namespaces. In particular, this broke models named either `Query` or
`Mutation` since they match built in names from `prisma` namespace.

Now we have a separate map for each namespace.

Fix #5749
Fix #9307
Fix #8153
@SevInf
Copy link
Contributor

SevInf commented Jul 20, 2023

This issue is fixed and the fkx will be available in Prisma 5.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug/2-confirmed Bug has been reproduced and confirmed. kind/bug A reported bug. team/client Issue for team Client. topic: engine topic: Prisma's GraphQL protocol Prisma Client ↔ Query Engine communication protocol for queries topic: reserved words See https://www.prisma.io/docs/reference/api-reference/prisma-schema-reference#naming-conventions
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants