Hi, I'm Byungho Joo.
ho-s / nestjs-graphql-typeorm-postgresql Goto Github PK
View Code? Open in Web Editor NEWNestJS + GraphQL + TypeORM + PostgresQL Boilerplate
License: MIT License
NestJS + GraphQL + TypeORM + PostgresQL Boilerplate
License: MIT License
Hello @Ho-s
Thanks for this awesome boilerplate.
Unfortunately i've got some error > Error with Body must be a string. Received: undefined.
Clone this repo and install package with yarn install
(node > 14)
Run postgres with docker docker run -p 5432:5432 --name postgres -e POSTGRES_PASSWORD=1q2w3e4r -d postgres
.development.env
.development.env
DB_HOST = localhost
DB_PORT = 5432
DB_USER = postgres
DB_PASSWORD = 1q2w3e4r
DB_NAME = postgres
PORT = 3000
JWT_PRIVATE_KEY="-----BEGIN RSA PRIVATE KEY-----
MIIJKgIBAAKCAgEA3F65WsAW2eI4qnrzEu/KoYq1Bn/zJRpEsBkQIz0g/sKhNJ0D
4pLfEIF6ZJGFFI9NJNoSoIrg7SfjhvHNhP6AFsa3QNjkMrOCC2d/6xW8oFcsS++1
MqJEsn5TJSm98rNvXpPT/DGFdUxE7cmoCL0klwzt+xk7eBRDUWhE3Z+1TBmVYEkO
9oFVdCyXOwsEDlzsbuccxfrgwmf2WZne4Ecnoy5i1nJci1TPDRgqOA9IrGncIdHI
j80Fope3x3W42nKY8SBoI3HqSTQ08j7Ci7gqxeBC5x6b847iWjqN7G978oPiD9PG
7dEd8IWkrfjt1ru2NDcPO8reRHt1EUEyrMg2epVi5uGpKoC4QouRVI+EeaA+zV9Q
/wwwMOyNlaJJxZXWGPaDJSMID1uTqAdyjUL5R0vk0TiBIGFxavxtBmJpdZhS9APs
1vPPRDq/O6A+ZqnlwafaEJspQSn58xkiHWS3ivOANlQuUMtnxoa+qeV8TxBGWNaK
lisdRl2vIChMp5zLdArp/N4qm41Nsvfie7Nlq5MFC/hS8JZuRewj1W1KR2D8anLf
KD93Uf5Zml9FLUnwg7r67XNdwYwDb7BSLUdZhJCavbqbnEPnnXtPoxJ/IfCiIbJ2
U6o7Rvbai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r67XNdwYwDb7BSLUdZ
hJCavbqbnEPnnXtPoxJ/IfCiIbJ2U6o7Rvbai0gnLx1kGkBxK67+kyhYl4/QsAE7
FF4BGAetAZ5OuqhefWlYcLsCAwEAAQ==
-----END PUBLIC KEY-----"
Run yarn dev
make mutation with playground
mutation Mutation($input: SignUpInput!) {
signUp(input: $input) {
jwt
user {
username
createdAt
updatedAt
}
}
}
{
"input": {
"nickname": "123",
"password": "123",
"username": "123"
}
}
And i got this error
Error with Body must be a string. Received: undefined.
In auth.service.ts - signUp
i tired to debug with console.log
async signUp(input: SignUpInput): Promise<JwtWithUser> {
console.log(input);
const doesExistId = await this.userService.getOne({
where: { username: input.username },
});
if (doesExistId) {
throw new BadRequestException('Username already exists');
}
console.log('hi');
const user = await this.userService.create(input);
return this.signIn(user);
}
SignUpInput { nickname: '123', password: '123', username: '123' }
[Nest] 67970 - 11/14/2023, 4:56:13 PM ERROR [ExceptionsHandler] Body must be a string. Received: undefined.
user.service.ts
tried to console.log query and it says undefinedgetOne(qs: OneRepoQuery<User>, query?: string) {
console.log(qs, query);
return this.userRepository.getOne(qs, query);
}
{ where: { username: '123' } } undefined
async signUp(input: SignUpInput): Promise<JwtWithUser> {
console.log(input);
// const doesExistId = await this.userService.getOne({
// where: { username: input.username },
// });
// console.log('hi1');
// if (doesExistId) {
// throw new BadRequestException('Username already exists');
// }
const user = await this.userService.create(input);
return this.signIn(user);
}
the error might be belongs to custom CRUD
Can i get any helps for this ? ๐ง
Hi, Are you sore that the where operators are correct?
I noticed that GetManyInput
does not have a relations
key, and it doesn't seem like there is an automatic way (or manual way) to specify which relations should load, so they are being returned as null
when requested through queries. Is this something that is to be implemented?
Hello - was trying this and while make a call to the qql endpoint for getoneuser and getme -> the getone method fails as query is undefined. I have added jwt token in header. It calls validate method but the query is undefined.
query GetMe {
getMe {
nickname
id
username
}
}
{
"errors": [
{
"message": "Error",
"path": [
"getMe"
],
"locations": [
{
"line": 2,
"column": 3
}
],
"extensions": {
"__orginal": {
"code": "UNAUTHENTICATED",
"stacktrace": [
"UnauthorizedException: Error",
" at JwtStrategy.validate (C:\D-drive\PropertyGuru\exp\NestJS-GraphQL-TypeORM-PostgresQL-main\src\auth\strategies\jwt.strategy.ts:27:13)",
" at processTicksAndRejections (node:internal/process/task_queues:96:5)",
" at JwtStrategy.callback [as _verify] (C:\D-drive\PropertyGuru\exp\NestJS-GraphQL-TypeORM-PostgresQL-main\node_modules\@nestjs\passport\dist\passport\passport.strategy.js:11:44)"
],
"originalError": {
"message": "Error",
"error": "Body must be a string. Received: undefined.",
"statusCode": 401
}
},
"code": "UNAUTHENTICATED",
"message": "Error"
}
}
],
"data": null
}
Hello friend. Good work on this repo. I am facing an issue and would like to know your thoughts.
Let's say I have below class:
@ObjectType()
@Entity()
export class User {
@Field(() => ID)
@PrimaryGeneratedColumn('uuid')
id: string;
@Field(() => String)
@Column()
username: string;
@Column()
yearOfBirth: number;
@Field(() => Number)
age: number;
}
When I create new users, I store their year of birth in database, but clients can query user's age directly (which I calculate it in graphql resolver before returning the response to the client). However this doesn't work with your setup since your code iterates through every field and transforms it into Select query before executing it into the DB.
When I run below query:
query User($input: GetOneInput!) {
user(input: $input) {
id
username
age
}
}
I get below error:
"message": "Property "age" was not found in "User". Make sure your query is correct."
How would you approach this?
Thank you in advance.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.