With the goal of learning Apollo Server, I decided to implement the schema outlined here. The CodeGen produced what seemed to be logical type definitions for books and libraries.
export type Book = {
__typename?: 'Book';
author: Author;
title: Scalars['String'];
};
export type Library = {
__typename?: 'Library';
books?: Maybe<Array<Book>>;
branch: Scalars['String'];
};
The issue arose when the example code (Javascript) provided data for books and libraries as:
{
branch: "riverside",
}
and
{
title: "The Awakening",
author: "Kate Chopin",
branch: "riverside",
}
In the Javascript, each child had the ID of its parent, but in the GraphQL schema, each parent had an array of its children. This led to confusion when trying to apply the Resolvers
type, resulting in compiler errors questioning the absence of a child array.
It seems that Apollo and GraphQL CodeGen are robust tools, therefore it puzzled me why such a fundamental concept was overlooked. What am I overlooking here?
(On a side note, I stumbled upon this question which appears to touch on the same dilemma.)