GraphQl+ Springboot+数据加载器:正确的模式是什么?

发布于 2025-01-30 04:38:41 字数 1068 浏览 3 评论 0原文

我有GraphQl + Springboot + MongoDB应用程序,带有GraphQl.java.kickstart.springboot,并且我遇到了性能问题。 该应用程序的步行骨架是去年完成的,我收到了它。我想添加数据加载机 / batchdataloader(更好)以提高性能,并避免查询数据库的加时性,以了解类似的请求。查看数据加载器示例,我看到的实现与我的实现截然不同。 我有一个QueryResolver类,可以调用称为存储库的服务。结果是从这里暴露的,而不是一些解析器处理的。

@Component
@Slf4j
@AllArgsConstructor
@NoArgsConstructor
public class Query implements GraphQLQueryResolver {
    @Autowired
    ProjectService projectService;

    public Iterable<ProjectDao> listProjects(String name, Sort orderByInput) {
        return projectService.getProjects(name, orderByInput);
    }
}

现在,我不明白这是否是一种错误的方法来添加数据加载器。 在这里我找到了一个问题类似的实现,但随后他似乎已经改变了答案。 更改整个代码会很耗时,我真的希望我只是缺少一些东西。 您有任何建议或文档需要建议吗?非常感谢您!

I have GraphQL + SpringBoot + MongoDB application, with graphql.java.kickstart.springboot ,and I'm having performance issues.
The walking skeleton of this application was done the last year and I received it as it is. I'd like to add DataLoaders / BatchDataLoaders (better) to improve the performance and to avoid to query the DB overtime for similar requests. Looking at DataLoaders examples I see quite different implementations from the one I have.
I have a QueryResolver class that calls the Service which calls the Repository. The result is exposed from here, not handled by some Resolvers.

@Component
@Slf4j
@AllArgsConstructor
@NoArgsConstructor
public class Query implements GraphQLQueryResolver {
    @Autowired
    ProjectService projectService;

    public Iterable<ProjectDao> listProjects(String name, Sort orderByInput) {
        return projectService.getProjects(name, orderByInput);
    }
}

Now I don't understand if this is a wrong approach in order to add the DataLoaders.
Here I found a question with a similar implementation, but then he seems to have changed looking at this answer.
Changing the whole code would be time-consuming and I really hope I'm just missing something.
Do you have any tips or docs to suggest? Thank you so much in advance!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文