This repository has been archived by the owner on Nov 20, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
56 lines (51 loc) · 1.58 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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
const { ApolloServer, gql } = require("apollo-server");
const fs = require("fs");
const accounts = require("./accounts.json");
const typeDefs = fs.readFileSync("schema.graphqls").toString();
const resolvers = {
Query: {
getAggregatedTransactions: (_, { accountIdentifier, transactionTypes }) => {
const account = accounts.find(
(account) => account.identifier === accountIdentifier
);
const findTransactionsByType = (transactionType) => ({
type: transactionType,
details: account.transactions.filter(
(transaction) => transaction.type === transactionType
),
});
const results = transactionTypes.map(findTransactionsByType);
return results;
},
getAccount: (_, { accountIdentifier }) =>
accounts.find((account) => account.identifier === accountIdentifier),
},
Account: {
__resolveType({ type }) {
switch (type) {
case "ACCOUNT_VARIANT_ONE":
return "AccountVariantOne";
case "ACCOUNT_VARIANT_TWO":
return "AccountVariantTwo";
}
return null;
},
},
Transaction: {
__resolveType({ type }) {
switch (type) {
case "TRANSACTION_VARIANT_ONE":
return "TransactionVariantOne";
case "TRANSACTION_VARIANT_TWO":
return "TransactionVariantTwo";
case "TRANSACTION_VARIANT_THREE":
return "TransactionVariantThree";
}
return null;
},
},
};
const server = new ApolloServer({ typeDefs, resolvers });
server.listen().then(({ url }) => {
console.log(`🚀 Server ready at ${url}`);
});