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.
npm i @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
.meshrc.yaml
transforms:
- hoist-field:
- typeName: Query
pathConfig:
- users
- results
newFieldName: usersWill 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
.meshrc.yaml
transforms:
- hoist-field:
- typeName: Query
pathConfig:
- users
- results
newFieldName: users
filterArgsInPath: true # This flag sets the default for the entire pathWill transform the given schema to:
type Query {
users: [User!]!
}
type User {
id: ID!
}Filtering args on specific levels of the path
.meshrc.yaml
transforms:
- hoist-field:
- typeName: Query
pathConfig:
- fieldName: users
filterArgs:
- limit
- results
newFieldName: usersWill 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 topathConfig- - Array of fieldsNames to reach the field to be hoisted (required) Array of:Stringobject:fieldName(type:String, required) - Field namefilterArgs(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 typeNamealias(type:String)filterArgsInPath(type:Boolean) - Defines if args in path are filtered (default = false)