StrapiCollectionQuery constructor

StrapiCollectionQuery({
  1. required dynamic collectionName,
  2. required List<StrapiField> requiredFields,
  3. int? limit,
  4. int? start,
})

graph query against strapi collection or List of references (think of repeatable references in strapi) in Strapi data structure, you can nest it according to the reference fields that exists in the data structure of the collection model, collectionName is required only for the root query, any collectionName passed to additional queries of a root query are ignored because query will be made against the field name, pass requiredFields to be in the response, limit is the maximum number of documents in the response, start can be used to paginate the queries,

if you have a collections like the fallowing,

A with model

{
  "id":"<value>",
  "name": "<value>",
  "single_reference_for_B": "<id>",
  "repeatable_reference_for_C": ["<id>","<id>",...],
}

B with model

{
  "id":"<value>",
  "dob": "<value>",
}

C with model

{
  "id":"<value>",
  "place": "<value>",
}

for above collection models, if you are making graph query against A, required fields are passed like this

final query = StrapiCollectionQuery(
collectionName: "A",
requiredFields: [
  StrapiLeafField("id"),
  StrapiLeafField("name"),
],
);
///and [StrapiLeafField]s are filtered like this, this query returns objects contining the id (must return only one)
///check out [StrapiFieldQuery] to see all the filter posibilities
query.whereField(
   field: StrapiLeafField("id"),
   query: StrapiFieldQuery.equalTo,
   value: "<value>",
 );

you cannot require the fields single_reference_for_B and repeatable_reference_for_C as they are references, if you want to require them you have to nest the query against them like this,

lets modify the last query

///use [StrapiModelQuery] if the reference is single
query.whereModelField(
field: StrapiModelField("single_reference_for_B"),
  query: StrapiModelQuery(
  requiredFields: [
    StrapiLeafField("id"),
    StrapiLeafField("dob"),
  ],
),
);

///use [StrapiCollectionQuery] if the reference is repeatable i.e list of references as mentioned earlier
query.whereCollectionField(
field: StrapiCollectionField("repeatable_reference_for_C"),
query: StrapiCollectionQuery(
  collectionName: "C",
  requiredFields: [
    StrapiLeafField("id"),
    StrapiLeafField("place"),
  ],
),
);

Implementation

StrapiCollectionQuery({
  required collectionName,
  required List<StrapiField> requiredFields,
  this.limit,
  this.start,
})  : this.collectionName = _collectionNameToGraphQlName(collectionName),
      super(requiredFields: requiredFields);