On this page

Extend Transform (experimental)

GraphQL Mesh v0 documentation (superseded by v1): Improve your GraphQL schema with the extend transform in GraphQL Mesh. Extend schema with additional type definitions and resolvers.

extend transform allows you to extend the source’s schema directly on the source level. But this might cause inconsistency if the schema heavily relies on that schema’s existing structure. This transform can be used for the data sources that return fixed results.

For example, OpenAPI and JSON Schema handlers are good examples of this kind of source. In contrast, PostGraphile and GraphQL handlers don’t because they rely on their existing structure. The resolvers added by this transform access directly to root, args, and context of that schema, so you cannot use selectionSet (actually, you shouldn’t, because this is not a root level transform).

How to use?

Add the following configuration under the source configuration;

.meshrc.yaml
transforms:
  - extend:
      typeDefs: ./someTypeDefs.graphql
      resolvers: ./someResolvers.ts

You can extend the existing types in:

someTypeDefs.graphql
extend type User {
  fullName: String
}

And define resolvers for those types;

someResolvers.ts
module.exports = {
  User: {
    fullName: user => `${user.firstName} ${user.lastName}` // e.g. `user` is the raw result returned by your data source
  }
}

Config API Reference

  • typeDefs (type: Any)
  • resolvers (type: Any)