#javascript #typescript #graphql #typeorm #typegraphql
Вопрос:
Это код для простого API в typegraphql, typeorm
Я столкнулся с проблемой в некотором синтаксисе, поскольку в настоящее время это не удается исключительно из-за сбоя импорта.
Я сделал очень простые вещи в своем index.ts
файле
- Подключено к базе данных postgres
- Настройте сервер apollo с помощью некоторых распознавателей, которые я построил
Это мой индекс.ts
// src/index.ts
import "reflect-metadata";
import { createConnection } from "typeorm";
import { ApolloServer } from "apollo-server";
import {buildSchema} from 'type-graphql'
async function main() {
try {
const connection = await createConnection({
name: "PostgresDB",
type: "postgres",
host: "",
port: 5432,
username: "",
password: "",
database: "",
synchronize: true,
ssl: {
rejectUnauthorized:false
},
logging: true,
entities: ["src/entity/*.*"]
})
const schema = await buildSchema({
resolvers: [
CoordinateResolver,
CarrierLiveLocationResolver,
CurrentRoutesResolver,
DepotsOnPlatformResolver
]
})
const server = new ApolloServer({ schema })
await server.listen(4000)
console.log("Server has started!")
} catch (error) {
console.log(error)
console.log('life is hard')
}
}
main()
это мой tsconfig.json
{
"compilerOptions": {
"target": "es5",
"module": "commonjs",
"strict": true,
"esModuleInterop": true,
"experimentalDecorators": true,
"emitDecoratorMetadata": true,
"strictPropertyInitialization": false,
"baseUrl": "./",
"paths": {
"@entity/*": ["./src/entity/*"],
"@resolvers/*": ["./src/resolvers/*"],
"@inputs/*": ["./src/inputs/*"]
}
}
}
это мой пакет.json
{
"name": "typegraphql-api",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo "Error: no test specified" amp;amp; exit 1",
"start": "nodemon -w src --ext ts --exec ts-node src/index.ts"
},
"repository": {
"type": "git",
"url": "git https://TRFDCYUIJNKL.git"
},
"keywords": [],
"author": "",
"license": "ISC",
"bugs": {
"url": "https://TRFDCYUIJNKL/issues"
},
"homepage": "https://TRFDCYUIJNKL#readme",
"dependencies": {
"apollo-server": "^3.4.0",
"class-validator": "^0.13.1",
"graphql": "^15.6.1",
"pg": "^8.7.1",
"reflect-metadata": "^0.1.13",
"type-graphql": "^1.1.1",
"typeorm": "^0.2.38"
},
"devDependencies": {
"ts-node": "^10.3.0",
"typescript": "^4.4.4"
}
}