From fb023a5d4c5dcd5e070179b72c83015ccc916e2d Mon Sep 17 00:00:00 2001 From: Remy Korrelboom Date: Sat, 17 Nov 2018 11:50:31 +0100 Subject: [PATCH] feat(fastify) Update README's with fastify createHandler interface #626 --- README.md | 23 ++++++++++------------- packages/apollo-server-fastify/README.md | 22 +++++++++------------- 2 files changed, 19 insertions(+), 26 deletions(-) diff --git a/README.md b/README.md index 955eaf46fc8..803e976c9fc 100644 --- a/README.md +++ b/README.md @@ -86,6 +86,7 @@ Often times, Apollo Server needs to be run with a particular integration. To sta - `apollo-server-express` - `apollo-server-koa` - `apollo-server-hapi` +- `apollo-server-fastify` - `apollo-server-lambda` - `apollo-server-azure-functions` - `apollo-server-cloud-functions` @@ -239,23 +240,19 @@ new ApolloServer({ ```js const { ApolloServer, gql } = require('apollo-server-fastify'); -const fastify = require('fastify'); +const { typeDefs, resolvers } = require('./module'); -async function StartServer() { - const server = new ApolloServer({ typeDefs, resolvers }); - - const app = fastify(); - - await server.applyMiddleware({ - app, - }); +const server = new ApolloServer({ + typeDefs, + resolvers, +}); - await server.installSubscriptionHandlers(app.server); +const app = require('fastify')(); +(async function () { + app.register(await server.createHandler()); await app.listen(3000); -} - -StartServer().catch(error => console.log(error)); +})(); ``` ### AWS Lambda diff --git a/packages/apollo-server-fastify/README.md b/packages/apollo-server-fastify/README.md index 96e20270e59..230569ec2d3 100644 --- a/packages/apollo-server-fastify/README.md +++ b/packages/apollo-server-fastify/README.md @@ -15,23 +15,19 @@ npm install apollo-server-fastify ```js const { ApolloServer, gql } = require('apollo-server-fastify'); -const fastify = require('fastify'); +const { typeDefs, resolvers } = require('./module'); -async function StartServer() { - const server = new ApolloServer({ typeDefs, resolvers }); +const server = new ApolloServer({ + typeDefs, + resolvers, +}); - const app = fastify(); - - await server.createHandler({ - app, - }); - - await server.installSubscriptionHandlers(app.server); +const app = require('fastify')(); +(async function () { + app.register(await server.createHandler()); await app.listen(3000); -} - -StartServer().catch(error => console.log(error)); +})(); ``` ## Principles