MONEI / Shopify-api-node

Node Shopify connector sponsored by MONEI
https://monei.com/shopify-payment-gateway/
MIT License
946 stars 278 forks source link

Getting the GraphQl Cost for the query #489

Closed ozzyonfire closed 2 years ago

ozzyonfire commented 3 years ago

Is there any way to get the requested and actual query costs back?

When running a graphQL query natively we get back an "extensions" object, like so:

"extensions": {
    "cost": {
      "requestedQueryCost": 502,
      "actualQueryCost": 502,
      "throttleStatus": {
        "maximumAvailable": 1000,
        "currentlyAvailable": 498,
        "restoreRate": 50
      }
    }
  }

I understand that we get the throttle status back from the shopify.on('callLimits', (limits) => console.log(limits)); but limits only contains restoreRate, current, remaining and max.

I'd like to be able to create a throttling function that will wait for the required number of seconds. For example, if I know my query is going cost 502, and my available cost is 498, then with a restore rate of 50, I only have to wait for 1 second. However, without knowing what the cost of my query will be, I can't properly throttle my requests.

Thanks, keep up the great work on the library!

lpinca commented 3 years ago

I'm fine with adding that info in the limits object that is emitted as an argument of the 'callGraphqlLimits' event. It should be very easy to do that. Feel free to open a PR.

pociej commented 3 years ago

@ozzyonfire i think https://github.com/MONEI/Shopify-api-node/issues/451 is related, as well as #490.