-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
74 lines (71 loc) · 1.76 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
require('dotenv').load();
// const { useRedis, cacheWithKey } = require('./cache');
const { GraphQLServer, PubSub } = require('graphql-yoga');
const apexClient = require('./api/apexHttpClient');
const resolvers = {
Query: {
info: (root, { name, platform }) => {
// useRedis(args.name, () =>
return apexClient
.get(`/profile/${platform ? platform.value : 5}/${name}`)
.then(data => data.data);
}
// .then(cacheWithKey(args.name, 60000))
// )
},
ProfileType: {
metadata: parent => {
return { level: parent.metadata.level };
},
latestGames: parent => {
return parent.children.map(child => ({
id: child.id,
legendName: child.metadata.legend_name,
icon: child.metadata.icon,
bgImage: child.metadata.bgimage,
stats: child.stats
}));
}
},
Platform: {
PC: {
value: 5
},
XBOX: {
value: 1
},
PSN: {
value: 2
}
},
Stats: {
kills: parent => {
const kills = parent.filter(stat => stat.metadata.key === 'Kills');
return kills.length ? kills[0] : { value: -1, percentile: -1 };
}
},
Subscription: {
counter: {
subscribe: (parent, args, { pubsub }) => {
const channel = Math.random()
.toString(36)
.substring(2, 15); // random channel name
let count = 0;
setInterval(
() => pubsub.publish(channel, { counter: { count: count++ } }),
2000
);
return pubsub.asyncIterator(channel);
}
}
}
};
const pubsub = new PubSub();
const server = new GraphQLServer({
typeDefs: ['./src/schema.graphql'],
resolvers,
context: { pubsub }
});
server.start(() =>
console.log(`Server is running on http://localhost:4000 🤘`)
);