Upgrade Apollo server to v3 (#229)

* Upgrade apollo server to v3 in eden-watcher

* Upgrade apollo server to v3 in other watchers and codegen

* Refactor common server code to util

* Pass express application object in the method to create server

* Remove unnecessary import
This commit is contained in:
prathamesh0
2022-11-16 11:14:54 +05:30
committed by GitHub
parent a52bdf64b1
commit 62c57d8005
39 changed files with 625 additions and 514 deletions
@@ -4,7 +4,7 @@
import assert from 'assert';
import debug from 'debug';
import { PubSub } from 'apollo-server-express';
import { PubSub } from 'graphql-subscriptions';
import { EthClient } from '@cerc-io/ipld-eth-client';
import {
@@ -7,7 +7,7 @@ import 'reflect-metadata';
import yargs from 'yargs';
import { hideBin } from 'yargs/helpers';
import debug from 'debug';
import { PubSub } from 'apollo-server-express';
import { PubSub } from 'graphql-subscriptions';
import { Config, getConfig, fillBlocks, JobQueue, DEFAULT_CONFIG_PATH, initClients } from '@cerc-io/util';
{{#if (subgraphPath)}}
@@ -7,7 +7,7 @@ import 'reflect-metadata';
import yargs from 'yargs';
import { hideBin } from 'yargs/helpers';
import debug from 'debug';
import { PubSub } from 'apollo-server-express';
import { PubSub } from 'graphql-subscriptions';
import fs from 'fs';
import path from 'path';
@@ -48,13 +48,13 @@
{{#if (subgraphPath)}}
"@cerc-io/graph-node": "^0.2.13",
{{/if}}
"apollo-server-express": "^2.25.0",
"apollo-type-bigint": "^0.1.3",
"debug": "^4.3.1",
"ethers": "^5.4.4",
"express": "^4.17.1",
"express": "^4.18.2",
"graphql": "^15.5.0",
"graphql-import-node": "^0.0.4",
"graphql-subscriptions": "^2.0.0",
"json-bigint": "^1.0.0",
"reflect-metadata": "^0.1.13",
"typeorm": "^0.2.32",
@@ -63,7 +63,7 @@
},
"devDependencies": {
"@ethersproject/abi": "^5.3.0",
"@types/express": "^4.17.11",
"@types/express": "^4.17.14",
"@types/yargs": "^17.0.0",
"@typescript-eslint/eslint-plugin": "^4.25.0",
"@typescript-eslint/parser": "^4.25.0",
@@ -7,14 +7,13 @@ import path from 'path';
import assert from 'assert';
import 'reflect-metadata';
import express, { Application } from 'express';
import { ApolloServer, PubSub } from 'apollo-server-express';
import { PubSub } from 'graphql-subscriptions';
import yargs from 'yargs';
import { hideBin } from 'yargs/helpers';
import debug from 'debug';
import 'graphql-import-node';
import { createServer } from 'http';
import { DEFAULT_CONFIG_PATH, getConfig, Config, JobQueue, KIND_ACTIVE, initClients, startGQLMetricsServer } from '@cerc-io/util';
import { DEFAULT_CONFIG_PATH, getConfig, Config, JobQueue, KIND_ACTIVE, initClients, startGQLMetricsServer, createAndStartServer } from '@cerc-io/util';
{{#if (subgraphPath)}}
import { GraphWatcher, Database as GraphDatabase } from '@cerc-io/graph-node';
{{/if}}
@@ -82,23 +81,11 @@ export const main = async (): Promise<any> => {
}
const resolvers = await createResolvers(indexer, eventWatcher);
const app: Application = express();
const typeDefs = fs.readFileSync(path.join(__dirname, 'schema.gql')).toString();
const server = new ApolloServer({
typeDefs,
resolvers
});
await server.start();
server.applyMiddleware({ app });
const httpServer = createServer(app);
server.installSubscriptionHandlers(httpServer);
httpServer.listen(port, host, () => {
log(`Server is listening on host ${host} port ${port}`);
});
// Create an Express app
const app: Application = express();
const server = createAndStartServer(app, typeDefs, resolvers, { host, port });
startGQLMetricsServer(config);