⚠️
This is the documentation for the old GraphQL Mesh version v0. We recommend upgrading to the latest GraphQL Mesh version v1.
Migrate to GraphQL Mesh v1
Migrate to GraphQL Mesh v1
Filter Schema Transform
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
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
}
With the following Filter Schema config:
.meshrc.yaml
transforms:
- filterSchema:
mode: bare | wrap
filters:
- Type.!LooseType
- Query.!admins
- Mutation.!{addUser, removeUser}
- User.{username, name, age}
- Query.user.!name
It would become the following schema:
type Query {
me: User
users: [User]
user(id: ID): User
}
type Mutation {
updateMyProfile(name: String, age: Int): User
}
type User {
username: String
name: String
age: Int
}
💡
For information about “bare” and “wrap” modes, please read the dedicated section.
Config API Reference
mode
(type:String (bare | wrap)
) - Specify to apply filter-schema transforms to bare schema or by wrapping original schemafilters
(type:Array of String
, required) - Array of filter rulesfilterDeprecatedTypes
(type:Boolean
) - Filter deprecated typesfilterDeprecatedFields
(type:Boolean
) - Filter deprecated fields