benawad / type-graphql-series

Typescript GraphQL Server built with TypeGraphQL
326 stars 129 forks source link

Dynamic resolvers with Decorators in Entity #9

Closed paean99 closed 2 years ago

paean99 commented 5 years ago

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