forked from synapsecns/explorer-api
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
41 lines (35 loc) · 1.51 KB
/
Copy pathindex.js
File metadata and controls
41 lines (35 loc) · 1.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import 'dotenv/config'
import {ApolloServer} from "apollo-server"
import {ApolloServerPluginLandingPageGraphQLPlayground} from "apollo-server-core"
import {schema} from "./api/gql/schema.js"
import "./api/db/index.js"
import {bridgeTransactions} from "./api/controllers/bridgeTransactions.js"
import {latestBridgeTransactions} from "./api/controllers/latestBridgeTransactions.js"
import {bridgeAmountStatistic} from "./api/controllers/bridgeAmountStatistic.js";
import {countByChainId} from './api/controllers/countByChainId.js'
import {countByTokenAddress} from './api/controllers/countByTokenAddress.js'
import {addressRanking} from './api/controllers/addressRanking.js'
// This function will create a new server Apollo Server instance
export const createServer = async (options = { port: 4000 }) => {
const server = new ApolloServer({
typeDefs: schema,
resolvers: {
Query: {
bridgeTransactions,
latestBridgeTransactions,
bridgeAmountStatistic,
countByChainId,
countByTokenAddress,
addressRanking,
},
},
plugins: [
ApolloServerPluginLandingPageGraphQLPlayground({}),
]
})
const serverInfo = await server.listen(options);
console.log(`Running a GraphQL API server at localhost:${options.port}/graphql`)
// serverInfo is an object containing the server instance and the url the server is listening on
return serverInfo;
};
await createServer()