Splitting schema into multiple crates #1630
Unanswered
MatteoJoliveau
asked this question in
Q&A
Replies: 2 comments
-
Got the same need here building a schema from multiple crates. @MatteoJoliveau Have you found a way? |
Beta Was this translation helpful? Give feedback.
0 replies
-
Just ran into this and also could not figure out a way on my own as well 😅 |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hi all!
TL;DR: is there a way to split a single schema into multiple crates without having to resort to making completely different applications and federating them?
Longer explanation: In our project, we're trying to divide the codebase into multiple independent crates so that each encapsulates an entire business context, supplying all related entities, use cases, interfaces and implementations such as DB repositories, etc.
For instance, we would have a
users
crate providing the mainUser
entity, aUserRepository
interface with itsPostgresUserRepository
concrete implementation, aUserService
that provides the variouscreate()
,change_name()
,follow()
business logic functions, etc...Then we'd also have a
posts
crate withPost
,PostRepository
and yadda yadda.The two crates are related (a Post has a creator that is a User, a User owns multiple Posts) but not strictly dependent as the link between the two entities is simply an
ID
.We would love for each crate to also provide
async-graphql
Objects to contribute to the application schema, but I'm having trouble representing the relationship between the two without importing each other's types (which we can't do because of the cyclic dependency rule of Rust crates).My goal is to be able to represent this query:
Each crate would provide its own root Query object, that is then passed to the schema via a merged object:
I tried to make a struct in
posts
calledUser
with just an ID field and marking it with#[graphql(extends)]
, but it doesn't seem to work as I think that's only for GQL Federation support.If I try to run the application I get this error:
users::User and posts::User have the same GraphQL name User
So my question is: is there a way to split a single schema into multiple crates without having to resort to making completely different applications and federating them?
Beta Was this translation helpful? Give feedback.
All reactions