GraphQL Mesh v0 documentation (superseded by v1): Learn how to filter your GraphQL schema elements with GraphQL Mesh filterSchema transform. Exclude deprecated entities and more!
The filterSchema transform allows you to specify which schema elements to include or exclude in
your mesh. You can include or exclude entire queries and mutations, place restrictions on which
types can appear in your calls or which fields can appear in specific types.
For example, you might want to exclude deprecated queries, mutations, and types from your schema so
that your integration is not affected when these entities are removed.
Installation
npm i @graphql-mesh/transform-filter-schema
yarn add @graphql-mesh/transform-filter-schema
pnpm add @graphql-mesh/transform-filter-schema
bun add @graphql-mesh/transform-filter-schema
How to use?
Add the following configuration to your Mesh config file:
.meshrc.yaml
transforms: - filterSchema: mode: bare | wrap filters: - Type.!User # <-- This will remove `User` type - Type.!{User, Post} # <-- This will remove `User` and `Post` types - Query.!admins # <-- This will remove field `admins` from `Query` type - Mutation.!{addUser, removeUser} # <-- This will remove fields `addUser` and `removeUser` from `Mutation` type - User.{id, username, name, age} # <-- This will remove all fields, from User type, except `id`, `username`, `name` and `age` - Query.user.id # <-- This will remove all args from field `user`, in Query type, except `id` only - Query.user.!name # <-- This will remove argument `name` from field `user`, in Query type - Query.user.{id, name} # <-- This will remove all args for field `user`, in Query type, except `id` and `name` - Query.user.!{id, name} # <-- This will remove args `id` and `name` from field `user`, in Query type - Query.*.id # <-- This will remove all args from all fields in Query type, except `id` only - Query.*.!name # <-- This will remove argument `name` from all fields in Query type - Query.*.{id, name} # <-- This will remove all args from all fields in Query type, except `id` and `name` - Query.*.!{id, name} # <-- This will remove args `id` and `name` from all fields in Query type
Example
Let’s assume you have the following schema:
type Query { me: User users: [User] user(id: ID, name: String): User admins: [User]}type Mutation { updateMyProfile(name: String, age: Int): User addUser(username: String, name: String, age: Int): User removeUser(id: ID): ID}type User { id: ID username: String password: String name: String age: Int ipAddress: String}type LooseType { foo: String bar: String}