我有两种 GraphQL 类型:
type Author {
id: String!
name: String!
}
type Book {
id: String!
author: Author!
name: String!
}
在我的数据库中,它是通过 books 表内的外键实现的:
表作者(伪代码)
`id` INTEGER UNSIGNED
`name` STRING
表书(伪代码)
`id` INTEGER UNSIGNED
`author_id` INTEGER UNSIGNED REFERENCE `authors.id`
`name` STRING
因此,当我解析 GraphQL 查询时,例如:
query allTheBooks {
id
name
author {
id
name
}
}
我只想做一件事SELECT
SQL 查询如下:
SELECT books.id, books.name, authors.id, authors.name
FROM books
LEFT JOIN authors ON authors.id = books.author_id
而不是当前的:
SELECT books.id, books.name, books.author_id
FROM books
SELECT authors.id, authors.name
FROM authors
WHERE author.id = [one the the books.author_id of the first SELECT]
SELECT authors.id, authors.name
FROM authors
WHERE author.id = [one the the books.author_id of the first SELECT]
[...]
有没有办法知道 GraphQL 解析器中查询了哪些“子字段”?
预先感谢您的答复!