Hey all ![]()
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 emissioncart-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) {
token
}
}
mutation SignupMutation($createOneCartData: CartCreateInput!) {
createOneCart(data: $createOneCartData) {
id
}
}
mutation AttachCartToUserMutation($attachCartToUserCartId: String!, $attachCartToUserUserId: String!) {
attachCartToUser(cartId: $attachCartToUserCartId, userId: $attachCartToUserUserId) {
id
}
}
Useful links
- federated-nexus-prisma-subgraph-template - I’ve created a template that you can clone and create your own implementations.
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.