首页 > 解决方案 > Graphql-java 是否支持对象数组作为复杂对象的查询参数?

问题描述

我目前正在使用 java spring-boot 实现 graphql。作为示例,我有如下架构:

type Book {
  id:ID
  name:String
  author:[Author]
  publisher:Publisher
}

type Author {
  authorId:ID
  authorName:String
}

type Publisher. {
  publisherId:ID
  publisherName:String
}

以上都是通过下面独立的rest api来获取的。我需要获取一系列书籍。

我总是可以对每本书进行独立查询:

eg:query {
  _678:bookbyId(id:678) {
  id
  name
  author {
    id
  }
  publisher {
    id
  }
  _679:bookbyId(id:679 ){
    id
    name
    author {
      id
    }
    publisher {
      id
    }
  }

但是有没有更好的查询方式

bookbyId([id:678,id:679]){
  id
  name
  author {
    id
  }
  publisher {
    id
  }

如果是,我如何处理作者和出版商到正确书籍的映射?

标签: graphql-java

解决方案


推荐阅读