On this page

How to: Customize the Mesh server

GraphQL Mesh v0 documentation (superseded by v1): Learn how to customize your Mesh server with GraphQL Yoga and Envelop, and take advantage of out-of-the-box features such as persisted queries, live queries, files upload, and serverless deployment. Configure or replace the server implementation with plugins and a standalone solution.

GraphQL Mesh provides a reliable and production-ready server implementation built with GraphQL Yoga and Envelop with, out of the box support for:

  • Persisted queries
  • Live queries
  • Files upload
  • Serverless deployment
  • and more…

GraphQL Mesh Gateway

Mesh server

Unified Schema

Sources

Envelop plugins

Books REST API GraphQL Schema

Apply transforms

Authors gRPC API GraphQL Schema

Stores GraphQL API GraphQL Schema

Merged GraphQL Schema

Unified Schema

Yoga GraphQL Server

Customizing your GraphQL Mesh Gateway server can be achieved in 2 ways:

  • Configure and provide Envelop plugins: to add behaviors such as caching, authentication, tracing to your Gateway
  • Provide a standalone server implementation: to completely replace the server used by the Gateway

Configure and provide plugins

Aided by the capabilities of Envelop, you can easily add plugins that helps with security and authentication, advanced caching, error handling, monitoring, logging and much more.

For full list of available plugins, please refer to the plugins section.

Configuration: serve reference

  • fork - - Spawn multiple server instances as node clusters (default: 1) One of:
    • Int
    • Boolean
  • port - - TCP Port to listen (default: 4000) One of:
    • Int
    • String
  • hostname (type: String) - The binding hostname (default: localhost)
  • cors (type: Object) - Configuration for CORS:
    • origin (type: Any)
    • allowedHeaders (type: Array of String)
    • exposedHeaders (type: Array of String)
    • credentials (type: Boolean)
    • maxAge (type: Int)
    • preflightContinue (type: Boolean)
    • optionsSuccessStatus (type: Int)
  • staticFiles (type: String) - Path to your static files you want to be served with GraphQL Mesh HTTP Server
  • playground - - Show GraphiQL Playground.

Pass true or false to toggle GraphiQL. Pass an object (playground.offline: true) to enable GraphiQL with assets bundled inline for air-gapped environments. One of:

  • Boolean
  • object:
    • offline (type: Boolean) - Use an offline GraphiQL that bundles JS, CSS and fonts inline instead of loading them from a CDN. Useful for air-gapped or on-premise environments with no internet access.

Requires @graphql-yoga/render-graphiql in the same project (install it yourself; mesh serve and generated createBuiltMeshHTTPHandler artifacts import it directly).

  • sslCredentials (type: Object) - SSL Credentials for HTTPS Server If this is provided, Mesh will be served via HTTPS:
    • key (type: String, required)
    • cert (type: String, required)
  • endpoint (type: String) - Path to GraphQL Endpoint (default: /graphql)
  • browser - - Path to the browser that will be used by mesh serve to open a playground window in development mode This feature can be disabled by passing false One of:
    • String
    • Boolean
  • playgroundTitle (type: String) - Title of GraphiQL Playground
  • batchingLimit (type: Int) - Enable and define a limit for Request Batching
  • healthCheckEndpoint (type: String) - Endpoint for Health Check
  • extraParamNames (type: Array of String) - By default, GraphQL Mesh does not allow parameters in the request body except query, variables, extensions, and operationName.

This option allows you to specify additional parameters that are allowed in the request body.

@default []

@example [‘doc_id’, ‘id’]

Provide a standalone server implementation

Creation of own server with Mesh Gateway and its deployment is described in Deploy a Mesh Gateway