• Docs
  • Transforms
  • Hoist

Hoist Field Transform

The hoist transform allows you to lift a field from one object type to a 'parent' root or object type. It is currently only available as a wrap transform.

yarn add @graphql-mesh/transform-hoist-field
💡
Underneath it leverages the HoistField transform from the @graphql-tools/wrap package.

How to use?

Given the following schema:

type Query {
  users(limit: Int!, page: Int): UserSearchResult
}
 
type UserSearchResult {
  page: Int!
  results: [User!]!
}
 
type User {
  id: ID!
}

Simple hoisting

transforms:
  - hoist-field:
      - typeName: Query
        pathConfig:
          - users
          - results
        newFieldName: users

Will transform the given schema to:

type Query {
  users(limit: Int!, page: Int): [User!]!
}
 
type User {
  id: ID!
}

Filtering args via a default for the entire path

transforms:
  - hoist-field:
      - typeName: Query
        pathConfig:
          - users
          - results
        newFieldName: users
        filterArgsInPath: true # This flag sets the default for the entire path

Will transform the given schema to:

type Query {
  users: [User!]!
}
 
type User {
  id: ID!
}

Filtering args via on specific levels of the path

transforms:
  - hoist-field:
      - typeName: Query
        pathConfig:
          - fieldName: users
            filterArgs:
              - limit
          - results
        newFieldName: users

Will transform the given schema to:

type Query {
  users(page: Int): [User!]!
}
 
type User {
  id: ID!
}

Config API Reference

  • typeName (type: String, required) - Type name that defines where field should be hoisted to
  • pathConfig - - Array of fieldsNames to reach the field to be hoisted (required) Array of:
    • String
    • object:
      • fieldName (type: String, required) - Field name
      • filterArgs (type: Array of String, required) - Match fields based on argument, needs to implement (arg: GraphQLArgument) => boolean;
  • newFieldName (type: String, required) - Name the hoisted field should have when hoisted to the type specified in typeName
  • alias (type: String)
  • filterArgsInPath (type: Boolean) - Defines if args in path are filtered (default = false)
Last updated on July 27, 2022