Skip to content

Commit 5186f21

Browse files
authored
Merge pull request #40 from MEITREX/feature-assignments
Add assignment service to graphql
2 parents ff4af4a + e1ca5fc commit 5186f21

6 files changed

Lines changed: 153 additions & 15 deletions

File tree

.meshrc.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,12 @@ sources:
5656
endpoint: "{env.DOCPROCAI_SERVICE_URL}"
5757
operationHeaders:
5858
CurrentUser: "{context.currentUserJson}"
59+
- name: AssignmentService
60+
handler:
61+
graphql:
62+
endpoint: "{env.ASSIGNMENT_SERVICE_URL}"
63+
operationHeaders:
64+
CurrentUser: "{context.currentUserJson}"
5965
- name: GamificationService
6066
handler:
6167
graphql:
@@ -71,6 +77,7 @@ additionalTypeDefs:
7177
- "./additionalTypeDefs/flashcard.graphqls"
7278
- "./additionalTypeDefs/quiz.graphqls"
7379
- "./additionalTypeDefs/media.graphqls"
80+
- "./additionalTypeDefs/assignment.graphqls"
7481
additionalResolvers:
7582
- "./additionalResolvers/content.ts"
7683
- "./additionalResolvers/course.ts"

README.md

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -47,21 +47,23 @@ The `additionalResolvers` section defines code for custom GraphQL queries which
4747

4848
### Relevant for deployment
4949

50-
| Name | Description | Value in Dev Environment | Value in Prod Environment |
51-
|--------------------------|--------------------------------------|----------------------------------------------------------------------------|-----------------------------------------------------------------------|
52-
| GATEWAY_PORT | Gateway port | 8080 | 8080 |
53-
| GATEWAY_HOSTNAME | Gateway host name | 0.0.0.0 | 0.0.0.0 |
54-
| DAPR_HTTP_PORT | Dapr HTTP Port | - | 3500 |
55-
| COURSE_SERVICE_URL | URL for course service GraphQL | http://host.docker.internal:2001/graphql | http://localhost:3500/v1.0/invoke/course-service/method/graphql |
56-
| MEDIA_SERVICE_URL | URL for media service GraphQL | http://host.docker.internal:3001/graphql | http://localhost:3500/v1.0/invoke/media-service/method/graphql |
57-
| CONTENT_SERVICE_URL | URL for content service GraphQL | http://host.docker.internal:4001/graphql | http://localhost:3500/v1.0/invoke/content-service/method/graphql |
58-
| USER_SERVICE_URL | URL for user service GraphQL | http://host.docker.internal:5001/graphql | http://localhost:3500/v1.0/invoke/user-service/method/graphql |
59-
| FLASHCARD_SERVICE_URL | URL for flashcard service GraphQL | http://host.docker.internal:6001/graphql | http://localhost:3500/v1.0/invoke/flashcard-service/method/graphql |
60-
| REWARD_SERVICE_URL | URL for reward service GraphQL | http://host.docker.internal:7001/graphql | http://localhost:3500/v1.0/invoke/reward-service/method/graphql |
61-
| SKILLLEVEL_SERVICE_URL | URL for skilllevel service GraphQL | http://host.docker.internal:8001/graphql | http://localhost:3500/v1.0/invoke/skilllevel-service/method/graphql |
62-
| QUIZ_SERVICE_URL | URL for quiz service GraphQL | http://host.docker.internal:9001/graphql | http://localhost:3500/v1.0/invoke/quiz-service/method/graphql | |
50+
| Name | Description | Value in Dev Environment | Value in Prod Environment |
51+
|------------------------|------------------------------------|----------------------------------------------------------------------------|---------------------------------------------------------------------|
52+
| GATEWAY_PORT | Gateway port | 8080 | 8080 |
53+
| GATEWAY_HOSTNAME | Gateway host name | 0.0.0.0 | 0.0.0.0 |
54+
| DAPR_HTTP_PORT | Dapr HTTP Port | - | 3500 |
55+
| COURSE_SERVICE_URL | URL for course service GraphQL | http://host.docker.internal:2001/graphql | http://localhost:3500/v1.0/invoke/course-service/method/graphql |
56+
| MEDIA_SERVICE_URL | URL for media service GraphQL | http://host.docker.internal:3001/graphql | http://localhost:3500/v1.0/invoke/media-service/method/graphql |
57+
| CONTENT_SERVICE_URL | URL for content service GraphQL | http://host.docker.internal:4001/graphql | http://localhost:3500/v1.0/invoke/content-service/method/graphql |
58+
| USER_SERVICE_URL | URL for user service GraphQL | http://host.docker.internal:5001/graphql | http://localhost:3500/v1.0/invoke/user-service/method/graphql |
59+
| FLASHCARD_SERVICE_URL | URL for flashcard service GraphQL | http://host.docker.internal:6001/graphql | http://localhost:3500/v1.0/invoke/flashcard-service/method/graphql |
60+
| REWARD_SERVICE_URL | URL for reward service GraphQL | http://host.docker.internal:7001/graphql | http://localhost:3500/v1.0/invoke/reward-service/method/graphql |
61+
| SKILLLEVEL_SERVICE_URL | URL for skilllevel service GraphQL | http://host.docker.internal:8001/graphql | http://localhost:3500/v1.0/invoke/skilllevel-service/method/graphql |
62+
| QUIZ_SERVICE_URL | URL for quiz service GraphQL | http://host.docker.internal:9001/graphql | http://localhost:3500/v1.0/invoke/quiz-service/method/graphql | |
63+
| ASSIGNMENT_SERVICE_URL | URL for assignment service GraphQL | http://host.docker.internal:11001/graphql | http://localhost:3500/v1.0/invoke/assignment-service/method/graphql |
6364
| GAMIFICATION_SERVICE_URL | URL for gamification service GraphQL | http://host.docker.internal:1201/graphql | http://localhost:1200\v1.0/invoke/gamifiation-service/method/graphql |
64-
| JWKS_URL | URL for jwks keycloak | http://host.docker.internal:9009/realms/GITS/protocol/openid-connect/certs | http://keycloak/keycloak/realms/GITS/protocol/openid-connect/certs |
65+
| JWKS_URL | URL for jwks keycloak | http://host.docker.internal:9009/realms/GITS/protocol/openid-connect/certs | http://keycloak/keycloak/realms/GITS/protocol/openid-connect/certs |
66+
6567

6668

6769
### Other properties

additionalResolvers/content.ts

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,8 +233,68 @@ const resolvers: Resolvers = {
233233
},
234234

235235
},
236+
createAssignmentAssessment: {
237+
async resolve(root, _args, context, info) {
238+
// find out in which course the chapter this assessment should be created in is
239+
let chapters = await context.CourseService.Query._internal_noauth_chaptersByIds({
240+
root,
241+
args: {
242+
ids: [_args.assessmentInput.metadata.chapterId]
243+
},
244+
selectionSet: `
245+
{
246+
course {
247+
id
248+
}
249+
}
250+
`,
251+
});
252+
253+
if (chapters.length !== 1) {
254+
throw new Error("Chapter with given id does not exist.");
255+
}
256+
257+
let courseId = chapters[0].course.id;
258+
259+
// check that the user is an admin in the course the assessment should be created in
260+
if (!context.currentUser.courseMemberships.some((membership) => {
261+
return membership.courseId === courseId && membership.role === "ADMINISTRATOR";
262+
})) {
263+
throw new Error("User is not enrolled and/or an admin in the course the assessment should be created in.");
264+
}
236265

266+
// create the assessment
267+
let content = await context.ContentService.Mutation._internal_createAssessment({
268+
root,
269+
args: {
270+
courseId: courseId,
271+
input: _args.assessmentInput
272+
},
273+
context,
274+
info
275+
});
276+
277+
// Create the assignment
278+
await context.AssignmentService.Mutation._internal_noauth_createAssignment({
279+
root,
280+
args: {
281+
courseId: courseId,
282+
assessmentId: content.id,
283+
input: _args.assignmentInput
284+
},
285+
context,
286+
// we need to define a selection set manually here, otherwise it thinks we don't need any data
287+
// from this mutation and it won't actually be executed
288+
selectionSet: `
289+
{
290+
assessmentId
291+
}
292+
`,
293+
});
237294

295+
return content;
296+
}
297+
},
238298
},
239299
Query: {
240300
semanticSearch: {
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
extend type Grading {
2+
"""
3+
The user this grading belongs to.
4+
"""
5+
student: PublicUserInfo @resolveTo(
6+
sourceName: "UserService"
7+
sourceTypeName: "Query"
8+
sourceFieldName: "findPublicUserInfos"
9+
keyField: "studentId"
10+
keysArg: "ids"
11+
)
12+
}

additionalTypeDefs/content.graphqls

Lines changed: 57 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,58 @@ extend type Quiz {
187187
)
188188
}
189189

190+
extend type AssignmentAssessment {
191+
"""
192+
The assignment of the assessment.
193+
If this is null the system is in an inconsistent state and the assessment should be deleted.
194+
"""
195+
assignment: Assignment @resolveTo(
196+
sourceName: "AssignmentService",
197+
sourceTypeName: "Query",
198+
sourceFieldName: "findAssignmentsByAssessmentIds",
199+
keyField: "id",
200+
keysArg: "assessmentIds"
201+
)
202+
203+
"""
204+
The progress of processing the assessment. In particular when processing is done,
205+
the assessment's task contents will have been indexed for search.
206+
"""
207+
aiProcessingProgress: AiEntityProcessingProgress! @resolveTo(
208+
sourceName: "DocprocaiService",
209+
sourceTypeName: "Query",
210+
sourceFieldName: "_internal_noauth_getContentsAiProcessingProgress",
211+
keyField: "id",
212+
keysArg: "contentIds"
213+
)
214+
215+
"""
216+
Tags suggested for this assessment by the AI system.
217+
"""
218+
suggestedTags: [String!]! @resolveTo(
219+
sourceName: "DocprocaiService",
220+
sourceTypeName: "Query",
221+
sourceFieldName: "_internal_noauth_getAssessmentSuggestedTags",
222+
requiredSelectionSet: "{ id }",
223+
sourceArgs: {
224+
assessmentId: "{root.id}"
225+
}
226+
)
227+
}
228+
229+
extend type Assignment {
230+
"""
231+
The content this assignment belongs to.
232+
"""
233+
content: Content @resolveTo(
234+
sourceName: "ContentService",
235+
sourceTypeName: "Query",
236+
sourceFieldName: "contentsByIds",
237+
keyField: "assessmentId",
238+
keysArg: "ids"
239+
)
240+
}
241+
190242
extend type ContentMetadata {
191243
"""
192244
The course this content belongs to.
@@ -225,6 +277,10 @@ extend type Mutation {
225277
Creates a new flashcard set assessment and a new, linked flashcard set with the given properties.
226278
"""
227279
createFlashcardSetAssessment(assessmentInput: CreateAssessmentInput!, flashcardSetInput: CreateFlashcardSetInput!): FlashcardSetAssessment # resolved in content.ts
228-
280+
281+
"""
282+
Creates a new assignment assessment and a new, linked assignment with the given properties.
283+
"""
284+
createAssignmentAssessment(assessmentInput: CreateAssessmentInput!, assignmentInput: CreateAssignmentInput!): AssignmentAssessment! # resolved in content.ts
229285

230286
}

docker-compose.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ services:
2323
SKILLLEVEL_SERVICE_URL: http://app-skilllevel:8001/graphql
2424
QUIZ_SERVICE_URL: http://app-quiz:9001/graphql
2525
DOCPROCAI_SERVICE_URL: http://app-docprocai:9901/graphql/
26+
ASSIGNMENT_SERVICE_URL: http://app-assignment:1101/graphql
2627
GAMIFICATION_SERVICE_URL: http://app-gamification:1201/graphql
2728
DEBUG: 0
2829
ENABLE_LOGGING: 1 # Set to 1 to enable custom logging

0 commit comments

Comments
 (0)