# Optimizing a Query

**URL:** <https://community.shiphero.com/t/optimizing-a-query/789>\
**Category:** GraphQL API\
**Created:** [September 11, 2020, 11:02am UTC](https://community.shiphero.com/t/optimizing-a-query/789 "2020-09-11T11:02:13Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Thiyagarajan1](https://avatars.discourse-cdn.com/v4/letter/t/da6949/32.png) [@Thiyagarajan1](https://community.shiphero.com/u/Thiyagarajan1)\
**Post date:** [September 11, 2020, 11:02am UTC](https://community.shiphero.com/t/optimizing-a-query/789/1 "2020-09-11T11:02:14Z")

</div>

Hello

When I tired to get my user quota, I got like

```
{
    "data": {
        "user_quota": {
            "credits_remaining": 1001,
            "max_available": 1001,
            "increment_rate": 15
        }
    }
}

```

**In case if there are 200 products, having query like**

```
query {
  products {
    request_id
    complexity
    data(first: 100) {
    pageInfo { 
        hasNextPage 
        hasPreviousPage 
        startCursor 
        endCursor 
      }
      edges {
        node {
          id
          legacy_id
          account_id
          name
          sku
          warehouse_products {
            warehouse_id
            on_hand
          }
        }
      }
    }
  }
}

```

1-100 at first connection  
101-200 at second connection

**In case if there are 200 orders, having query like**

```
query {
shipments(date_from: "yyyy-mm-dd") {
request_id
complexity
data(first:10) {
  edges {
    node {
      id
      legacy_id
      order_id
      user_id
      warehouse_id
      pending_shipment_id
      address {
        name
        address1
        address2
        city
        state
        country
        zip
        phone
      }
      shipped_off_shiphero
      dropshipment
      created_date
      line_items(first: 10) {
        edges {
          node {
            line_item_id
            quantity
          }
        }
      }
      shipping_labels {
        id
        legacy_id
        account_id
        tracking_number
        carrier
        shipping_name
        shipping_method
        cost
        profile
        packing_slip
        warehouse
        insurance_amount
        carrier_account_id
        source
        created_date
      }
    }
  }
}
}
}

```

Are above queries are good practise to follow up?

---

<div class="post-metadata">

**Author:** ![Thiyagarajan1](https://avatars.discourse-cdn.com/v4/letter/t/da6949/32.png) [@Thiyagarajan1](https://community.shiphero.com/u/Thiyagarajan1)\
**Post date:** [September 14, 2020, 1:29pm UTC](https://community.shiphero.com/t/optimizing-a-query/789/2 "2020-09-14T13:29:18Z")

</div>

@tomasw

Can you please give some suggestions?

---

<div class="post-metadata">

**Author:** ![Thiyagarajan1](https://avatars.discourse-cdn.com/v4/letter/t/da6949/32.png) [@Thiyagarajan1](https://community.shiphero.com/u/Thiyagarajan1)\
**Post date:** [September 14, 2020, 4:52pm UTC](https://community.shiphero.com/t/optimizing-a-query/789/3 "2020-09-14T16:52:52Z")

</div>

@tomasw

Looking Forward to Hearing From You. Thanks!!!

---

<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 14, 2020, 5:28pm UTC](https://community.shiphero.com/t/optimizing-a-query/789/4 "2020-09-14T17:28:28Z")

</div>

Hi @Thiyagarajan1!  
I apologize for my delayed response about this.  
Absolutely, that will work, you will have to use pagination to navigate through the results:

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

Which is basically using the `endCursor` and then using it as `after:...`

If you are only interested on the On Hand you could also use the [Inventory Snapshot](https://developer.shiphero.com/inventory-snapshot/)

For the orders, you will need to do the pagination though.  
Let me know if I could explain better or if there is anything else I could help with.  
Thanks in advance!  
Tom

---

<div class="post-metadata">

**Author:** ![Thiyagarajan1](https://avatars.discourse-cdn.com/v4/letter/t/da6949/32.png) [@Thiyagarajan1](https://community.shiphero.com/u/Thiyagarajan1)\
**Post date:** [September 15, 2020, 4:08am UTC](https://community.shiphero.com/t/optimizing-a-query/789/5 "2020-09-15T04:08:10Z")

</div>

Thank you!!!

Will let you know, If I need further clarification on this.
