Skip to content
This repository has been archived by the owner on Apr 17, 2023. It is now read-only.

fix(fastify-template): switching to apollo-server-fastify #2256

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion templates/ts-fastify-mongodb-backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
"graphql-config": "3.2.0",
"graphql-subscriptions": "1.1.0",
"graphql-tag": "2.11.0",
"mercurius": "6.5.0",
"mongodb": "3.6.3"
},
"devDependencies": {
Expand Down
23 changes: 8 additions & 15 deletions templates/ts-fastify-mongodb-backend/src/index.ts
Original file line number Diff line number Diff line change
@@ -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';

Expand Down Expand Up @@ -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`);
});
}

Expand Down