33import com .springqprobackend .springqpro .domain .TaskEntity ;
44import com .springqprobackend .springqpro .enums .TaskStatus ;
55import com .springqprobackend .springqpro .enums .TaskType ;
6+ import com .springqprobackend .springqpro .service .ProcessingService ;
67import com .springqprobackend .springqpro .service .TaskService ;
78import com .springqprobackend .springqpro .graphql .controllerRecords .CreateTaskInput ;
89import com .springqprobackend .springqpro .graphql .controllerRecords .UpdateTaskInput ;
10+ import org .slf4j .Logger ;
11+ import org .slf4j .LoggerFactory ;
912import org .springframework .graphql .data .method .annotation .SchemaMapping ;
1013import org .springframework .security .access .prepost .PreAuthorize ;
14+ import org .springframework .security .core .Authentication ;
1115import org .springframework .stereotype .Controller ;
1216import org .springframework .graphql .data .method .annotation .Argument ;
1317import org .springframework .graphql .data .method .annotation .MutationMapping ;
2327- The schema defines how the client *sees* the data.
2428- Spring will automatically wire the /graphql endpoint (no controller mapping is needed).
2529*/
26-
27- /* 2025-11-12-DEBUG:
28- DONE:
29- - task (query)
30- - tasks (query)
31- - createTask (mutation)
32- TO-DO FROM schema.graphqls:
33- - updateTask (mutation)
34- - deleteTask (mutation)
35- */
36-
3730@ Controller // IMPORTANT NOTE: GraphQL controllers use @Controller, NOT @RestController (remember this!)
3831public class TaskGraphQLController {
3932 // Field(s):
33+ private static final Logger logger = LoggerFactory .getLogger (ProcessingService .class );
4034 private final TaskService taskService ;
4135 // Constructor(s):
4236 public TaskGraphQLController (TaskService taskService ) {
@@ -45,37 +39,46 @@ public TaskGraphQLController(TaskService taskService) {
4539
4640 @ QueryMapping // This is GraphQL query resolver.
4741 @ PreAuthorize ("isAuthenticated()" ) // 2025-11-24-DEBUG: Securing my GraphQL resolvers for JWT.
48- public List <TaskEntity > tasks (@ Argument TaskStatus status ) {
42+ public List <TaskEntity > tasks (@ Argument TaskStatus status , Authentication auth ) {
43+ logger .info ("INFO: GraphQL tasks (by status) Query sent by user:{}" , auth .getName ());
4944 return taskService .getAllTasks (status );
5045 }
5146 @ QueryMapping
5247 @ PreAuthorize ("isAuthenticated()" ) // 2025-11-24-DEBUG: Securing my GraphQL resolvers for JWT.
53- public List <TaskEntity > tasksType (@ Argument TaskType type ) { return taskService .getAllTasks (type ); } // <-- 2025-11-19-DEBUG: ADDITION.
48+ public List <TaskEntity > tasksType (@ Argument TaskType type , Authentication auth ) {
49+ logger .info ("INFO: GraphQL tasks (by type) Query sent by user:{}" , auth .getName ());
50+ return taskService .getAllTasks (type );
51+ }
5452
5553 @ QueryMapping
5654 @ PreAuthorize ("isAuthenticated()" ) // 2025-11-24-DEBUG: Securing my GraphQL resolvers for JWT.
57- public TaskEntity task (@ Argument String id ) {
55+ public TaskEntity task (@ Argument String id , Authentication auth ) {
56+ logger .info ("INFO: GraphQL task (by id) Query sent by user:{}" , auth .getName ());
5857 return taskService .getTask (id ).orElse (null );
5958 }
6059
6160 @ MutationMapping
6261 @ PreAuthorize ("isAuthenticated()" ) // 2025-11-24-DEBUG: Securing my GraphQL resolvers for JWT.
63- public TaskEntity createTask (@ Argument ("input" ) CreateTaskInput input ) {
62+ public TaskEntity createTask (@ Argument ("input" ) CreateTaskInput input , Authentication auth ) {
63+ logger .info ("INFO: GraphQL createTask Query sent by user:{}" , auth .getName ());
6464 return taskService .createTask (input .payload (), input .type ());
6565 }
6666
6767 @ MutationMapping
6868 @ Transactional
6969 @ PreAuthorize ("isAuthenticated()" ) // 2025-11-24-DEBUG: Securing my GraphQL resolvers for JWT.
70- public TaskEntity updateTask (@ Argument ("input" ) UpdateTaskInput input ) {
70+ public TaskEntity updateTask (@ Argument ("input" ) UpdateTaskInput input , Authentication auth ) {
71+ logger .info ("INFO: GraphQL updateTask Query sent by user:{}" , auth .getName ());
7172 taskService .updateStatus (input .id (), input .status (), input .attempts ());
72- return task (input .id ()); // or "return taskService.getTask(id).orElse(null);"
73+ return taskService .getTask (input .id ()).orElse (null );
74+ //return task(input.id()) ; // or "return taskService.getTask(id).orElse(null);"
7375 }
7476
7577 @ MutationMapping
7678 @ Transactional
7779 @ PreAuthorize ("hasRole('ADMIN')" )
78- public boolean deleteTask (@ Argument String id ) {
80+ public boolean deleteTask (@ Argument String id , Authentication auth ) {
81+ logger .info ("INFO: GraphQL deleteTask Query sent by user:{}" , auth .getName ());
7982 return taskService .deleteTask (id );
8083 }
8184
0 commit comments