Multiple Prisma Services in single Apollo server


#1

Hello! What is currently the best way to communicate with a secondary prisma service?

Scenario: I want to build multiple services and have them all use the same auth service. I want my public schema to hide the fact there are two services and present itself as a single service. Here is a mockup of my schema:

Here are my datamodels:

main service

type Post {
  text: String
  author: User!
}
type User {
  id: ID! @unique
  posts: [Post]
  accountId: ID! @unique
}

auth service

type Account {
  id: ID! @unique
  username: String!
  password: String!
}

public schema

type Query {
  posts: [Post]
}
type Post {
  text: String
  author: User!
}
type User {
  id: ID! @unique
  posts: [Post]
  accountId: ID! @unique
  account: Account!
}
type Account {
  id: ID! @unique
  username: String!
}

The man issue at the moment is generating the required prisma client or bindings. I can simply go to the secondary service and generate it from there, but that just gets messy. Is there a better way? Can I generate it from the primary project, maybe by connecting to the secondary one?


#2

I dont think currently there is a good way of doing this so please open a new feature request for this.

As a workaround, I will make two separate clients in two different folders like so:

Folder structure:

├── auth
│   ├── generated
│   │   └── prisma-client
│   ├── datamodel.prisma
│   ├── docker-compose.yml
│   └── prisma.yml
├── prisma
│   ├── generated
│   │   └── prisma-client
│   ├── datamodel.prisma
│   ├── docker-compose.yml
│   └── prisma.yml
└── index.js

Now you can use

const { prisma as authClient } = require('./auth/generated/prisma-client');
const { prisma } = require('./auth/generated/prisma-client');


// use it in you code now

If you have any proposal in mind that will help us quite a lot!


#3

The problem with the approach you propose is: what if I already have the auth service running? I want to keep the auth service in a separate repo. Here is a proposal for how this could be possible:

  • Allow specifying name/location of prisma.yml file when using cli
  • Make datamodel property of prisma.yml optional

Then I would run:

prisma -f ./auth/prisma.yml generate

to generate my client


#4

Looks nice, something that we can have in the future, please open a FR :pray:

For separate repo I think you can use git submodules right now


#5

For now I think I will fall back to graphql get-schema

Edit: which is the correct repository to open the FR?


#6

https://github.com/prisma/prisma :slight_smile:


#7

Done