# How to Decrease Complexity of the querys

**URL:** <https://community.shiphero.com/t/how-to-decrease-complexity-of-the-querys/109>\
**Category:** GraphQL API\
**Created:** [September 5, 2019, 4:06pm UTC](https://community.shiphero.com/t/how-to-decrease-complexity-of-the-querys/109 "2019-09-05T16:06:08Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Daniel](https://avatars.discourse-cdn.com/v4/letter/d/3ec8ea/32.png) [@Daniel](https://community.shiphero.com/u/Daniel)\
**Post date:** [September 5, 2019, 4:06pm UTC](https://community.shiphero.com/t/how-to-decrease-complexity-of-the-querys/109/1 "2019-09-05T16:06:08Z")

</div>

How to decrease complexity of the query.

I was call inventory\_changes query but i got below error, i found query required 101 credit for single record (Particular SKU) , how to resolve this issue, please help

{  
“errors”: [  
{  
“code”: 30,  
“message”: “There are not enough credits to perfom the requested operation, which requires 101 credits, but the are only 0 credits left. You can execute queries up to that level of credits or wait 32 minutes until your quota is refreshed”,  
“operation”: “inventory\_changes”,  
“request\_id”: “5d71066ba584c602ef4c6fce”,  
“required\_credits”: 101,  
“remaining\_credits”: 0,  
“time\_remaining”: “32 minutes”  
}  
],  
“data”: {  
“inventory\_changes”: null  
}  
}

Query : query{  
inventory\_changes(sku:“701980785238”){  
complexity  
data{

```
  edges{
    
    node{
      cycle_counted
      
     
    }
  }
}

```

}  
}

---

<div class="post-metadata">

**Author:** ![yosef](https://sea2.discourse-cdn.com/flex020/user_avatar/community.shiphero.com/yosef/32/9_2.png) [@yosef](https://community.shiphero.com/u/yosef)\
**Post date:** [September 5, 2019, 4:22pm UTC](https://community.shiphero.com/t/how-to-decrease-complexity-of-the-querys/109/2 "2019-09-05T16:22:33Z")

</div>

Daniel,  
Try adding `first` to the data and use `hasNextPage` to see if you need to retrieve more records. Without `first` the complexity defaults to 100.

For example:

```
{
  inventory_changes(sku: "701980785238") {
    complexity
    data(first: 10) {
      pageInfo {
        hasNextPage
      }
      edges {
        node {
          cycle_counted
        }
      }
    }
  }
}
```

---

<div class="post-metadata">

**Author:** ![Daniel](https://avatars.discourse-cdn.com/v4/letter/d/3ec8ea/32.png) [@Daniel](https://community.shiphero.com/u/Daniel)\
**Post date:** [September 5, 2019, 5:18pm UTC](https://community.shiphero.com/t/how-to-decrease-complexity-of-the-querys/109/4 "2019-09-05T17:18:22Z")

</div>

Thank you so much  
I was try above solution and it decreasing the complexity

---

<div class="post-metadata">

**Author:** ![Daniel](https://avatars.discourse-cdn.com/v4/letter/d/3ec8ea/32.png) [@Daniel](https://community.shiphero.com/u/Daniel)\
**Post date:** [September 5, 2019, 5:38pm UTC](https://community.shiphero.com/t/how-to-decrease-complexity-of-the-querys/109/5 "2019-09-05T17:38:59Z")

</div>

Hi  
How to get data for particular cursor value

---

<div class="post-metadata">

**Author:** ![tomasw](https://sea2.discourse-cdn.com/flex020/user_avatar/community.shiphero.com/tomasw/32/248_2.png) [@tomasw](https://community.shiphero.com/u/tomasw)\
**Post date:** [September 5, 2019, 6:00pm UTC](https://community.shiphero.com/t/how-to-decrease-complexity-of-the-querys/109/6 "2019-09-05T18:00:33Z")

</div>

Hi Daniel,  
You could do it by adding cursor along with the node. For example:

```
{
  inventory_changes(sku: "701980785238") {
    complexity
    data(first: 10) {
      pageInfo {
        hasNextPage
      }
      edges {
        node {
          cycle_counted
        }
        cursor
      }
    }
  }
}

```

also, on the page info section you can also see first and last cursors, for example:

```
{
  inventory_changes(sku: "701980785238") {
    complexity
    data(first: 10) {
      pageInfo {
        hasNextPage
        hasPreviousPage
        startCursor
        endCursor
      }
      edges {
        node {
          cycle_counted
        }
      }
    }
  }
}
```

---

<div class="post-metadata">

**Author:** ![Daniel](https://avatars.discourse-cdn.com/v4/letter/d/3ec8ea/32.png) [@Daniel](https://community.shiphero.com/u/Daniel)\
**Post date:** [September 6, 2019, 3:18am UTC](https://community.shiphero.com/t/how-to-decrease-complexity-of-the-querys/109/7 "2019-09-06T03:18:06Z")

</div>

This is correct but i want to know how to use cursor value for search criteria to find data for one cursor value, there has any mechanism to pass cursor value in the query.

---

<div class="post-metadata">

**Author:** ![tomasw](https://sea2.discourse-cdn.com/flex020/user_avatar/community.shiphero.com/tomasw/32/248_2.png) [@tomasw](https://community.shiphero.com/u/tomasw)\
**Post date:** [September 6, 2019, 12:38pm UTC](https://community.shiphero.com/t/how-to-decrease-complexity-of-the-querys/109/8 "2019-09-06T12:38:56Z")

</div>

Absolutely!, if you need to specify a cursor you can do so by adding the cursor’s value it to `data` using `after` or `before`.  
For the previous example, would be something like this:

```
{
      inventory_changes(sku: "701980785238") {
        complexity
        data(after:"YXJyYXljb25uZWN0aW9uOjk5") {
          pageInfo {
            hasNextPage
            hasPreviousPage
            startCursor
            endCursor
          }
          edges {
            node {
              cycle_counted
            }
          }
        }
      }
    }

```

This way it will now retrieve information after cursor: YXJyYXljb25uZWN0aW9uOjk5

A suggestion to keep in mind here is that cursors have a dynamic nature in pagination, this means that they might not always have the same value if the query or the data changes they also might change.

> [GraphQL Primer – Developer Resources | ShipHero](https://developer.shiphero.com/graphql-primer/#pagination)
