Last 12 weeks · 0 commits
1 of 6 standards met
I had time to brood about the previously mentioned idea in the PR #6 and i ended trying a possible solution. Although i think that it would be preferable to be implemented by type-graphql itself. Like in the others PR i sent, i just had time to put the query working and didn't worried with mutation and its parameters. And like before i will feign to not have seen the innumerable ts-ignore spread all over the place... The way it work is similar to the prototype code given in #6 Import the general functions for the resolvers and add them as a parameter to @autoQueries in entity. See the example in src\entity\Tomato.ts Seem to works as it is, but mutations need more work. And also, it may break if used with more than one entity :( Just a proof of concept or something in those lines. p.s. Sorry. just saw that i should have cleaned the git history Ok Done the squash
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 }
Repository: benawad/type-graphql-series. Description: Typescript GraphQL Server built with TypeGraphQL Stars: 322, Forks: 125. Primary language: TypeScript. Languages: TypeScript (99.7%), JavaScript (0.3%). Topics: graphql, postgresql, redis, typegraphql, typescript. Open PRs: 6, open issues: 6. Last activity: 4y ago. Community health: 28%. Top contributors: benawad, surtich, remusa.