We have recently changed how we calculate GraphQL queries complexites and we will enforce the new limits starting from June 12, 2023. Please, read the product update page too.
Each query hitting our Content Delivery API has a complexity cost based on
which type of field is present
how many fields are present
how many filters are present
how many sorting parameters are present
the page size
Each DatoCMS plan comes with a maximum allowed complexity cost which is 10,000,000 by default. Take a look at the "Plan and usage" section of your project in the Account dashboard to understand which is your complexity limit.
The Content Delivery API sets the X-Complexity
header in the response to let you know the calculated complexity cost for your submitted query and the X-Max-Complexity
header containing your current plan complexity limit.
If the query complexity cost above your plan limit you'll get an error from the Content Delivery API:
{"errors": [{"message": "Query has complexity of xxx, which exceeds max complexity of yyy"}]}
Unless specified otherwise, each requested GraphQL field has a cost of 1.
Each filter argument has a cost of 250.
Each sorting parameter has a cost of 250.
To calculate the pagination cost, multiply the page size by the inner fields' cost. By default, the page size is 20 but you can override it using the first
argument.
Root fields like allArtists
have a base cost of 100. To this, the cost of filters, the cost of sorting, and the cost of pagination must be added.
The following query has a cost of 140: 100 (base) + 20 (implicit page size) x 2 (inner fields' cost)
query { # it returns at max 20 records by defaultallArtists { # 100id # 1name # 1}}
The following query has a cost of 1175: 100 (base) + 750 (filtering) + 250 (sorting) + 25 (page size) x 3 (inner fields' cost)
query {allArtists( # 100filter: {birth: {gt: "1990-01-01", lt: "2010-01-01"}, # 250 x 2 => 500country: {eq: "DE"} # 250},orderBy: [name_ASC], # 250first: 25 # explicit page size) {id # 1name # 1age # 1}}
Root fields like _allArtistsMeta
have a base cost of 1000. To this, the cost of filters and the inner field's cost must be added.
The following query has a cost of 1251: 1000 (base) + 250 (filtering) + 1 (inner fields' cost)
query {_allArtistsMeta( # 1000filter: { country: {eq: "NL"} } # 250) {count # 1}}
Root fields like artist
have a base cost of 50. To this, the cost of filters, the cost of sorting, and the inner fields' cost must be added.
The following query has a complexity cost of 301: 50 (base) + 250 (filtering) + 1 (inner fields' cost)
query {artist( # 50filter: { id: {eq: "123"} } # 250) {name # 1}}
Root fields about single-instance records have a base cost of 25. To this, the inner field's cost must be added.
The following query has a cost of 27: 25 (base) + 2 (inner fields' cost)
query {contactPage { # 25phoneNumber # 1emailAddress # 1}}
Fields like _allReferencingMovies
have a base cost of 100. To this, the cost of filters, the cost of sorting, and the cost of pagination must be added.
The following section has a cost of 1110: 100 (base) + 500 (filtering) + 500 (sorting) + 5 (page size) x 2 (inner fields' cost)
..._allReferencingMovies( # 100through: {fields: {anyIn: [movie_artist]}, # 250locales: {anyIn: en} # 250},orderBy: [title_ASC, _createdAt_DESC], # 500,first: 5 # explicit page size) {id # 1title # 1}...
Fields like _allReferencingMoviesMeta
have a base cost of 1000. To this, the cost of filters and the inner fields' cost must be added.
The following section has a cost of 1001.
..._allReferencingMoviesMeta { # 1000count # 1}...
The following GraphQL fields differ from the base cost (1):
single asset field: 5
asset gallery field: 5 x inner fields' cost
multiple-paragraph text, when rendering Markdown in HTML: 5
JSON field: 5
single link field: 10
multiple links field: 5 x inner fields' cost
modular content field: 5 x inner fields' cost
structured text field
value: 10
blocks: 5 x inner fields' cost
links: 5 x inner fields' cost
children field (available in tree collections): 5 x inner fields' cost
parent field (available in tree collections): 25
multi-locale field
value: number of environment's locales x inner fields' cost
SEO meta tag field
image: 5
default _seoMetaTags: 5
The following query has a cost of 351, composed by:
50 (base cost of single record field)
250 (filtering)
5 + 1 + 5 (photo field)
10 + 5 x 1 + 5 x 2 (content field)
5 x 3 (movies field)
query {artist( # 50filter: { id: {eq: "123"} } # 250) {photo { #single asset field: 5url # 1blurUpThumb # 5}content { # structured text fieldvalue # 10links { # 5 x inner fields' costid # 1}blocks { # 5 x inner fields' costid # 1text # 1}}movies { # multiple links field: 5 x inner fields' costid # 1title # 1releaseDate # 1}}
A GraphQL union complexity is the max complexity between all of the possible types.
The modular content field content
has a complexity cost of 10: 5 x 2
query {artist(filter: { id: { eq: "123" }}) {namecontent { # 5 x max possible union's cost... on MovieRecord {title # 1}... on TvSerieRecord {title # 1channel # 1}}}}
Root field allUploads
has a base cost of 100. To this, the cost of filters, the cost of sorting, and the cost of pagination must be added.
The following query has a cost of 801: 100 (base) + 250 (filtering) + 250 (sorting) + 30 (page size) x 7 (inner fields' cost)
query {allUploads( # 100filter: {format: {eq: "jpg"}}, # 250orderBy: [size_DESC], # 250first: 30 # explicit page size) {id # 1url # 1blurUpThumb # 5}}
Root field _allUploadsMeta
has a base cost of 1000. To this, the cost of filters and the inner fields' cost must be added.
The following query has a cost of 1251: 1000 (base) + 250 (filtering) + 1 (inner fields' cost)
query {_allUploadsMeta( # 1000filter: {format: {eq: "jpg"}} # 250) {count # 1}}
Root field upload
has a base cost of 50. To this, the cost of filters, the cost of sorting, and the inner fields' cost must be added.
The following query has a complexity cost of 308: 50 (base) + 250 (filtering) + 8 (inner fields' cost)
query {upload( # 50filter: {id: {eq: "123"}} # 250) {url #1title #1blurUpThumb # 5blurhash #1}}
The following GraphQL fields differ from the base cost (1):
blurUpThumb: 5
Root field _site
has a base cost of 10. To this, the inner fields' cost must be added.
The following query has a cost of 13.
query {_site { # 10globalSeo { # 1siteName # 1titleSuffix # 1}}}