-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
37 lines (28 loc) · 1.41 KB
/
index.js
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
const { ApolloServer } = require("apollo-server"); // Import Apollo Server
const { importSchema } = require("graphql-import"); // Import graphql-import to load schema
const EtherDataSource = require("./datasource/ethDatasource"); // Import custom EtherDataSource
const typeDefs = importSchema("./schema.graphql"); // Load schema from file
require("dotenv").config(); // Load environment variables from .env file
const resolvers = {
Query: {
etherBalanceByAddress: (root, _args, { dataSources }) => // Resolver to get ether balance for an address
dataSources.ethDataSource.etherBalanceByAddress(),
totalSupplyOfEther: (root, _args, { dataSources }) => // Resolver to get total ether supply
dataSources.ethDataSource.totalSupplyOfEther(),
latestEthereumPrice: (root, _args, { dataSources }) => // Resolver to get latest ETH price
dataSources.ethDataSource.getLatestEthereumPrice(),
blockConfirmationTime: (root, _args, { dataSources }) => // Resolver to get average block confirmation time
dataSources.ethDataSource.getBlockConfirmationTime(),
},
};
const server = new ApolloServer({ // Create Apollo Server instance
typeDefs,
resolvers,
dataSources: () => ({
ethDataSource: new EtherDataSource(), // Pass EtherDataSource instance
}),
});
server.timeout = 0;
server.listen("9000").then(({ url }) => { // Start Apollo Server
console.log(`🚀 Server ready at ${url}`);
});