I am working with two GraphQL types:
type Author {
id: String!
name: String!
}
type Book {
id: String!
author: Author!
name: String!
}
In my database structure, I have set up a foreign key relationship within the books table:
table authors (example code)
`id` INTEGER UNSIGNED
`name` STRING
table books (example code)
`id` INTEGER UNSIGNED
`author_id` INTEGER UNSIGNED REFERENCE `authors.id`
`name` STRING
When resolving a GraphQL query like:
query allTheBooks {
id
name
author {
id
name
}
}
My goal is to minimize SQL queries and perform just one SELECT
operation like:
SELECT books.id, books.name, authors.id, authors.name
FROM books
LEFT JOIN authors ON authors.id = books.author_id
Instead of multiple sequential queries as currently being done.
Is it possible to identify which "child fields" are requested in a GraphQL resolver?
Your insights on this matter would be greatly appreciated. Thank you!