Replies: 2 comments 1 reply
-
| 
 Out of the box it has  You should NOT your  In this code example I cant see how you call the data loader. I guess its  Also note that re-using data loader instances between requests can lead to security problems - eg request A loads data X and then later request B will see that (potentially) cached data - which may be allowed or may not. | 
Beta Was this translation helpful? Give feedback.
-
| 
 Thanks for your reply. And I am trying to use mapstruct and dataloader together to make it easier to translate domain object to DTO. // ============================ Domain =================== @Entity @Getter @NoArgsConstructor(access = AccessLevel.PROTECTED) public class Comment { @Id @GeneratedValue private Long id; private String content; private Long articleId; private String authorId; private Instant createdAt; } @Entity @Getter @NoArgsConstructor(access = AccessLevel.PROTECTED) public class User { @Id private String username; private String email; private Instant createdAt; } // ============================ DTO =================== @Data public class CommentDTO { private Long id; private String content; private Instant createdAt; private UserDTO author; } @Data public class UserDTO { String username; String email; } // ============================ Mapper =================== @Mapper(componentModel = "spring") public abstract class UserDTOMapper { private @Autowired DataLoaderRegistry dataLoaderRegistry; abstract UserDTO toDTO(User user); @SneakyThrows User toEntity(String id) { DataLoader<String, User> userDataLoader = dataLoaderRegistry.getDataLoader("userLoader"); return userDataLoader.load(id).get(); // <-------- This is wrong, this will stuck the thread } } @Mapper(componentModel = "spring", uses = {UserDTOMapper.class}) public abstract class CommentDTOMapper { @Autowired private DataLoaderRegistry registry; @Mapping(source = "authorId", target = "author") abstract CommentDTO commentToCommentDTO(Comment comment); abstract List<CommentDTO> map(List<Comment> comments); }I know I am wrong to call  | 
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi, I am trying to use dataloader without graphql. I know there is a
ScheduledDataLoaderRegistryto automatically call thedispatchin everyDataLoaderbut I still don't know how to use it. The code below seems not making the registry automatically trigger thedispatchAllas expected.Beta Was this translation helpful? Give feedback.
All reactions