Anyone using prisma-nexus in prod? How do you run...
# orm-help
l
Anyone using prisma-nexus in prod? How do you run it? With ts-node? The way the schema is created (referencing .ts files) it wont run with node after compiling with tsc..
v
I’m using it and I’m traspiling everyting to
js
l
Do you have typegenAutoConfig in makePrismaSchema?
v
yes that is a problem also for me
but actually u need that file just in dev for overwriting your types
this one
Copy code
typegenAutoConfig: {
      sources: [
        {
          source: path.join(__dirname, './generated/prisma-client/index.ts'),
          alias: 'prisma',
        },
        {
          source: path.join(__dirname, './shared/types/context.ts'),
          alias: 'ctx',
        },
      ],
      contextType: 'ctx.Context',
    },
and then u get the debug messages from nexus
l
Yeah that is the issue im seing as well.. Did you solve it somehow or just remove typegenAutoConfig?
v
talking with @divyendu we decided to just skip the problem
so is still there but is not creating troubles 🙂
anyway running the project with
ts-node
u lose in performance quite a lot..i think
d
Yes, this looks more like a developer experience issue, it is on my list to raise internally and get back 👍 in any case, please compile TS to JS for production use, tools like
ts-node
are to be used for development as they do a compile and run.
l
Thanks! ts-node-dev is unbearably slow for me so i was looking into using concurrently with tsc and nodemon instead but I guess it wont generate types..
For dev that is.. Will tsc + node in prod 👍
v
for dev I’m using this
and is amazing
"dev": "dotenv -- tsnd --inspect --respawn src/server.ts",
l
What ts-node-dev version are you runnning? It takes minutes to reboot for me.. Running a super simple demo app..
v
mmm
"ts-node-dev": "^1.0.0-pre.32",
maybe it’s your tsconfig
l
Same.. will try and remove some flags.. I got --no-notify and --transpileOnly as welll..
Yeah that might be.. Will debug.. thanks
v
u’re welcome
p
@Vittorio Adamo @Lars-Jørgen Kristiansen the reason for the error about not finding the file is to do the way you are using
__dirname
here is an example that i got working with the
--js
flag, notice that
__dirname
is wrapped by
path.resolve
Copy code
import { makePrismaSchema } from 'nexus-prisma'
import * as path from 'path'

import datamodelInfo from './generated/nexus-prisma'
import { prisma } from './generated/prisma-client'
import * as types from './resolvers'

const schema = makePrismaSchema({
  types,
  prisma: {
    datamodelInfo,
    client: prisma,
  },
  outputs: {
    schema: path.join(path.resolve(__dirname), './generated/schema.graphql'),
    typegen: path.join(path.resolve(__dirname), './generated/nexus.ts'),
  },
  nonNullDefaults: {
    input: true,
    output: true,
  },
  typegenAutoConfig: {
    sources: [
      {
        source: path.join(path.resolve(__dirname), './context.ts'),
        alias: 'ctx',
      },
    ],
    contextType: 'ctx.Context',
  },
})

export default schema
w
Hey there, in production, pass a NODE_ENV to node so that nexus stops generating the outputs file and look for the typings, you need these only in dev 🙂 eg:
NODE_ENV=production node dist/src/index.js
👍🏽 1
v
thank you!