In an effort to teach myself Apollo Server I was implementing the schema described here. CodeGen generated what look like very sensible definitions for the types.
export type Book = {
__typename?: 'Book';
author: Author;
title: Scalars['String'];
};
export type Library = {
__typename?: 'Library';
books?: Maybe<Array<Book>>;
branch: Scalars['String'];
};
The problem was the (Javascript) given in the example, equally sensibly, gave data for books and libraries as
{
branch: "riverside",
}
and
{
title: "The Awakening",
author: "Kate Chopin",
branch: "riverside",
}
That is, in the Javascript, each child had the ID of its parent, but in the GraphQL, each parent had an array of its actual children.
When I applied the Resolvers
type, of course, the compiler complained. Where is the child array? it asked plaintively.
You are supposed to figure that out at run-time, if you are even asked. Stupid computer.
Both Apollo and GraphQL CodeGen are very professional products. They would not have omitted something this basic. What am I missing?
(Incidentally, I think, but am really not sure, that this question springs from the same issue.)