Open diegonc opened 4 years ago
Oh, I just read in typeorm docs it's an experimental feature yet. Maybe it's not as good idea as I thought.
Hey, thanks for the code sample. Do you want to put it in as a PR in the examples folder? Then it’s not “officially supported” but folks have the pattern handy.
Hey @diegonc . I'd still be interested in getting this represented in the examples folder if you're interested in adding it.
Hi, where should I put it? Do I just pick the next number and create a new folder?
Yeah, that works. I typically just copy the last folder, re-number the DB name, etc... and gut the model, service and resolver of what's not needed.
Sorry I cannot seem to make it work like it did at that time. Even my original project looks broken now. I cannot make Person and Group implement Party at the graphql schema.
Extending from Party doesn't add the implements clause and adding {api: {implements: Party}} to group or person gives an error (I suspect due to the circular dependencies):
$ warthog codegen
TypeError: Cannot read property 'type' of undefined
at /home/diegonc/dev/test/quasar/wireframe-api/node_modules/type-graphql/dist/schema/schema-generator.js:157:149
at Array.map (<anonymous>)
at interfaces (/home/diegonc/dev/test/quasar/wireframe-api/node_modules/type-graphql/dist/schema/schema-generator.js:157:59)
at resolveThunk (/home/diegonc/dev/test/quasar/wireframe-api/node_modules/graphql/type/definition.js:438:40)
at defineInterfaces (/home/diegonc/dev/test/quasar/wireframe-api/node_modules/graphql/type/definition.js:619:20)
at GraphQLObjectType.getInterfaces (/home/diegonc/dev/test/quasar/wireframe-api/node_modules/graphql/type/definition.js:587:31)
at typeMapReducer (/home/diegonc/dev/test/quasar/wireframe-api/node_modules/graphql/type/schema.js:276:28)
at typeMapReducer (/home/diegonc/dev/test/quasar/wireframe-api/node_modules/graphql/type/schema.js:286:20)
at typeMapReducer (/home/diegonc/dev/test/quasar/wireframe-api/node_modules/graphql/type/schema.js:286:20)
at Array.reduce (<anonymous>)
at new GraphQLSchema (/home/diegonc/dev/test/quasar/wireframe-api/node_modules/graphql/type/schema.js:145:28)
at Function.generateFromMetadataSync (/home/diegonc/dev/test/quasar/wireframe-api/node_modules/type-graphql/dist/schema/schema-generator.js:31:24)
at Function.<anonymous> (/home/diegonc/dev/test/quasar/wireframe-api/node_modules/type-graphql/dist/schema/schema-generator.js:16:33)
at Generator.next (<anonymous>)
at /home/diegonc/dev/test/quasar/wireframe-api/node_modules/tslib/tslib.js:115:75
at new Promise (<anonymous>)
Can you shoot me a link to your branch?
This is what I have so far:
https://github.com/diegonc/warthog/tree/t/single-table-inheritance
Note to self to see diff: https://github.com/goldcaddy77/warthog/compare/main...diegonc:t/single-table-inheritance
TypeORM has a mode in which entities in a tree may share the same table as it's ancestor. It goes something like in the following snippets:
Class party can already be implemented by just using the TableInheritance decorator from TypeORM along with Model from warthog.
Child classes however cannot be added as warthog's Model decorator uses Entity. So, I came up with a custom decorator sitting in my code tree which I called ChildModel and is shown below.
Maybe it's a good idea to add the decorator to warthog's source tree :-)