Hey im having some "problems" using nexus if someo...
# orm-help
t
Hey im having some "problems" using nexus if someone can give a look, I have a schema that looks like this
Copy code
import { makeSchema } from '@nexus/schema';
import * as types from './graphql';
import path from 'path';

export const schema = makeSchema({
  types,
  outputs: {
    schema: path.join(__dirname, 'generated', 'schema.graphql'),
    typegen: path.join(__dirname, 'generated', 'nexus.ts'),
  },
  typegenAutoConfig: {
    contextType: 'Context.Context',
    sources: [
      {
        source: require.resolve('./context'),
        alias: 'Context',
      },
    ],
  },
});
and when I try to generate it by running
Copy code
ts-node --transpile-only src/schema
I have two problems, one of them is because my resolvers call files that either have a db or redis connection and since they are not using lazy connections I get errors related to the connection failure and the generation stops, the other one is because im using this package https://www.npmjs.com/package/env-var for env variables which makes it easier to require env variables and ensure their types, so when I try to generate the schema there are files that depend on this env variables so I get errors because of the env variables not being present To keep using nexus and work around this issues I updated my redis and db connection to be lazy which solves that problem and for the env variables im setting them using env-cmd package the command now looks as follow
Copy code
env-cmd ts-node --transpile-only src/schema
when I use env-cmd on the command it runs without errors but sadly no files are generated, any clue why? sorry for the long post
b
Copy code
"scripts": {
        "start": "../node_modules/.bin/ts-node-dev --no-notify --respawn --transpileOnly index.ts",
        "postinstall": "yarn -s generate",
        "generate": "yarn -s generate:prisma && yarn -s generate:nexus",
        "generate:prisma": "dotenv yarn prisma generate",
        "generate:nexus": "ts-node --transpile-only src/schema",
        "seed": "dotenv ts-node seed.ts",
        "initDB": "dotenv -- yarn prisma migrate save --name init --experimental",
        "saveDB": "dotenv -- yarn prisma migrate up --experimental"
    },
    "dependencies": {
        "@prisma/client": "^2.0.0",
        "dotenv": "^8.2.0",
        "dotenv-cli": "^3.1.0"
    },
This is my solution for .env I use redis but as you can see the nexus generate starts with schema file not the index with server/redis ...
t
@Björnstjerne Tiedemann I don't run nexus generate against a redis connection, those are imports that exist in the in the resolvers files, the resolvers are used to generate the final schema, so the issue was that once I import the "types" above those types have imports on their files and some of them reference the redis or the db
r
Hey @Tiago Correia 👋 Is your NODE_ENV set to
production
? If so, you would have to change it to
development
to generate the files. Also passing the rest of the variables should work fine as well.
t
@Ryan that was actually it, amazing, the env was set to DEV probably there is logic on nexus side about the env variable having to be "development"
💯 1