Credits, Complexity, and Depth

API Credits

As in Zoho CRM Rest APIs, Zoho CRM GraphQL API calls are also associated with credits. A single GraphQL API call can consume up to 10 credits based on the type of resources queried.

When making requests, each resource consumes a specific amount of credits, ranging from 0.25 to 1. These credits are aggregated to determine the total consumption and rounded up to the nearest integer. If the total exceeds 10, an error will be thrown.

Query Complexity

Query Complexity refers to the workload a query exerts on servers. It increases based on the number of fields and depth of the query. To ensure proper server performance, complexity is capped to 1000 per GraphQL query. If a query exceeds this complexity, ExecutionAborted error will be thrown.

Root-level query refers to the top-level query that serves as the entry point for fetching data from the GraphQL API. Sub-level query refers to nested resources inside a resource.

The calculation for query complexity is done based on the below factors.

Root level query100 points for each resource
Sub query25 points for each Parent lookup (Lookup fields, User lookup fields etc).
50 points for each Child relation (Subform data).
50 points for each Multi Module lookup (what_Id, Appointments_For).

Credit and Complexity consumed by different resources in _Meta

ResourceCreditsComplexity
ChildRelation.550
ChildRelations1100
CustomView0.550
CustomViews1100
Field0.550
Fields1100
KanbanView1100
Layout1100
Layouts1100
LayoutFields1100
Module0.550
Modules1100
Profile0.550
ProfileModuleProperties1100
ProfilePermissions1100
Profiles1100
RelatedList0.550
RelatedLists1100
Role.550
Roles1100
User(Except Created_By, Modified_By fields)0.550
UserProperties1100
Users1100
Widgets1100

Credit and Complexity consumed by different resources in _Records

ResourceCreditsComplexity
Child Relations(eg: Subforms).550
Multi Module Lookups(eg: what_Id, Appointments_For).550
Parent relations(eg: Lookup fields).2525
User lookups (eg: Created_By, Modified_By).2525

Note

Multi-select lookups data has to be queried through the corresponding linking module.

Query Depth

Query Depth refers to the number of nesting levels of a field that is queried. In order to limit server load, in Zoho CRM, query depth is limited to 7 for metadata and 3 for records. LIMIT_EXCEEDED error will be thrown if query depth exceeds allowed value.

Calculating depth

To calculate depth in a query, count the number of nesting levels of the query excluding the nesting levels of "query","Records", "Meta", "_data" and "{value}" of a field (leaf node).

Example for calculating depth

Copiedquery  { # not considered for depth
    Records {# not considered for depth
        Leads { # depth 1
            _data {# not considered for depth
                Converted_Deal { # depth 2
                    Account_Name { #depth 3
                        Owner { #depth 4
                            last_name { # not considered for depth
                                value
                            }
                        }
                    }
                }
            }
        }
    }
}

GraphQL-query-depth

Examples for calculating credits and complexity

1. Querying Users

Copiedquery  {
    Meta {
        Users {                                               # 1 credit,100 complexity
            _data {
                id
                Reporting_To {                           # .5 credit,50 complexity
                    id
                    last_name
                }
                role {                                          # .5 credit,50 complexity
                    id
                    name
                    description
                }
                profile {                                      # .5 credit,50 complexity
                    id
                    name
                    description
                }
            }
        }
    }
}

Total Credits: 1 + 0.5 + 0.5 + 0.5 =ceil(2.5) = 3 credits.

Total Complexity: 100 + 50 + 50 + 50 = 250

2. Querying what_Id

Copiedquery {
    Records {
        Tasks {                                                #1 credit,100 complexity
            _data {
                What_Id {                                     #.5 credit,50 complexity
                    id {
                        value
                    }
                }
                id {
                    value
                }
            }
        }
    }
}

Total Credits: 1+.5 = ceil(1.5) = 2 credits

Total Complexity: 100 + 50 = 150

 

3. Querying Parent and Child Relationships (Subforms)

Copiedquery {
    Records {                                               #1 Credit,100 complexity
        Leads {
            _data {
                id {
                    value
                }
                Subform_1__r {                           #.5 Credits,50 complexity
                    _data {
                        id {
                            value
                        }
                    }
                }
                Converted_Deal {                       #.25 Credits,25 complexity
                    id {
                        value
                    }
                }
            }
        }
    }
}

Total Credits: 1+0.5 +.25= ceil(1.75) = 2 Credits

Total Complexity: 100 + 50 + 25 = 175

4. Multiple resources nested query

Copiedquery {
    Meta {
        Modules(filter: { api_name: "Leads" }) {        # 1 credit,100 complexity
            _data {
                id
                api_name
                module_name
                singular_label
                api_supported
                status
                fields {                                            # 1 credit,100 complexity
                    _data {
                        id
                        api_name
                        ui_type
                        data_type
                        json_type
                        visible
                    }
                }
                custom_view(filter: { api_name: "Todays_Leads" }) {   # 1 credit,100 complexity
                    _data {
                        id
                        api_name
                        display_value
                        name
                        system_defined
                    }
                }
            }
        }
        Roles {                                      # 1 credit,100 complexity
            _data {
                id
                display_label
                api_name
                name
                reporting_to {            # 0.5 credit,50 complexity
                    id
                    display_label
                    api_name
                    name
                }
            }
        }
    }
}

Total Credits :1+1+1+1+0.5 = ceil(4.5) = 5

Total Complexity: 100 + 100 + 100 + 100 + 50 = 450