File tree Expand file tree Collapse file tree 2 files changed +30
-30
lines changed Expand file tree Collapse file tree 2 files changed +30
-30
lines changed Original file line number Diff line number Diff line change @@ -225,17 +225,17 @@ const schema = gql`
225
225
}
226
226
type Student {
227
227
id : ID !
228
- text : String !
228
+ name : String !
229
229
teacher : Teacher !
230
230
}
231
231
` ;
232
232
233
233
const resolvers = {
234
234
Student: {
235
235
teacher : student => {
236
- return teachers[student .id ];
237
- },
238
- },
236
+ return teachers[student .teacherId ];
237
+ }
238
+ }
239
239
};
240
240
```
241
241
Original file line number Diff line number Diff line change @@ -6,7 +6,7 @@ const app = express();
6
6
7
7
app . use ( cors ( ) ) ;
8
8
9
- const students = {
9
+ const teachers = {
10
10
1 : {
11
11
id : "1" ,
12
12
name : "Aria"
@@ -17,35 +17,35 @@ const students = {
17
17
}
18
18
} ;
19
19
20
- let messages = {
20
+ let students = {
21
21
1 : {
22
22
id : "1" ,
23
- text : "Hello World " ,
24
- studentId : "1"
23
+ name : "Annika " ,
24
+ teacherId : "1"
25
25
} ,
26
26
2 : {
27
27
id : "2" ,
28
- text : "By World " ,
29
- studentId : "2"
28
+ name : "Cammie " ,
29
+ teacherId : "2"
30
30
}
31
31
} ;
32
32
33
33
const schema = gql `
34
34
type Query {
35
- me: Student
36
- student (id: ID!): Student
37
- students : [Student !]
38
- messages : [Message !]!
39
- message (id: ID!): Message !
35
+ me: Teacher
36
+ teacher (id: ID!): Teacher
37
+ teachers : [Teacher !]
38
+ students : [Student !]!
39
+ student (id: ID!): Student !
40
40
}
41
- type Student {
41
+ type Teacher {
42
42
id: ID!
43
43
name: String!
44
44
}
45
- type Message {
45
+ type Student {
46
46
id: ID!
47
- text : String!
48
- student: Student !
47
+ name : String!
48
+ teacher: Teacher !
49
49
}
50
50
` ;
51
51
@@ -54,22 +54,22 @@ const resolvers = {
54
54
me : ( parent , args , { me } ) => {
55
55
return me ;
56
56
} ,
57
- student : ( parents , { id } ) => {
58
- return students [ id ] ;
57
+ teacher : ( parents , { id } ) => {
58
+ return teachers [ id ] ;
59
+ } ,
60
+ teachers : ( ) => {
61
+ return Object . values ( teachers ) ;
59
62
} ,
60
63
students : ( ) => {
61
64
return Object . values ( students ) ;
62
65
} ,
63
- messages : ( ) => {
64
- return Object . values ( messages ) ;
65
- } ,
66
- message : ( parent , { id } ) => {
67
- return messages [ id ] ;
66
+ student : ( parent , { id } ) => {
67
+ return students [ id ] ;
68
68
}
69
69
} ,
70
- Message : {
71
- student : message => {
72
- return students [ message . studentId ] ;
70
+ Student : {
71
+ teacher : student => {
72
+ return teachers [ student . teacherId ] ;
73
73
}
74
74
}
75
75
} ;
@@ -78,7 +78,7 @@ const server = new ApolloServer({
78
78
typeDefs : schema ,
79
79
resolvers,
80
80
context : {
81
- me : students [ 1 ]
81
+ me : teachers [ 1 ]
82
82
}
83
83
} ) ;
84
84
You can’t perform that action at this time.
0 commit comments