Node JS Shopify API crashing app how to resolve

Node JS Shopify API crashing app how to resolve

Vax
Shopify Partner
1 0 2

I'm following the shopify-api-js documentation to make requests to the GraphQL API through my app here (https://github.com/Shopify/shopify-api-js)

 

The moment I add the first import mentioned in the documentation.

 

 

import '@shopify/shopify-api/adapters/node';

I receive this error consistently and can not progress my testing.

 

╭─ error ────────────────────────────────────────────────────────────────────────────╮
│                                                                                    │
│                                                                                    │
│    The Partners GraphQL API responded unsuccessfully with the HTTP status 200 and  │
│   errors:                                                                          │
│                                                                                    │
│    [                                                                               │
│    {                                                                               │
│      "message": "Too many requests",                                               │
│      "extensions": {                                                               │
│        "code": "429"                                                               │
│      }                                                                             │
│    }                                                                               │
│  ]                                                                                 │
│                                                                                    │
│                                                                                    │
│  To investigate the issue, examine this stack trace:                               │
│    at (graphql-request/src/index.ts:410)                                           │
│      throw new ClientError(                                                        │
│    at step (graphql-request/dist/index.js:63)                                      │
│      op = body.call(thisArg, _);                                                   │
│    at next (graphql-request/dist/index.js:44)                                      │
│      function verb(n) { return function (v) { return step([n, v]); }; }            │
│    at fulfilled (graphql-request/dist/index.js:35)                                 │
│      function fulfilled(value) { try { step(generator.next(value)); } catch (e) {  │
│       reject(e); } }                                                               │
│    at processTicksAndRejections (node:internal/process/task_queues:96)             │
│                                                                                

 

I found others who were reporting a similiar issue here but it looks like there was no answer: https://community.shopify.com/c/shopify-apis-and-sdks/the-partners-graphql-api-responded-unsuccessfu...

 

 

Attempted Debugs:

  1. Created  a new app with npm init @Shopify/app@latest to see if it was just my app breaking, new demo app works (without theme extension).
  2. Tried a npm run dev -- --reset, closing out terminal, starting a new terminal, restarting comp, tried it on a different development store, still hitting the error.
Replies 4 (4)

Impress
Shopify Partner
20 1 6

Getting this all the time. If I re-run `npm run dev` about 20 times, it eventually works.

strategicsystem
Shopify Partner
8 0 1

I'm struggling with the same thing only it still doesn't connect even after 20+ attempts. The nature of the error suggests trying over and over may in fact make it worse.  Anyone figured out how to resolve this or what the actual root cause is?

Impress
Shopify Partner
20 1 6

yes  npx shopify app dev --verbose > fail.log  shows the CLI makes 5 GraphQL requests in under a second.

 

I created an issue here https://github.com/Shopify/cli/issues/1552

 

In the meantime you can work around this by editing your node_modules/@shopify/cli-kit/dist/private/node/api/graphql.js

 

on line ~6 edit:

export function graphqlRequest(query, api, url, token, variables, handleErrors = true) {
  const action = async () => {
    const headers = buildHeaders(token);

 

to read:

export function graphqlRequest(query, api, url, token, variables, handleErrors = true) {
  const action = async () => {
    await new Promise((resolve) => setTimeout(resolve, 1500));
    const headers = buildHeaders(token);
    ...

 

This will make your cli slower, but you'll save time by not re-running the command 20 times.

strategicsystem
Shopify Partner
8 0 1

Thanks a million, this works 🙂