prisma-examples icon indicating copy to clipboard operation
prisma-examples copied to clipboard

typescript/graphql-nextjs/README is missing information on how to regenerate Nexus

Open janpio opened this issue 5 years ago • 3 comments

I am not super sure, but I think if I change the schema more fundamentally I also need to generate the nexus types. Unfortunately this is not mentioned in the README, and the files itself tell me that I should not touch then.

yarn generate:nexus does not work unfortunately:

C:\Users\Jan\Documents\prisma-examples\typescript\graphql-nextjs>yarn generate:nexus
yarn run v1.22.0
$ ts-node --transpile-only pages/api
C:\Users\Jan\Documents\prisma-examples\typescript\graphql-nextjs\pages\api\index.ts:1
import { intArg, makeSchema, objectType, stringArg, asNexusMethod } from 'nexus';
       ^

SyntaxError: Unexpected token {
    at Module._compile (internal/modules/cjs/loader.js:720:23)
    at Module.m._compile (C:\ProgramData\nvm\v12.6.0\node_modules\ts-node\src\index.ts:493:23)
    at Module._extensions..js (internal/modules/cjs/loader.js:787:10)
    at Object.require.extensions.<computed> [as .ts] (C:\ProgramData\nvm\v12.6.0\node_modules\ts-node\src\index.ts:496:12)
    at Module.load (internal/modules/cjs/loader.js:643:32)
    at Function.Module._load (internal/modules/cjs/loader.js:556:12)
    at Function.Module.runMain (internal/modules/cjs/loader.js:839:10)
    at Object.<anonymous> (C:\ProgramData\nvm\v12.6.0\node_modules\ts-node\src\bin.ts:158:12)
    at Module._compile (internal/modules/cjs/loader.js:776:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:787:10)
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

🤷‍♂

janpio avatar Mar 28 '20 04:03 janpio

Hi,

I had the same problem with the gaphql-nextjs repository. If you're still having the problem try the following:

Create a file tsconfig.nexus.json

{
  "extends": "./tsconfig.json",
  "compilerOptions": {
    "module": "commonjs",
    "target": "ES5"
  }
}

Change __dirname in pages/api/index.ts to process.cwd() (for reference #1543)

export const schema = makeSchema({
  types: [Query, Mutation, Post, User, GQLDate],
  outputs: {
-    typegen: path.join(__dirname, 'nexus-typegen.ts'),
-    schema: path.join(__dirname, 'schema.graphql')+
+    typegen: path.join(process.cwd(), 'nexus-typegen.ts'),
+    schema: path.join(process.cwd(), 'schema.graphql')
  },
})

and change the generate:nexus script in package.json:

-    "generate:nexus": "ts-node  --transpile-only ./pages/api" 
+    "generate:nexus": "ts-node --project ./tsconfig.nexus.json --transpile-only ./pages/api"

edit: I just realized who you are. 😁 ... Leaving it for others who run into the same problem 👍

ankri avatar Apr 10 '20 13:04 ankri

I just realized who you are. 😁 ... Leaving it for others who run into the same problem 👍

I am exactly the right person to give this information to 😸 And thanks, one of my colleagues will hopefully be able to use your information to fix the example.

janpio avatar Apr 10 '20 19:04 janpio

Alright, thanks. While they're at it: ts-node is missing in devDependencies


just fyi: I ditched the example because it is not (yet) using nexus-plugin-prisma And since I didn't get to run that either, I am writing graphql stuff ApolloServer old-school-style

ankri avatar Apr 10 '20 19:04 ankri

The example has been updated to use Pothos & GraphQL Yoga. Feel free to re-open the issue if you're still running into the issue. :)

ruheni avatar Feb 01 '23 14:02 ruheni