-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathStudentType.js
44 lines (43 loc) · 1.1 KB
/
StudentType.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
import BookshelfType from '../'
import ClassroomType from './ClassroomType'
import HomeworkType from './HomeworkType'
import {
GraphQLInt,
GraphQLList,
GraphQLNonNull,
GraphQLObjectType,
GraphQLString,
} from 'graphql'
export default new GraphQLObjectType(BookshelfType({
name: 'Student',
description: 'A humble student.',
fields: (model) => ({
id: model.attr({
type: new GraphQLNonNull(GraphQLInt),
description: 'The id of the student.',
}),
name: model.attr({
type: GraphQLString,
description: 'The id of the student.',
}),
homeworks: model.hasMany({
type: new GraphQLList(HomeworkType),
description: 'All the homework the student has submitted.',
}),
classrooms: model.hasMany({
type: new GraphQLList(ClassroomType),
description: 'The classes the student is in.',
args: {
id: {
type: GraphQLInt,
description: 'Optional ID of a class.'
}
},
resolve: (qb, modelInstance, {id}) => {
if (id) {
qb.where({classroom_id: id});
}
}
})
}),
}));