-
-
Notifications
You must be signed in to change notification settings - Fork 672
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Typescript module and type-graphql dependency #69
Comments
There's no need to use TypeGraphQL in Angular App. To fetch data from GraphQL server you write dedicated GraphQL queries. Then you can use |
@fromnowhereuser Can you tell me for what do you use TypeGraphQL model definitions in your Angular app? |
Closing as |
@19majkel94 i dont need graphql form the angular project. But i want the class definitions. I use them a lot in the angular project. Angular Project ====== But it doesnt work. Do i did it wrong ? |
Seems like you don't have I would have to create a dummy decorators that could be used in browser, like TypeORM: |
i dont have any problem in my angular App. Again, i dont use typegraphql in my angular app, i just need the class. My problem is when i want to start the typegraphql project. If i define the annotated class in a lib, the app wont start: I'm really sorry if the explanation was not clear... |
Please create a repository with minimal example code that reproduce the issue, so I could run it and find where the problem is 😉 |
Here the sample project: Just go to models2 and go to back |
As I said:
This is the first issue with your repo - lease upgrade your dependencies version as you have mismatch between projects. Second, RTFM! Without After fixing you issues, the transpiled code looks like this: __decorate([
type_graphql_1.Field(type => type_graphql_1.ID),
__metadata("design:type", Number)
], XAItem.prototype, "id", void 0);
__decorate([
type_graphql_1.Field(),
__metadata("design:type", String)
], XAItem.prototype, "name", void 0);
__decorate([
type_graphql_1.Field(),
__metadata("design:type", String)
], XAItem.prototype, "desc", void 0);
XAItem = __decorate([
type_graphql_1.InterfaceType({ description: "" }),
__metadata("design:paramtypes", [])
], XAItem); Third, you can't mix interfaces and inheritance: @ObjectType({ implements: XAItem, description: "" })
export class User extends XAItem {} GraphQL has no support for extending in schema, so you can't express this kind of relation. You need to switch Also, you can't use classes as interfaces and have constructors defined: @InterfaceType({ description: "" })
export abstract class XAItem {
constructor() {
this.name = '';
this.id = 0;
this.desc = 'undef';
} The last error From my experience there's always too much problems from separating things to projects/modules than the benefits of this. I would recommend restructuring your app to don't need this.
The solution for coupling backend with frontend is GraphQL 😉 Use |
Wow..? that's a lot of error... Thank you very much for your support and time. I have business functions on my types. I am building a progressive app... Every derived class (from XaItem) has business functions. What do you think ? |
So seems you like OOP. But with this you are volatiling the single responsibility principle. Use TypeGraphQL types like a DTO classes. Move the logic to separate services or create adapters for converting model classes (business logic, db entity stuffs, etc.) to DTO and vice-versa. Don't use big, all-in-one classes with multiple interfaces and inheritance chains 😉 |
So, one class representing Data only. And interface for specific behavior ? Seems good to me. Did i get it ? |
Basically, yes 😉 I am closing this issue for now. |
I love your project. The approach seems to be very similar to the JAVA one. And i like that.
One domain model that make "one source of truth". Then i have splitted my TS class model definition in a specific node project (the library) to make it available from:
a type-graphql server
AND
an Angular app.
The library project AND the type-graphql server depend of type-graphql.
When i launch the server, i have something like that:
Error: Cannot determine type for MyType:attr
Am i doing it wrong ? Because... it seems that type-graphql is enable to see the transpiled anotation. Thank you for any help or advice you can provide.
The text was updated successfully, but these errors were encountered: