Hello for some reason my typel graphl is not working:
You are creating my database normally, but I cannot insert or select data:
this is my code
my ormconfig.json:
{
"type": "postgres",
"host": "localhost",
"port": 5432,
"username": "spirit",
"password": "api",
"database": "emasa_ci",
"synchronize": true,
"logging": true,
"entities": ["dist/src/entity/**/*.js"],
"migrations": ["dist/src/migration/**/*.js"],
"subscribers": ["dist/src/subscriber/**/*.js"],
"cli": {
"entitiesDir": "dist/src/entity",
"migrationsDir": "dist/src/migration",
"subscribersDir": "dist/src/subscriber"
}
}
my app.ts:
export async function startServer() {
const app = express();
const schema = await createSchema();
const connection = await createConnection();
const server = new ApolloServer({
schema,
context: ({ req, res }: any) => ({ req, res }),
});
server.applyMiddleware({ app });
return app;
}
my entity:
@ObjectType()
@Entity()
export class User extends BaseEntity {
@Field(() => Int)
@PrimaryGeneratedColumn()
id: number;
@Field()
@Column('text')
email: string;
@Field()
@Column('text')
name: string;
@Column('text')
password: string;
}
i use ts node for run on dev:
"dev": "nodemon src/index.ts --exec ts-node",
my folder structure:
Well, in the ormconfig.json you are reffering to "entities": ["dist/src/entity/**/*.js"]
.
However, the files are propably not there (or outdated) because you compile with ts-node. You should either compile with tsc
and run the code with node dist/app.js
or just change the entities path to ["src/entity/**/*.ts"]
.
Ideally you could set up a combination of both. Ts-node is great for development because its compiling in the memory (jit). However tsc will be faster in production because it compiles the whole code into js files (aot).
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.