mirror of
https://github.com/cerc-io/watcher-ts
synced 2024-11-19 20:36:19 +00:00
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:
parent
a52bdf64b1
commit
62c57d8005
@ -32,10 +32,9 @@
|
||||
"@cerc-io/tracing-client": "^0.2.13",
|
||||
"@cerc-io/util": "^0.2.13",
|
||||
"@types/lodash": "^4.14.168",
|
||||
"apollo-server-express": "^2.25.0",
|
||||
"debug": "^4.3.1",
|
||||
"ethers": "^5.4.4",
|
||||
"express": "^4.17.1",
|
||||
"express": "^4.18.2",
|
||||
"graphql": "^15.5.0",
|
||||
"lodash": "^4.17.21",
|
||||
"reflect-metadata": "^0.1.13",
|
||||
@ -46,7 +45,7 @@
|
||||
"devDependencies": {
|
||||
"@ethersproject/abi": "^5.3.0",
|
||||
"@types/chai": "^4.2.19",
|
||||
"@types/express": "^4.17.11",
|
||||
"@types/express": "^4.17.14",
|
||||
"@types/mocha": "^8.2.2",
|
||||
"@types/yargs": "^17.0.0",
|
||||
"@typescript-eslint/eslint-plugin": "^4.25.0",
|
||||
|
@ -3,7 +3,7 @@
|
||||
//
|
||||
|
||||
import debug from 'debug';
|
||||
import { withFilter } from 'apollo-server-express';
|
||||
import { withFilter } from 'graphql-subscriptions';
|
||||
import { ethers } from 'ethers';
|
||||
|
||||
import { Indexer } from './indexer';
|
||||
|
@ -5,16 +5,15 @@
|
||||
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 { createServer } from 'http';
|
||||
|
||||
import { getCache } from '@cerc-io/cache';
|
||||
import { EthClient } from '@cerc-io/ipld-eth-client';
|
||||
import { TracingClient } from '@cerc-io/tracing-client';
|
||||
import { getConfig, JobQueue, DEFAULT_CONFIG_PATH } from '@cerc-io/util';
|
||||
import { getConfig, JobQueue, DEFAULT_CONFIG_PATH, createAndStartServer } from '@cerc-io/util';
|
||||
|
||||
import typeDefs from './schema';
|
||||
|
||||
@ -81,21 +80,9 @@ export const main = async (): Promise<any> => {
|
||||
|
||||
const resolvers = await createResolvers(indexer, txWatcher);
|
||||
|
||||
// Create an Express app
|
||||
const app: Application = express();
|
||||
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}`);
|
||||
});
|
||||
const server = createAndStartServer(app, typeDefs, resolvers, { host, port });
|
||||
|
||||
return { app, server };
|
||||
};
|
||||
|
@ -5,7 +5,7 @@
|
||||
import assert from 'assert';
|
||||
import debug from 'debug';
|
||||
import _ from 'lodash';
|
||||
import { PubSub } from 'apollo-server-express';
|
||||
import { PubSub } from 'graphql-subscriptions';
|
||||
|
||||
import { EthClient } from '@cerc-io/ipld-eth-client';
|
||||
import { JobQueue } from '@cerc-io/util';
|
||||
|
@ -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);
|
||||
|
||||
|
@ -44,14 +44,14 @@
|
||||
"@cerc-io/util": "^0.2.13",
|
||||
"@ethersproject/providers": "^5.4.4",
|
||||
"@ipld/dag-cbor": "^6.0.12",
|
||||
"apollo-server-express": "^2.25.0",
|
||||
"apollo-type-bigint": "^0.1.3",
|
||||
"debug": "^4.3.1",
|
||||
"decimal.js": "^10.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",
|
||||
@ -59,7 +59,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,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';
|
||||
|
||||
|
@ -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';
|
||||
import { GraphWatcher, Database as GraphDatabase } from '@cerc-io/graph-node';
|
||||
|
@ -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';
|
||||
import { GraphWatcher, Database as GraphDatabase } from '@cerc-io/graph-node';
|
||||
|
||||
import { createResolvers } from './resolvers';
|
||||
@ -76,23 +75,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);
|
||||
|
||||
|
@ -48,14 +48,14 @@
|
||||
"@cerc-io/util": "^0.2.13",
|
||||
"@ethersproject/providers": "^5.4.4",
|
||||
"@types/lodash": "^4.14.168",
|
||||
"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-request": "^3.4.0",
|
||||
"graphql-subscriptions": "^2.0.0",
|
||||
"json-bigint": "^1.0.0",
|
||||
"lodash": "^4.17.21",
|
||||
"reflect-metadata": "^0.1.13",
|
||||
@ -66,7 +66,7 @@
|
||||
"@ethersproject/abi": "^5.3.0",
|
||||
"@nomiclabs/hardhat-ethers": "^2.0.2",
|
||||
"@nomiclabs/hardhat-waffle": "^2.0.1",
|
||||
"@types/express": "^4.17.11",
|
||||
"@types/express": "^4.17.14",
|
||||
"@types/json-bigint": "^1.0.0",
|
||||
"@types/yargs": "^17.0.0",
|
||||
"@typescript-eslint/eslint-plugin": "^4.25.0",
|
||||
|
@ -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';
|
||||
|
||||
|
@ -5,14 +5,13 @@
|
||||
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 } from '@cerc-io/util';
|
||||
import { DEFAULT_CONFIG_PATH, getConfig, Config, JobQueue, KIND_ACTIVE, initClients, createAndStartServer } from '@cerc-io/util';
|
||||
|
||||
import typeDefs from './schema';
|
||||
|
||||
@ -69,21 +68,9 @@ export const main = async (): Promise<any> => {
|
||||
|
||||
const resolvers = process.env.MOCK ? await createMockResolvers() : await createResolvers(indexer, eventWatcher);
|
||||
|
||||
// Create an Express app
|
||||
const app: Application = express();
|
||||
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}`);
|
||||
});
|
||||
const server = createAndStartServer(app, typeDefs, resolvers, { host, port });
|
||||
|
||||
return { app, server };
|
||||
};
|
||||
|
@ -51,14 +51,14 @@
|
||||
"@cerc-io/util": "^0.2.13",
|
||||
"@ethersproject/providers": "^5.4.4",
|
||||
"@ipld/dag-cbor": "^6.0.12",
|
||||
"apollo-server-express": "^2.25.0",
|
||||
"apollo-type-bigint": "^0.1.3",
|
||||
"debug": "^4.3.1",
|
||||
"decimal.js": "^10.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",
|
||||
@ -68,7 +68,7 @@
|
||||
"@ethersproject/abi": "^5.3.0",
|
||||
"@nomiclabs/hardhat-ethers": "^2.0.2",
|
||||
"@nomiclabs/hardhat-waffle": "^2.0.1",
|
||||
"@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,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';
|
||||
|
||||
|
@ -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';
|
||||
|
||||
|
@ -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 } from '@cerc-io/util';
|
||||
import { DEFAULT_CONFIG_PATH, getConfig, Config, JobQueue, KIND_ACTIVE, initClients, createAndStartServer } from '@cerc-io/util';
|
||||
|
||||
import { createResolvers } from './resolvers';
|
||||
import { Indexer } from './indexer';
|
||||
@ -67,23 +66,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 });
|
||||
|
||||
return { app, server };
|
||||
};
|
||||
|
@ -45,14 +45,14 @@
|
||||
"@cerc-io/util": "^0.2.13",
|
||||
"@ethersproject/providers": "^5.4.4",
|
||||
"@ipld/dag-cbor": "^6.0.12",
|
||||
"apollo-server-express": "^2.25.0",
|
||||
"apollo-type-bigint": "^0.1.3",
|
||||
"debug": "^4.3.1",
|
||||
"decimal.js": "^10.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",
|
||||
"lodash": "^4.17.21",
|
||||
"multiformats": "^9.4.8",
|
||||
@ -62,7 +62,6 @@
|
||||
},
|
||||
"devDependencies": {
|
||||
"@ethersproject/abi": "^5.3.0",
|
||||
"@types/express": "^4.17.11",
|
||||
"@types/yargs": "^17.0.0",
|
||||
"@typescript-eslint/eslint-plugin": "^4.25.0",
|
||||
"@typescript-eslint/parser": "^4.25.0",
|
||||
|
@ -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';
|
||||
|
||||
|
@ -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';
|
||||
import { GraphWatcher, Database as GraphDatabase } from '@cerc-io/graph-node';
|
||||
|
@ -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 } from '@cerc-io/util';
|
||||
import { DEFAULT_CONFIG_PATH, getConfig, Config, JobQueue, KIND_ACTIVE, initClients, createAndStartServer } from '@cerc-io/util';
|
||||
import { GraphWatcher, Database as GraphDatabase } from '@cerc-io/graph-node';
|
||||
|
||||
import { createResolvers } from './resolvers';
|
||||
@ -76,23 +75,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 });
|
||||
|
||||
return { app, server };
|
||||
};
|
||||
|
@ -28,10 +28,10 @@
|
||||
"left-pad": "^1.3.0",
|
||||
"lodash": "^4.17.21",
|
||||
"subscriptions-transport-ws": "^0.9.19",
|
||||
"ws": "^7.4.6"
|
||||
"ws": "^8.11.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/ws": "^7.4.4",
|
||||
"@types/ws": "^8.5.3",
|
||||
"@typescript-eslint/eslint-plugin": "^4.25.0",
|
||||
"@typescript-eslint/parser": "^4.25.0",
|
||||
"eslint": "^7.27.0",
|
||||
|
@ -42,14 +42,14 @@
|
||||
"@cerc-io/util": "^0.2.13",
|
||||
"@ethersproject/providers": "^5.4.4",
|
||||
"@ipld/dag-cbor": "^6.0.12",
|
||||
"apollo-server-express": "^2.25.0",
|
||||
"apollo-type-bigint": "^0.1.3",
|
||||
"debug": "^4.3.1",
|
||||
"decimal.js": "^10.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",
|
||||
@ -57,7 +57,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,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';
|
||||
|
||||
|
@ -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';
|
||||
|
||||
|
@ -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';
|
||||
|
||||
import { createResolvers } from './resolvers';
|
||||
import { Indexer } from './indexer';
|
||||
@ -67,23 +66,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);
|
||||
|
||||
|
@ -18,3 +18,4 @@ export * from './src/index-block';
|
||||
export * from './src/metrics';
|
||||
export * from './src/gql-metrics';
|
||||
export * from './src/common';
|
||||
export * from './src/server';
|
||||
|
@ -5,26 +5,36 @@
|
||||
"license": "AGPL-3.0",
|
||||
"dependencies": {
|
||||
"@cerc-io/solidity-mapper": "^0.2.13",
|
||||
"@graphql-tools/schema": "^9.0.10",
|
||||
"@graphql-tools/utils": "^9.1.1",
|
||||
"apollo-server-core": "^3.11.1",
|
||||
"apollo-server-express": "^3.11.1",
|
||||
"debug": "^4.3.1",
|
||||
"decimal.js": "^10.3.1",
|
||||
"ethers": "^5.4.4",
|
||||
"express": "^4.18.2",
|
||||
"fs-extra": "^10.0.0",
|
||||
"graphql": "^15.5.0",
|
||||
"graphql-ws": "^5.11.2",
|
||||
"ipfs-http-client": "^56.0.3",
|
||||
"lodash": "^4.17.21",
|
||||
"multiformats": "^9.4.8",
|
||||
"pg": "^8.5.1",
|
||||
"pg-boss": "^6.1.0",
|
||||
"prom-client": "^14.0.1",
|
||||
"toml": "^3.0.0"
|
||||
"toml": "^3.0.0",
|
||||
"ws": "^8.11.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@cerc-io/cache": "^0.2.13",
|
||||
"@cerc-io/ipld-eth-client": "^0.2.13",
|
||||
"@types/express": "^4.17.14",
|
||||
"@types/fs-extra": "^9.0.11",
|
||||
"@types/pg": "^8.6.5",
|
||||
"@types/ws": "^8.5.3",
|
||||
"@typescript-eslint/eslint-plugin": "^4.25.0",
|
||||
"@typescript-eslint/parser": "^4.25.0",
|
||||
"apollo-server-express": "^2.25.0",
|
||||
"apollo-server-express": "^3.11.1",
|
||||
"decimal.js": "^10.3.1",
|
||||
"eslint": "^7.27.0",
|
||||
"eslint-config-semistandard": "^15.0.1",
|
||||
|
@ -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';
|
||||
|
||||
|
59
packages/util/src/server.ts
Normal file
59
packages/util/src/server.ts
Normal file
@ -0,0 +1,59 @@
|
||||
import { Application } from 'express';
|
||||
import { ApolloServer } from 'apollo-server-express';
|
||||
import { createServer } from 'http';
|
||||
import { WebSocketServer } from 'ws';
|
||||
import { useServer } from 'graphql-ws/lib/use/ws';
|
||||
import { ApolloServerPluginDrainHttpServer } from 'apollo-server-core';
|
||||
import debug from 'debug';
|
||||
|
||||
import { TypeSource } from '@graphql-tools/utils';
|
||||
import { makeExecutableSchema } from '@graphql-tools/schema';
|
||||
|
||||
const log = debug('vulcanize:server');
|
||||
|
||||
export const createAndStartServer = async (
|
||||
app: Application,
|
||||
typeDefs: TypeSource,
|
||||
resolvers: any,
|
||||
endPoint: { host: string, port: number }
|
||||
): Promise<ApolloServer> => {
|
||||
// Create HTTP server
|
||||
const httpServer = createServer(app);
|
||||
|
||||
// Create the schema
|
||||
const schema = makeExecutableSchema({ typeDefs, resolvers });
|
||||
|
||||
// Create our WebSocket server using the HTTP server we just set up.
|
||||
const wsServer = new WebSocketServer({
|
||||
server: httpServer,
|
||||
path: '/graphql'
|
||||
});
|
||||
const serverCleanup = useServer({ schema }, wsServer);
|
||||
|
||||
const server = new ApolloServer({
|
||||
schema,
|
||||
csrfPrevention: true,
|
||||
plugins: [
|
||||
// Proper shutdown for the HTTP server
|
||||
ApolloServerPluginDrainHttpServer({ httpServer }),
|
||||
// Proper shutdown for the WebSocket server
|
||||
{
|
||||
async serverWillStart () {
|
||||
return {
|
||||
async drainServer () {
|
||||
await serverCleanup.dispose();
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
]
|
||||
});
|
||||
await server.start();
|
||||
server.applyMiddleware({ app });
|
||||
|
||||
httpServer.listen(endPoint.port, endPoint.host, () => {
|
||||
log(`Server is listening on ${endPoint.host}:${endPoint.port}${server.graphqlPath}`);
|
||||
});
|
||||
|
||||
return server;
|
||||
};
|
Loading…
Reference in New Issue
Block a user