v1
Transforms
Filter Schema

Filter Schema Transform

The filter schema 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.

How to use?

In the configuration, you can use regular function to filter the specific types, fields and arguments.

mesh.config.ts
import {
  createFilterTransform,
  defineConfig,
  loadGraphQLHTTPSubgraph
} from '@graphql-mesh/compose-cli'
 
export const composeConfig = defineConfig({
  subgraphs: [
    {
      sourceHandler: loadGraphQLHTTPSubgraph('Countries', {
        endpoint: 'https://countries.trevorblades.com'
      }),
      transforms: [
        createFilterTransform({
          rootFieldFilter(typeName, fieldName) {
            if (typeName === 'Query' && fieldName === 'countries') {
              return false
            }
            return true
          },
          typeFilter(typeName) {
            if (typeName === 'Country') {
              return false
            }
            return true
          },
          fieldFilter(typeName, fieldName) {
            if (typeName === 'Country' && fieldName === 'name') {
              return false
            }
            return true
          },
          argumentFilter(typeName, fieldName, argName) {
            if (typeName === 'Country' && fieldName === 'name' && argName === 'lang') {
              return false
            }
            return true
          }
        })
      ]
    }
  ]
})