-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.js
64 lines (57 loc) · 1.06 KB
/
test.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
const express = require("express");
const graphqlHttp = require("express-graphql");
const app = express();
const { buildSchema } = require("graphql");
const schema = buildSchema(`
type Video {
id: ID
title: String
duration: Int
watched: Boolean
}
type Query {
video: Video
videos: [Video]
}
type Schema {
query: Query
}
`);
const videoA = {
id: "1",
title: "Create a GraphQL schema",
duration: 120,
watched: true
};
const videoB = {
id: "2",
title: "Ember.js CLI",
duration: 240,
watched: false
};
const videos = [videoA, videoB];
const resolvers = {
video: () => videoA,
videos: () => videos
};
const query = `
query {
videos {
id,
title
}
}
`;
// graphql(schema, query, resolvers)
// .then(result => {
// result;
// console.log(result.data.videos);
// })
// .catch(e => console.log(e));
app.use(
"/graphql",
graphqlHttp({ schema, graphiql: true, rootValue: resolvers })
);
app.listen(process.env.PORT || 3000, () =>
console.log("Example app listening on port 3000!")
);