I'm having a block trying to figure out the syntax for a query condition that seems like it would be a pretty common one.
The typedef below stores an ID value for the agent who represents an Author, in a one-agent-to-many (authors) relationship. I'd like to extract the name of the agent at the same time I'm getting details from the Author schema.
type Author {
id: ID!
firstName: String
middleInitial: String
lastName: String
posts: [Post]
agent: ID
}
So the enclosing query (returning a list of all Authors) looks like this:
{
authors {
firstName
lastName
agent
}
}
This gives me back the Agent's ID. How can I use that same query to fetch the agent's name, from a typedef similar to the one above?
type Agent {
id: ID!
name: String
}
type Author {
id: ID!
firstName: String
middleInitial: String
lastName: String
posts: [Post]
agent: Agent
}
// Query
{
authors {
firstName
lastName
agent {
name
}
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With