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

Issue: Schema generation issue when using Prisma @@id attributes. #149

Closed
robm94 opened this issue Jun 20, 2023 · 2 comments
Closed

Issue: Schema generation issue when using Prisma @@id attributes. #149

robm94 opened this issue Jun 20, 2023 · 2 comments
Assignees
Labels
is: bug Something isn't working package: generator Generator package
Milestone

Comments

@robm94
Copy link

robm94 commented Jun 20, 2023

After adding a many to many relation I get the following error when running "npm run dev"

[vite-node] Failed to execute file: 
 GraphQLError: Syntax Error: Expected Name, found "}".
    at syntaxError (folder_path/node_modules/prisma-appsync/dist/server/index.js:7:660)
    at P5.expectToken (folder_path/node_modules/prisma-appsync/dist/server/index.js:22:17588)
    at P5.parseName (folder_path/node_modules/prisma-appsync/dist/server/index.js:22:1728)
    at P5.parseInputValueDef (folder_path/node_modules/prisma-appsync/dist/server/index.js:22:11241)
    at P5.optionalMany (folder_path/node_modules/prisma-appsync/dist/server/index.js:22:18355)
    at P5.parseInputFieldsDefinition (folder_path/node_modules/prisma-appsync/dist/server/index.js:22:13613)
    at P5.parseInputObjectTypeDefinition (folder_path/node_modules/prisma-appsync/dist/server/index.js:22:13436)
    at P5.parseDefinition (folder_path/node_modules/prisma-appsync/dist/server/index.js:22:2517)
    at P5.many (folder_path/node_modules/prisma-appsync/dist/server/index.js:22:18474)
    at P5.parseDocument (folder_path/node_modules/prisma-appsync/dist/server/index.js:22:1904) {
  path: undefined,
  locations: [ { line: 370, column: 5 } ],
  extensions: [Object: null prototype] {

The output of the schema.gpl file looks wrong it has a lot of indents and spaces that should not be there.
Here is the schema.prisma file I used.

datasource db {
    provider = "sqlite"
    url      = env("DATABASE_URL")
}

generator client {
    provider      = "prisma-client-js"
    binaryTargets = ["native", "rhel-openssl-1.0.x"]
}

generator appsync {
    provider = "prisma-appsync"
}

model Post {
    id         Int                 @id @default(autoincrement())
    title      String
    categories CategoriesOnPosts[]
}

model Category {
    id    Int                 @id @default(autoincrement())
    name  String
    posts CategoriesOnPosts[]
}

model CategoriesOnPosts {
    post       Post     @relation(fields: [postId], references: [id])
    postId     Int // relation scalar field (used in the `@relation` attribute above)
    category   Category @relation(fields: [categoryId], references: [id])
    categoryId Int // relation scalar field (used in the `@relation` attribute above)
    assignedAt DateTime @default(now())
    assignedBy String

    @@id([postId, categoryId])
}
@maoosi
Copy link
Owner

maoosi commented Jul 6, 2023

Thanks for reporting @robm94!

The issue seems related to @@id([postId, categoryId]) as replacing it with a classic id Int @id @default(autoincrement()) solves the issue.

Will look into it and hopefully ship a fix with the next release.

@maoosi maoosi changed the title Issue: Error when adding many to many relationship to prisma schema Issue: Schema generation issue when using Prisma @@id attributes. Jul 6, 2023
@maoosi maoosi added is: bug Something isn't working package: generator Generator package labels Jul 6, 2023
@maoosi maoosi self-assigned this Jul 6, 2023
@maoosi maoosi added this to the 1.0.0-rc.7 milestone Jul 6, 2023
@maoosi
Copy link
Owner

maoosi commented Aug 7, 2023

Fix released with 1.0.0-rc.7.

@maoosi maoosi closed this as completed Aug 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
is: bug Something isn't working package: generator Generator package
Projects
Status: Released
Development

No branches or pull requests

2 participants