Skip to content

Working with multiple schemas in the same project #886

Answered by Xetera
Xetera asked this question in Q&A
Discussion options

You must be logged in to vote

I was able to generate two separate schema outputs from the same codebase using a filtering technique like this that just filters out any object that starts with Private

import * as types from "./resolvers"

const publicTypes = Object.fromEntries(
  Object.entries(types).map(([key, value]) => {
    return [key, Object.fromEntries(
      Object.entries(value).filter(([name]) => !name.toLowerCase().startsWith("private"))
    )]
  })
)

export const schema = makeSchema({
  // ...
  types: publicTypes,
});

export const privateSchema = makeSchema({
  // ...
  types,
});

Inside your resolvers you can declare additional queries/mutations without exposing them like such

// lib/resolvers/user.ts
i…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by Xetera
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant