-
I'm currently looking for a way to separate the external and internal mutations on my API. Since nexus doesn't do JIT compiling of schemas based on permissions the way https://github.com/hasura/graphql-engine and https://graphql-ruby.org/authorization/visibility.html does, which allows hiding mutations and data types from users without the right permissions when introspecting, is it possible to conveniently generate 2 schemas from the same data source? If so, are there any examples I can look at? I haven't been able to find much on this topic unfortunately. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
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 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
import { objectType, mutationField } from "nexus";
export const User = objectType({
name: "User",
definition(t) {
t.model.name()
},
});
export const PrivateMutation = mutationField((t) => {
t.field("banUser", {
// ...
})
}) to split types into separate visibilities you can use export const PrivateUser = extendType({
type: "User",
definition(t) {
t.model.address()
},
}); From there you simply pass |
Beta Was this translation helpful? Give feedback.
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
Inside your resolvers you can declare additional queries/mutations without exposing them like such