Skip to main content

GraphQL query complexity seems too high when fetching current users teams with users

  • November 12, 2021
  • 3 replies
  • 1410 views

fatih
Forum|alt.badge.img
  • Participating Frequently

The query below results in the query complexity budget being exhausted, especially if users are not being limited:

me {
    id,
    name,
    teams {
      id,
      name,
      users(limit: 100) {
        id
      }
    }
  }

complexity {
    before,
    after,
    query,
    reset_in_x_seconds
  }

However the query cost for the query below is only about 1000.

  teams {
      id,
      name,
      users {
        id
      }
    }
  
  complexity {
    before,
    after,
    query,
    reset_in_x_seconds
  }

Am I misunderstanding about the usage of the first query or is this a bug?

3 replies

kolaai
Forum|alt.badge.img
  • monday.com Partner
  • November 12, 2021

Hello @fatih,
This is due to nesting. Nesting increases the complexity by multiple folds. If possible avoid it or keep it to the barest minimum.
You can read more about that in the docs here


AlexSavchuk
Forum|alt.badge.img
  • monday.com Team Member
  • November 12, 2021

Hey @fatih ,

I agree with @kolaai here - in this case, it is better to use 2 separate queries, one for team, and the other query for the info about current user. Otherwise, as Alfred mentioned, you are implementing nesting within the query and that amplifies the total complexity of your requests.

-Alex


fatih
Forum|alt.badge.img
  • Author
  • Participating Frequently
  • November 17, 2021

Thanks for your replies @kolaai & @AlexSavchuk. I understand that nesting increases complexity. What I do not understand yet is how limiting nested queries impacts complexity. I have an instance with 5 users, the following query results in a complexity of 13022:

me {
    id,
    name,
    teams {
      id,
      name,
      users(limit: 1) {
        id
      }
    }
  }
  
  complexity {
    before,
    after,
    query,
    reset_in_x_seconds
  }

If I increase the limit parameter the query complexity is increased by a thousand, it doesn’t stop at 5, but just continues to be increased by a thousand.