-
Notifications
You must be signed in to change notification settings - Fork 12
/
ClassroomType.js
48 lines (47 loc) · 1.28 KB
/
ClassroomType.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
import BookshelfType from '../'
import SubjectType from './SubjectType'
import HomeworkType from './HomeworkType'
import StudentType from './StudentType'
import {
GraphQLInt,
GraphQLList,
GraphQLNonNull,
GraphQLObjectType,
} from 'graphql'
import {
connectionDefinitions,
connectionArgs
} from 'graphql-relay';
export default new GraphQLObjectType(BookshelfType({
name: 'Classroom',
description: 'Need I say more?',
fields: function() {return {
id: this.attr({
type: new GraphQLNonNull(GraphQLInt),
description: 'The id of the classroom.',
}),
subject: this.belongsTo({
type: SubjectType,
description: 'The subject of the classroom.',
}),
students: this.hasMany({
type: new GraphQLList(StudentType),
description: 'Students in the classroom.',
}),
homeworks: this.hasMany({
type: connectionDefinitions({nodeType: HomeworkType}).connectionType,
args: connectionArgs,
description: 'Homework submitted to the classroom (latest to oldest).',
resolve: (qb) => {
qb.orderBy('created_at', 'DESC');
}
}),
size: {
type: GraphQLInt,
description: 'How many students there are in the class.',
resolve: (model) => {
return model.studentCount();
},
}
}},
}));