-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
103 lines (94 loc) · 1.89 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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
const express = require('express');
const graphqlHTTP = require('express-graphql');
const fetch = require('node-fetch');
const { buildSchema } = require('graphql');
const app = express();
const schema = buildSchema(`
type Comment {
id: String
text: String
created_time: String
from: User
}
type Comments {
data: [Comment]
count: Int
}
type Likes {
data: [User]
count: Int
}
type Image {
width: Int
height: Int
url: String
}
type ImageType {
thumbnail: Image
low_resolution: Image
standard_resolution: Image
}
type Caption {
id: String
text: String
created_time: String
from: User
}
type User {
id: String
full_name: String,
profile_picture: String,
username: String
}
type Item {
id: String,
code: String
user: User
images: ImageType
created_time: String
caption: Caption
likes: Likes
comments: Comments
can_view_comments: Boolean
can_delete_comments: Boolean
type: String
link: String
location: String
alt_media_url: String
}
type Feed {
items: [Item]
more_available: Boolean
status: String
}
type Query {
feed(username: String!): Feed
}
`);
const root = {
feed: async ({ username }) =>
fetch(`https://instagram.com/${username}/media`).then(res => res.json()),
};
app.get('/api/user/:username', (req, res) => {
const { username } = req.params;
fetch(`https://instagram.com/${username}/media`)
.then(data => data.json())
.then(json => res.json(json));
});
app.use(
'/graphql',
graphqlHTTP({
schema,
rootValue: root,
graphiql: true,
formatError: error => ({
message: error.message,
locations: error.locations,
stack: error.stack,
path: error.path,
}),
}),
);
app.listen(8080, () => {
console.log('Listening on port :8080/graphql'); // eslint-disable-line
});