Struggling with compound documents

Sorry, but I’m feeling a bit stupid right now.

I’m still new to JSONAPI and trying to build my first API according to the specification.
I’m working on the includes right now and I’m having a problem with the compound document example.

Is the example the structure of a response to a query for a single resource (GET /articles/1) or a query for a collection (GET /articles)?

Since “data” is an array, I assume that a collection was queried, even if the array only contains a single resource. But if that is the case, then I wonder how it would be possible on the client side to simply determine the linked records for one of the primary resources from the linked resources.
The client would have to work through the relationships for each of the primary resources and search through the list of includes to get the associated objects.

If the example is for the result of querying a single resource, then the problem would not be quite so big. Although the includes would also have to be searched in one situation or another, at least it would be ensured that all the contained relation data records somehow belong to this one resource.
But then I wonder why “data” is created as an array.

Am I perhaps making a mistake?

A resource may declare a relationship even if the related resource is not included in the compound document. You should parse the entire document and handle related resources regardless if they are included in the document or not. This gets even more important if resources are cached at the client-side.

I recommend having a look at existing implementation rather than reinventing: JSON:API — Implementations