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

generate:nexus failing for apollo-nexus-schema starter project #122

Closed
willwillis opened this issue Jul 22, 2020 · 9 comments
Closed

generate:nexus failing for apollo-nexus-schema starter project #122

willwillis opened this issue Jul 22, 2020 · 9 comments
Assignees
Labels
bug Something isn't working
Projects

Comments

@willwillis
Copy link

I attempted to create a new pal apollo-nexus-schema app with mysql. All other steps from the README completed successfully. Only src/nexusSchema is failing with this error:

> pal --version
@paljs/cli/1.1.8 win32-x64 node-v12.18.2
> yarn generate:nexus
yarn run v1.22.4
$ ts-node --transpile-only src/nexusSchema

C:\Users\Me\apollo-nexus\node_modules\graphql\error\syntaxError.js:15
  return new _GraphQLError.GraphQLError("Syntax Error: ".concat(description), undefined, source, [position]);
         ^
GraphQLError: Syntax Error: Expected Name, found "}".
    at syntaxError (C:\Users\Me\apollo-nexus\node_modules\graphql\error\syntaxError.js:15:10)
    at Parser.expectToken (C:\Users\Me\apollo-nexus\node_modules\graphql\language\parser.js:1423:40)
    at Parser.parseName (C:\Users\Me\apollo-nexus\node_modules\graphql\language\parser.js:92:22)
    at Parser.parseInputValueDef (C:\Users\Me\apollo-nexus\node_modules\graphql\language\parser.js:901:21)
    at Parser.optionalMany (C:\Users\Me\apollo-nexus\node_modules\graphql\language\parser.js:1516:28)
    at Parser.parseInputFieldsDefinition (C:\Users\Me\apollo-nexus\node_modules\graphql\language\parser.js:1066:17)
    at Parser.parseInputObjectTypeDefinition (C:\Users\Me\apollo-nexus\node_modules\graphql\language\parser.js:1050:23)
    at Parser.parseTypeSystemDefinition (C:\Users\Me\apollo-nexus\node_modules\graphql\language\parser.js:714:23)
    at Parser.parseDefinition (C:\Users\Me\apollo-nexus\node_modules\graphql\language\parser.js:144:23)
    at Parser.many (C:\Users\Me\apollo-nexus\node_modules\graphql\language\parser.js:1537:26)
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
> yarn dev
yarn dev
yarn run v1.22.4
$ ts-node-dev --no-notify --respawn --transpile-only src/server
Using ts-node version 8.10.2, typescript version 3.9.7
[ERROR] 12:35:58 GraphQLError: Syntax Error: Expected Name, found "}".
> prisma --version
Environment variables loaded from prisma\.env
@prisma/cli          : 2.3.0
Current platform     : windows
Query Engine         : query-engine e11114fa1ea826f9e7b4fa1ced34e78892fe8e0e (at ..\..\..\..\..\AppData\Local\Yarn\Data\global\node_modules\@prisma\cli\query-engine-windows.exe)
Migration Engine     : migration-engine-cli e11114fa1ea826f9e7b4fa1ced34e78892fe8e0e (at ..\..\..\..\..\AppData\Local\Yarn\Data\global\node_modules\@prisma\cli\migration-engine-windows.exe)
Introspection Engine : introspection-core e11114fa1ea826f9e7b4fa1ced34e78892fe8e0e (at ..\..\..\..\..\AppData\Local\Yarn\Data\global\node_modules\@prisma\cli\introspection-engine-windows.exe)
Format Binary        : prisma-fmt e11114fa1ea826f9e7b4fa1ced34e78892fe8e0e (at ..\..\..\..\..\AppData\Local\Yarn\Data\global\node_modules\@prisma\cli\prisma-fmt-windows.exe)

package.json

 "dependencies": {
    "@nexus/schema": "0.14.0",
    "@prisma/client": "2.3.0",
    "@paljs/nexus": "1.1.7",
    "apollo-server": "2.16.0",
    "graphql": "15.3.0"
  },
  "devDependencies": {
    "@prisma/cli": "2.3.0",
    "@types/node": "12.12.51",
    "prettier": "2.0.5",
    "ts-node": "8.10.2",
    "ts-node-dev": "1.0.0-pre.52",
    "typescript": "3.9.7"
},

The prisma client seems OK, I can use the client and launch studio just fine.

@vimutti77
Copy link

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"
  }

@AhmedElywa
Copy link
Collaborator

@vimutti77 can you provide a minimal reproduction for the issue?

@vimutti77
Copy link

@AhmedElywa This is minimal reproduction https://github.com/vimutti77/Test-PrismaSelect

This is what I found when doing minimal reproduction.

  1. The error will occur when there are 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])
}
  1. 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])
}
  1. If I remove new PrismaSelect(info).value, the error will disappear.

@AhmedElywa
Copy link
Collaborator

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

@AhmedElywa AhmedElywa self-assigned this Sep 9, 2020
@AhmedElywa AhmedElywa added the bug Something isn't working label Sep 9, 2020
@AhmedElywa AhmedElywa added this to To do in Dashboard via automation Sep 9, 2020
@ziimakc
Copy link

ziimakc commented Sep 27, 2020

Same problem i think, is there any solutions?

@AhmedElywa
Copy link
Collaborator

@ziimakc you also have many to many relation models not have any scalar fields?

Dashboard automation moved this from To do to Done Sep 29, 2020
@AhmedElywa AhmedElywa reopened this Sep 29, 2020
Dashboard automation moved this from Done to In progress Sep 29, 2020
@AhmedElywa
Copy link
Collaborator

AhmedElywa commented Sep 29, 2020

Hi all,
I hope you all review the new version 2.0.0.

@ziimakc
Copy link

ziimakc commented Sep 29, 2020

@AhmedElywa thanks, works fine now.

Dashboard automation moved this from In progress to Done Sep 29, 2020
@AhmedElywa
Copy link
Collaborator

Thanks, @ziimakc for the review

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Dashboard
  
Done
Development

No branches or pull requests

4 participants