You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何使用Java GraphQL DGS Client配置字段嵌套的查询参数

解决方案

你需要通过DGS自动生成的输入类构造嵌套参数,再调用items方法的带参重载传入参数即可,具体实现如下:


步骤1:构造嵌套输入参数

根据你GraphQL Schema自动生成的输入类型,依次构造过滤、分页及items的query参数:

// 1. 构造items的过滤条件,类名以代码生成的实际类名为准
ItemFilterInput filter = ItemFilterInput.newBuilder()
    .isAccessible(true)
    .availabilityTypes(List.of(AvailabilityType.StudyPlan))
    .build();

// 2. 构造分页排序参数
PaginationAndSortingInput pagination = PaginationAndSortingInput.newBuilder()
    .offset(0)
    .limit(10)
    .build();

// 3. 构造items字段的query入参
ItemQueryInput itemsQuery = ItemQueryInput.newBuilder()
    .filter(filter)
    .paginationAndSorting(pagination)
    .build();

注:上述输入类的类名、枚举名均为匹配你查询语句的示例,实际以DGS Client代码生成插件根据你的Schema生成的类名为准。


步骤2:修改投影构造逻辑,传入参数

将原先无参的items()调用改为带参数的重载,传入上面构造好的itemsQuery对象:

TocResourceProjectionRoot root = new TocResourceProjectionRoot().data().title().id()
        .identifier().getParent()
        // 替换原有无参items(),传入构造好的query参数
        .items(itemsQuery)
        .data().id().identifier().getParent().type().displayId()
        .orderNo().title().availabilityTypes().getRoot();

验证方法

你可以调用graphQLQueryRequest.serialize()打印生成的完整GraphQL查询语句,确认参数是否符合预期。

内容的提问来源于stack exchange,提问作者user3306895

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.09.28 15:54:01