Tiago Correia
06/10/2020, 3:11 PMimport { 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
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
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 postBjörnstjerne Tiedemann
06/10/2020, 6:10 PM"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"
},
Björnstjerne Tiedemann
06/10/2020, 6:12 PMTiago Correia
06/10/2020, 7:54 PMRyan
06/11/2020, 8:25 AMproduction
? 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.Tiago Correia
06/11/2020, 8:28 AM