The Guild LogoThe Guild Monogram

Search docs

Search icon

Products by The Guild

Products

Hive logoHive blurred logo

Hive

Schema Registry for your GraphQL Workflows

Skip to main content

Custom Server

By default, GraphQL Mesh provides you an HTTP server. You can see the details in Mesh as Gateway page. However, you can replace GraphQL Mesh's default server implementation by a custom one.

How to do?#

The following example shows how to replace GraphQL Mesh's default server implementation with Apollo Server;

myServerHandler.js

const { ApolloServer } = require('apollo-server');
module.exports = async ({ getBuiltMesh, documents, logger }) => {
const { schema } = await getBuiltMesh();
const apolloServer = new ApolloServer({
schema,
context: ({ req }) => req,
playground: {
tabs: documents.map(({ location, rawSDL }) => ({
name: location,
endpoint: '/graphql',
query: rawSDL,
})),
},
});
const { url } = await apolloServer.listen(4000);
logger.info(`🚀 Server ready at ${url}`);
};

Then add the following line to your configuration file;

serve:
customServerHandler: ./myServerHandler.js

When you use custom server handler, you won't be able to use configuration options under serve!

Example#