Reputation: 7821
I get the below error message on a GraphQL query to Contentful, but do not understand why.
Error message:
"Query cannot be executed. The maximum allowed complexity for a query is 11000 but it was 12100. Simplify the query e.g. by setting lower limits for collections."
Query:
query ClassCollection(
$slug: String
$limit: Int
) {
classCollection(
where: { slug: $slug }
limit: $limit
) {
items {
slug
title
linkedFrom {
courseCollection {
items {
slug
}
}
}
filesCollection {
items {
title
asset {
title
fileName
url
width
height
contentType
}
}
}
}
}
}
Content model:
Notes
Question
Why am I getting that error message and how can I fix it?
What I tried
EDIT: Calculating the Query Complexity
EDIT 2
Conclusion
Upvotes: 1
Views: 3382
Reputation: 551
Even if Contentful's GraphQL API is aware of the validation limits for how many Classes in a Course in the linkedFrom
field, it is feasible that any other content type in your space that has reference fields may (in theory) also link to a Class, so the query must assume that there can be up to the set limit of linkedFrom
entries that aren't Courses.
So your (default) complexity in the query you've shared is:
classes
linkedFrom
entriesfiles
asset
fields (ie, 1 per file
)It may be possible that enforcing validation on ALL reference fields throughout your space to exclude Classes is reflected in the GraphQL response, altho unlikely.
Alternative approaches could be to
(where: { linkedFrom: 'courseCollection'})
), which might be aware of the validation restriction.files
and linkedFrom
) separately, or getting the class and file data first and then querying for courses that have that class in their classes field.Upvotes: 2