Closed willwillis closed 3 years ago
I am also getting a GraphQLError: Syntax Error: Expected Name, found "}"
error after changing PrismaSelect
import
from
import { PrismaSelect } from '@prisma-tools/select'
to
import { PrismaSelect } from '@paljs/plugins'
my query
import { extendType, intArg } from '@nexus/schema'
import prisma from '@database/prisma'
import { PrismaSelect } from '@paljs/plugins'
export const userQuery = extendType({
type: 'Query',
definition: (t) => {
t.field('user', {
type: 'User',
args: {
userId: intArg(),
},
resolve: async (root, args, ctx, info): Promise<any> => {
const user = await prisma.user.findOne({
where: {
id: args.userId,
},
select: new PrismaSelect(info).value.select,
})
return user
},
})
},
})
my package.json
"dependencies": {
"@nexus/schema": "^0.15.0",
"@paljs/plugins": "^1.1.9",
"apollo-server-express": "^2.16.1",
"cross-env": "^7.0.2",
"dotenv-flow": "^3.2.0",
"express": "^4.17.1",
"graphql": "^15.3.0",
"nexus-plugin-prisma": "^0.17.0"
},
"devDependencies": {
"ts-node-dev": "^1.0.0-pre.59",
"tsconfig-paths": "^3.9.0",
"typescript": "^4.0.2"
}
@vimutti77 can you provide a minimal reproduction for the issue?
@AhmedElywa This is minimal reproduction https://github.com/vimutti77/Test-PrismaSelect
This is what I found when doing minimal reproduction.
many-to-many
relations in schema.prisma
.
model Post { id Int @id @default(autoincrement()) name String postCategories PostCategory[] }
model Category { id Int @id @default(autoincrement()) name String postCategories PostCategory[] }
model PostCategory { postId Int post Post @relation(fields: [postId], references: [id]) categoryId Int category Category @relation(fields: [categoryId], references: [id])
@@id([postId, categoryId]) }
2. If I add one field in a relation table, the error will disappear.
model PostCategory { foo String // <--- add this field postId Int post Post @relation(fields: [postId], references: [id]) categoryId Int category Category @relation(fields: [categoryId], references: [id])
@@id([postId, categoryId]) }
3. If I remove `new PrismaSelect(info).value`, the error will disappear.
Yes this because when we create input types for your models this model PostCategory will be empty and this gives an errors and when you add any field the input type not be empty so the issues are gone
I will look to good fix for this thanks
Same problem i think, is there any solutions?
@ZiiMakc you also have many to many relation models not have any scalar fields?
Hi all,
I hope you all review the new version 2.0.0
.
@AhmedElywa thanks, works fine now.
Thanks, @ZiiMakc for the review
I attempted to create a new pal apollo-nexus-schema app with mysql. All other steps from the
README
completed successfully. Onlysrc/nexusSchema
is failing with this error:package.json
The prisma client seems OK, I can use the client and launch studio just fine.