Type-graphql: Dealing with nested schema

Created on 15 Apr 2019  路  6Comments  路  Source: MichalLytek/type-graphql

Hi! Firsr off, thank you for such a great library.

I really want to use this library for my project but I'm having trouble implementing this example in type-graphql:

https://gist.github.com/xpepermint/7376b8c67caa926e19d2

Basically if I have nested schema with Project schema having array of Member and each Member having array of Tickets, how can I get all Projects each with all Members and each Member with all Tickets?

I tried looking up nested resolvers in your issue list but couldn't find anything helpful.

Thank you in advance for any feedback!

Question Solved

Most helpful comment

Just in the same way:

  • create Project, Member and Ticket class types
  • then create ProjectResolver class with projects and project methods (@Query)
  • create in ProjectResolver class a @FieldResolver named members()
  • create MemberResolver class with a @FieldResolver named tickets()

https://typegraphql.ml/docs/resolvers.html

I'm not quite sure how the suggested solution would work? How would the ProjectResolver in that case be able to resolve the nested "members" and the deeper nested "tickets"? I get the concept of a single nested object since I could simply inject a service that would return the data of the subtype, but that would mean that the service would have to resolve the members (with a @FieldResolver) and the tickets for each of them at the same time for multi level nesting, correct? That's not what I want to have as it wouldn't easily allow me to filter the output appropriately on the nested levels. In my opinion inside the "ProjectResolver" the "MemberResolver" should resolve the members field whenever a field is found with the Member or [Member] return type and same for the "TicketResolver" whenever the Ticket or [Ticket] return type is found.

I work around that duplication of code by injecting the resolver for the field resolver in the constructor and using the according method from the injected resolver, however that doesn't really seem to be the appropriate approach... Any guidance on how to correctly solve this issue or some example code? @dltmd6262 How did you solve this?

All 6 comments

Just in the same way:

  • create Project, Member and Ticket class types
  • then create ProjectResolver class with projects and project methods (@Query)
  • create in ProjectResolver class a @FieldResolver named members()
  • create MemberResolver class with a @FieldResolver named tickets()

https://typegraphql.ml/docs/resolvers.html

Thank you for the response! I'll try it ASAP.

Closing for a housekeeping purposes 馃敀

Just in the same way:

  • create Project, Member and Ticket class types
  • then create ProjectResolver class with projects and project methods (@Query)
  • create in ProjectResolver class a @FieldResolver named members()
  • create MemberResolver class with a @FieldResolver named tickets()

https://typegraphql.ml/docs/resolvers.html

I'm not quite sure how the suggested solution would work? How would the ProjectResolver in that case be able to resolve the nested "members" and the deeper nested "tickets"? I get the concept of a single nested object since I could simply inject a service that would return the data of the subtype, but that would mean that the service would have to resolve the members (with a @FieldResolver) and the tickets for each of them at the same time for multi level nesting, correct? That's not what I want to have as it wouldn't easily allow me to filter the output appropriately on the nested levels. In my opinion inside the "ProjectResolver" the "MemberResolver" should resolve the members field whenever a field is found with the Member or [Member] return type and same for the "TicketResolver" whenever the Ticket or [Ticket] return type is found.

I work around that duplication of code by injecting the resolver for the field resolver in the constructor and using the according method from the injected resolver, however that doesn't really seem to be the appropriate approach... Any guidance on how to correctly solve this issue or some example code? @dltmd6262 How did you solve this?

Hey has anyone figured this out? I'd really appreciate if someone was able to share a solution to this.

I'm running into the same limitations as described by @pascalbayer

Would it be possible to re-open this issue until a clear solution to the above is described?

a clear solution to the above is described?

@gDelgado14
Please open a new issue with a clear problem description - what you want to achieve, how you solve this problem now and how would you like to solve this (API proposal/example) 馃槈

Was this page helpful?
0 / 5 - 0 ratings

Related issues

glentakahashi picture glentakahashi  路  3Comments

MichalLytek picture MichalLytek  路  3Comments

Janushan picture Janushan  路  3Comments

Tybot204 picture Tybot204  路  3Comments

MichalLytek picture MichalLytek  路  4Comments