Can subgraphs access data from other subgraphs?

Hey all :wave:

At the moment I’m creating a greenfield project and we chose to go with micro-services on GraphQL.

The stack
A little context, we’re using Prisma as the ORM and Nexus JS for the declarative, code-first GraphQL schemas for TypeScript support.

Business context
I’ve managed to have a working (non-managed for the time being) @apollo/gateway with some federated sub-graphs (using prisma and nexus).

At the moment I’ve created two services:

  • identity-service - handles the user logic, authentication, sign-up’s, jwt tokens emission
  • cart-service - holds the user’s cart data.

State of the art
When I create a user, then, create a cart with the previously created user (providing the userId), on the gateway level I can see the the user.cart.{id, userId}.

The issue
On the identity-service, I have a signup Mutation which creates a User with all user specific data : name, email, password, .... Since identity-service has no visibility on what cart-service implementation is, I can’t attach a cart on the identity-service directly.

The user data model can live without a cartId associated and thats perfectly fine. The issue is, when, on the frontend, I submit a mutation, I would like the frontend to don’t care about this implementation details.

To signup a user I must run the following mutation

mutation SignupMutation($signupEmail: String!, $signupFirstName: String!, $signupLastName: String!, $signupPassword: String!) {
  signup(email: $signupEmail, firstName: $signupFirstName, lastName: $signupLastName, password: $signupPassword) {

mutation SignupMutation($createOneCartData: CartCreateInput!) {
  createOneCart(data: $createOneCartData) {

mutation AttachCartToUserMutation($attachCartToUserCartId: String!, $attachCartToUserUserId: String!) {
  attachCartToUser(cartId: $attachCartToUserCartId, userId: $attachCartToUserUserId) {

Useful links

If you’d like for me to share my repos with my implementations, I’d be glad to do so.

Thank you so much in advance.

Different subgraphs can reference things in other subgraphs via the extend type <name> @key(fields: "...") and @external directives.

This allows you to define a foreign key relationship between your entities in your API.

If you’re referring to federating a gateway into another gateway, I don’t believe that use case is supported right now.

@kevin-lindsay-1 If we want to pass same set of input arguments to nested resolvers across subgraph is @key the only way. Basically we want to pass a set of input arguments to referred services.

1 Like

Can you give an example?

i am also curious to know if this is possible… what is the best approach in passing multiple arguments across nested resolvers?