-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathhello1.js
More file actions
47 lines (41 loc) · 1.1 KB
/
hello1.js
File metadata and controls
47 lines (41 loc) · 1.1 KB
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
var express = require('express');
var graphqlHTTP = require('express-graphql');
var { buildSchema } = require('graphql');
var schema = buildSchema(`
type Query {
hello: String
persons(name: String, age: Int): [Person]
}
type Person {
name: String
age: Int
}
`);
var root = {
hello: () => 'Hello world!',
persons: (args, context, info) => {
console.log(context);
console.log(args);
const {name, age} = args;
return [
{name:"kim", age: 20},
{name:"lee", age: 30},
{name:"park", age: 40},
].filter((person) => {
if(!name && !age){ return true; }
if(!age && name && person.name === name){ return true; }
if(!name && age && person.age === age){ return true; }
if(name && age && person.name === name && person.age === age){ return true; }
return false;
});
}
};
var app = express();
const session = {id: "1001", expires: 20000};
app.use('/graphql', graphqlHTTP({
schema: schema,
rootValue: root,
context: session,
graphiql: true,
}));
app.listen(4000, () => console.log('Now browse to localhost:4000/graphql'));