I want to start exploring the typegraphql-prisma integration based on the existing TypeGraphQL + Prisma example in the prisma-examples repo.
To reproduce the error, you can set up the example:
git clone [email protected]:prisma/prisma-examples.git --depth=1
cd prisma-examples/typescript/graphql-typegraphql
npm install
npm run dev
The example itself doesn't use the integration yet, so I wanted to add it with the following steps. Installed the required deps:
npm i -D typegraphql-prisma
npm i graphql-type-json
npm i graphql-fields @types/graphql-fields
Then I added the generator:
generator typegraphql {
provider = "typegraphql-prisma"
}
And ran npx prisma generate.
I then see the new files in node_modules/@generated/type-graphql.
Now I want to use some of the generated default resolvers and adjust src/index.ts as follows:
import "reflect-metadata";
import * as tq from "type-graphql";
import { PostResolver } from "./PostResolver";
import { UserResolver } from "./UserResolver";
import { GraphQLServer } from "graphql-yoga";
import { createContext } from "./context";
import {
CreateUserResolver,
UpdateUserResolver,
DeleteUserResolver,
FindOneUserResolver,
FindManyUserResolver,
} from "@generated/type-graphql";
const app = async () => {
const schema = await tq.buildSchema({
resolvers: [PostResolver, UserResolver, CreateUserResolver, UpdateUserResolver, DeleteUserResolver, FindOneUserResolver, FindManyUserResolver],
});
const context = createContext();
new GraphQLServer({ schema, context }).start(() =>
console.log(`馃殌 Server ready at: http://localhost:4000\n猸愶笍`)
);
};
app();
However, when I'm trying to run this I'm getting the following error:
Using ts-node version 9.0.0, typescript version 3.8.3
/Users/nikolasburk/Desktop/prisma-examples/typescript/graphql-typegraphql/node_modules/@generated/type-graphql/index.ts:1
export * from "./enums";
^^^^^^
SyntaxError: Unexpected token 'export'
at wrapSafe (internal/modules/cjs/loader.js:1053:16)
at Module._compile (internal/modules/cjs/loader.js:1101:27)
at Module._compile (/Users/nikolasburk/Desktop/prisma-examples/typescript/graphql-typegraphql/node_modules/source-map-support/source-map-support.js:547:25)
at Module.m._compile (/private/var/folders/sy/wzhm36711zs2jwz7kzc86z3h0000gn/T/ts-node-dev-hook-12368100111403568.js:57:25)
at Module._extensions..js (internal/modules/cjs/loader.js:1157:10)
at require.extensions.<computed> (/private/var/folders/sy/wzhm36711zs2jwz7kzc86z3h0000gn/T/ts-node-dev-hook-12368100111403568.js:59:14)
at Object.nodeDevHook [as .ts] (/Users/nikolasburk/Desktop/prisma-examples/typescript/graphql-typegraphql/node_modules/ts-node-dev/lib/hook.js:61:7)
at Module.load (internal/modules/cjs/loader.js:985:32)
at Function.Module._load (internal/modules/cjs/loader.js:878:14)
at Module.require (internal/modules/cjs/loader.js:1025:19)
[ERROR] 08:47:51 SyntaxError: Unexpected token 'export'
Any thoughts on what I'm missing here?
typegraphql-prisma generates TypeScript source code files, not compiled JS + d.ts files.
So if you emit the files to node_modules, they might be omitted by default TS config, so they won't be compiled and Node will occur some syntax errors because of that.
I think I should make that output setting explicit for now, until I start emit JS code to node_modules.
So please update your generator config block:
generator typegraphql {
provider = "typegraphql-prisma"
output = "../prisma/generated/type-graphql"
}
Or try to include that node_modules folder in compilation step 馃槈
Awesome, thanks for the prompt response! Changing the output path indeed solved the issue 馃憤
Most helpful comment
typegraphql-prismagenerates TypeScript source code files, not compiled JS + d.ts files.So if you emit the files to
node_modules, they might be omitted by default TS config, so they won't be compiled and Node will occur some syntax errors because of that.I think I should make that
outputsetting explicit for now, until I start emit JS code tonode_modules.So please update your generator config block:
Or try to include that node_modules folder in compilation step 馃槈