The 'parent' element is declared, but its value is never read.
Closed this issue · 1 comments
Dear Ben Awad,
I'm also trying the code in your second lesson (register resolver TypeGraphql) and I went in two different issues.
One I solved, the other not yet.
Solved: createConnection() in typeorm is deprecated so I removed the ormconfig.json file and inserted in index.ts the following code:
import { DataSource } from "typeorm"
export const AppDataSource = new DataSource({
type: "postgres",
host: "localhost",
port: 5432,
username: "postgres",
password: "test",
database: "nodedemo",
synchronize: true,
logging: true,
entities: ["src/entity/."],
subscribers: [],
migrations: [],
})
and therefore the following to initialize the connection
const main = async () => {
await AppDataSource.initialize()
.then(() => {
// here you can start to work with your database
})
.catch((error) => console.log(error))
(....etc)
Everything is good. Query and mutation are working fine with the db but if I have still a problem with the variable 'name' as I get the following error "The 'parent' element is declared, but its value is never read.
I used your code so that I have in Register.ts
@resolver(User)
export class RegisterResolver {
@query(() => String)
async helloWorld() {
return "Hello World!";
}
@FieldResolver()
async name(@root() parent: User) {
return '${parent.firstName} ${parent.lastName}';
}
(...etc...)
and in User.ts
@ObjectType()
@entity()
export class User extends BaseEntity {
@field(() => ID)
@PrimaryGeneratedColumn()
id: number
@Field()
@Column()
firstName: string
@Field()
@Column()
lastName: string
@Field()
@Column("text", {unique: true})
email: string
@Field()
name: string;
@Column()
password: string
}
Solved!
I was using ' ' and/or " " instead of using backtick, a symbol that is not available in the italian keyboard.