From 730d8b84ab94fe80dfe1b252695ee107ad04278e Mon Sep 17 00:00:00 2001 From: Arsh Sharma Date: Mon, 15 Feb 2021 20:58:27 +0530 Subject: [PATCH] chore(fastify-template): rebased --- .../ts-fastify-mongodb-backend/package.json | 7 +++--- .../ts-fastify-mongodb-backend/src/index.ts | 23 +++++++------------ 2 files changed, 11 insertions(+), 19 deletions(-) diff --git a/templates/ts-fastify-mongodb-backend/package.json b/templates/ts-fastify-mongodb-backend/package.json index d488f31c27..754fb0dc03 100644 --- a/templates/ts-fastify-mongodb-backend/package.json +++ b/templates/ts-fastify-mongodb-backend/package.json @@ -14,16 +14,15 @@ "license": "Apache 2.0", "dependencies": { "@graphback/runtime-mongo": "1.1.1", - "@graphql-tools/schema": "7.1.2", + "apollo-server-fastify": "2.21.0", "dotenv": "8.2.0", - "fastify": "3.9.2", - "fastify-cors": "4.1.0", + "fastify": "2.15.3", + "fastify-cors": "3.0.3", "graphback": "1.1.1", "graphql": "15.4.0", "graphql-config": "3.2.0", "graphql-subscriptions": "1.1.0", "graphql-tag": "2.11.0", - "mercurius": "6.5.0", "mongodb": "3.6.3" }, "devDependencies": { diff --git a/templates/ts-fastify-mongodb-backend/src/index.ts b/templates/ts-fastify-mongodb-backend/src/index.ts index 0fd5c43513..fab1f733f8 100644 --- a/templates/ts-fastify-mongodb-backend/src/index.ts +++ b/templates/ts-fastify-mongodb-backend/src/index.ts @@ -1,13 +1,12 @@ /* eslint-disable @typescript-eslint/no-var-requires */ // eslint-disable-next-line @typescript-eslint/no-require-imports require('dotenv').config(); -import mercurius from 'mercurius'; +import { ApolloServer } from 'apollo-server-fastify'; import { buildGraphbackAPI } from 'graphback'; import { createMongoDbProvider } from '@graphback/runtime-mongo'; import fastify from 'fastify'; import fastifyCors from 'fastify-cors'; import { loadConfigSync } from 'graphql-config'; -import { makeExecutableSchema } from '@graphql-tools/schema'; import { connectDB } from './db'; import { noteResolvers } from './resolvers/noteResolvers'; @@ -36,23 +35,17 @@ async function start() { dataProviderCreator: createMongoDbProvider(db) }); - const schema = makeExecutableSchema({ - typeDefs, resolvers: [ - resolvers, - noteResolvers - ] - }) - - app.register((mercurius as any), { - schema, - graphiql: true, - context: contextCreator, - subscription: true + const apolloServer = new ApolloServer({ + typeDefs, + resolvers: [resolvers, noteResolvers], + context: contextCreator }); + app.register(apolloServer.createHandler()); + apolloServer.installSubscriptionHandlers(app.server); + app.listen(4000, () => { console.log(`🚀 Server ready at http://localhost:4000/graphql`); - console.log(`🚀 GraphQL IDE ready at http://localhost:4000/graphiql`); }); }