-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathschema3.js
63 lines (55 loc) · 1.12 KB
/
schema3.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
const makeExecutableSchema = require('graphql-tools').makeExecutableSchema;
let users = [
{ name: 'justin', email: '[email protected]', age: '99' },
{ name: 'alex', email: '[email protected]', age: '99' }
]
const typeDefs = `
# A User account. It *may* return an:
# - \`name\`
# - or other stuff
type User {
name: String,
email: String
age: Int
posts: [Post]
}
input UserInput {
name: String!,
email: String
age: Int
}
type Post {
id: Int,
title: String
}
type Query {
serverStatus: String,
getUsers: [User],
getUser(name: String): User
}
`;
const resolvers = {
Query: {
serverStatus: (root, args, context) => {
return 'OK';
},
getUsers: (root, args, context) => {
return users
},
getUser: (root, args, context) => {
return users.find(u => u.name === args.name)
}
},
User: {
posts: (root, args, context) => {
return getPostsForUser(root)
}
}
};
function getPostsForUser(user) {
return [{ id: 1, title: 'blog 1 by ' + user.name }]
}
module.exports = makeExecutableSchema({
typeDefs,
resolvers,
});