diff --git a/scheduler-server/src/main/java/gov/nasa/jpl/aerie/scheduler/server/services/GraphQLMerlinDatabaseService.java b/scheduler-server/src/main/java/gov/nasa/jpl/aerie/scheduler/server/services/GraphQLMerlinDatabaseService.java index 77288576f9..fef071f5e8 100644 --- a/scheduler-server/src/main/java/gov/nasa/jpl/aerie/scheduler/server/services/GraphQLMerlinDatabaseService.java +++ b/scheduler-server/src/main/java/gov/nasa/jpl/aerie/scheduler/server/services/GraphQLMerlinDatabaseService.java @@ -649,14 +649,20 @@ private void modifyActivityDirectives( { ensurePlanExists(planId); final var request = new StringBuilder(); - request.append("mutation updatePlanActivityDirectives($activities: [activity_directive_set_input!]!) {"); - var index = 0; - final var activitiesObject = Json.createArrayBuilder(); + request.append("mutation updatePlanActivityDirectives("); + request.append(String.join( + ",", + activities.stream().map($ -> "$activity_%d: activity_directive_set_input!".formatted($.id().id())).toList() + )); + request.append(") {"); + final var arguments = Json.createObjectBuilder(); for (final var act : activities) { + final var id = act.id().id(); request.append(""" - update_%d: update_activity_directive_by_pk(pk_columns: {id: %d, plan_id: %d}, _set: $activities[%d]) {} - """.formatted(act.id().id(), act.id().id(), planId.id(), index)); - index++; + update_%d: update_activity_directive_by_pk(pk_columns: {id: %d, plan_id: %d}, _set: $activity_%d) { + affected_rows + } + """.formatted(id, id, planId.id(), id)); final var activityObject = Json .createObjectBuilder() @@ -669,13 +675,9 @@ private void modifyActivityDirectives( insertionObjectArguments.add(arg.getKey(), serializedValueP.unparse(arg.getValue())); } activityObject.add("arguments", insertionObjectArguments.build()); - activitiesObject.add(activityObject); + arguments.add("activity_%d".formatted(id), activityObject); } - final var arguments = Json - .createObjectBuilder() - .add("activities", activitiesObject.build()) - .build(); - postRequest(request.toString(), arguments).orElseThrow(() -> new NoSuchPlanException(planId)); + postRequest(request.toString(), arguments.build()).orElseThrow(() -> new NoSuchPlanException(planId)); } private void deleteActivityDirectives( @@ -689,9 +691,10 @@ private void deleteActivityDirectives( request.append("mutation deletePlanActivityDirectives {"); for (final var id : ids) { request.append(""" - delete_%d: delete_activity_directive_by_pk(id: %d, plan_id: %d) {} + delete_%d: delete_activity_directive_by_pk(id: %d, plan_id: %d) {affected_rows} """.formatted(id.id(), id.id(), planId.id())); } + request.append("}"); postRequest(request.toString()).orElseThrow(() -> new NoSuchPlanException(planId)); }