Internal error. Looks like something went wrong on our end [Graphql]

charles_loder
Shopify Partner
23 1 4

I keep getting this error:

 

{
  "errors": [
    {
      "message": "Internal error. Looks like something went wrong on our end.\nRequest ID: 99a50d82-1f02-4c3a-b14b-42c8a6c8de03 (include this in support requests).",
      "extensions": {
        "code": "INTERNAL_SERVER_ERROR",
        "requestId": "99a50d82-1f02-4c3a-b14b-42c8a6c8de03"
      }
    }
  ]
}

How do I figure out what exactly wen wrong?

Replies 5 (5)
ShopifyDevSup
Shopify Staff
Shopify Staff
1200 190 418

Hey @charles_loder thanks for sharing that request ID - I was able to take a quick look on our end and from what I can tell it looks like this was a Draft Order Update mutation? I can't say for sure what happened without more information, but is it possible that your integration/workflow is making multiple requests for the same API resource around the same time while trying to update the draft order? We might need a little more detail about your workflow here to look into this more deeply, but based on what I could see in the logs this seems like a possible reason for the error. 

Basically, if you're running  parallel processes that are trying to modify the same resource it could cause an error like the one we're seeing. This is why we'd need a little more info to properly diagnose what's causing the error.

If you are alright with a sharing code snippet that deals with how you're implementing the Draft Orders API and it doesn't reveal sensitive data, I'd be happy to see if we can troubleshoot this more deeply. My team generally doesn't handle code-level troubleshooting at the moment, but if we can take a look at how you're setting up your API calls we can possibly dig into this more with you. 

If you're still dealing with the issue, just reply back here and we can dig into it further. My team doesn't monitor the community 24/7, but we do try to look into things as quickly as possible when needed. 

Hope this helps 

Al | Shopify Developer Support

Developer Support @ Shopify
- Was this reply helpful? Click Like to let us know!
- Was your question answered? Mark it as an Accepted Solution
- To learn more visit Shopify.dev or the Shopify Web Design and Development Blog

charles_loder
Shopify Partner
23 1 4

Correct, this was a draft order update mutation, and yes, we are running processes in parallel. I'll share some relevant portions of the code with some annotations.

 

The gist of the app is this. We mark some items are "pre-order" using additional attributes on the Order. When an order has pre-order items in it, it gets sent to our app to:

  • copy an order for as many pre-order line items that are present — i.e. if an order has 2 pre-order items, the app makes 2 draft orders
  • remove the necessary line items from the newly created draft orders — i.e. one draft order has 1 preorder item, the other draft order has the other preorder item
  • complete the draft orders
  • remove the pre-order line items from the original order

The app fails at the second step for one order, but not another.

 

// get an order the has preorder items
get(order.id)
    .then((order: Order | null) => {
      if (!order) {
        return { error: "Order not found" };
      }
      // filter out the line items that are NOT preorder items
      const lineItems = order.lineItems.nodes.filter((
        lineItem: DraftOrder.LineItem,
      ) => preordersFromAttrs(order.customAttributes).includes(lineItem.name)
      );
      // this is running in parallel
      return Promise.all(
        lineItems
          .map(async (
            lineItem: DraftOrder.LineItem,
          ) => (
            // creates a new draft order based off of the order
            await DraftOrder.fromOrder(order.id)
              .then((result: Result<DraftOrder.DraftOrder, string>) =>
              (
                console.log(JSON.stringify(result)),
                "ok" in result
                  // this is where it will fail for one line item but not another
                  // it takes the one line item, and updates the Draft Order
                  // so that it only has 1 line item in it
                  // see code in next block
                  ? DraftOrder.preparePreorderFulfillmentOrder(
                    result.ok,
                    [lineItem.name],
                  )
                  : result)
              )
              // if all good, complete the order
              .then((result: Result<string, string>) =>
                "ok" in result ? DraftOrder.complete(result.ok) : result
              )
              // update tags
              .then((result: Result<string, string>) =>
                "ok" in result
                  ? tag(result.ok, [
                    `__preorder_app:parent_${order.legacyResourceId}`,
                  ])
                  : result
              ))
          ),
      )
      // after Promise.all, so no longer parallel
        .then((
          results: Result<Order, string>[],
        ) => (console.log(
          "createPreorderFulfillmentOrders after Promise.all",
          results,
        ),
          results[0])
        );
    });

 

 

Though the processes are running in parallel, the mutations on each individual draft order are happening sequentially.

Here is the mutation that is failing:

const preparePreorderFulfillmentOrderMutation: string = `
  mutation preparePreorderFulfillmentOrder($id: ID!, $input: DraftOrderInput!) {
    draftOrderUpdate(id: $id, input: $input) {
      draftOrder {
        id
      }
      userErrors {
        field
        message
      }
    }
  }
`;

// this updates the Draft Order so that there is only 1 line item in it
// the pre-order item from the Promise.all map
const preparePreorderFulfillmentOrder = (
  draftOrder: DraftOrder,
  preorders: string[],
): Promise<Result<string, string>> =>
  Shopify.request(
    JSON.stringify({
      query: preparePreorderFulfillmentOrderMutation,
      variables: {
        id: draftOrder.id,
        input: {
          lineItems: draftOrder.lineItems.nodes
            .filter((lineItem: LineItem) => preorders.includes(lineItem.name))
            .map((lineItem: LineItem) => (console.log("preparePreorderFulfillmentOrder map", lineItem), {
              appliedDiscount: {
                description: "Preorder fulfillment",
                value: 100.0,
                valueType: "PERCENTAGE",
              },
              quantity: lineItem.quantity,
              variantId: lineItem.variant.id,
            })),
          tags: draftOrder.tags
            .filter((tag: string) => !tag.match("__preorder*"))
            .concat("__preorder_app:preorder_fulfillment"),
        },
      },
    }),
  ).then(
    // ...just ensure that we return an "ok" in our results
  );

Apologies for so much!

You say,
"but is it possible that your integration/workflow is making multiple requests for the same API resource around the same time while trying to update the draft order? "

 

I'll experiment with just adding a delay between the Draft Order creation and the Draft Order update and see if it that works

charles_loder
Shopify Partner
23 1 4

Update, adding delays did not seem to help:

await DraftOrder.fromOrder(order.id)
// create an order, then 1 second delay
  .then((result: Result<DraftOrder.DraftOrder, string>) => 
(console.log('Delaying...'),Shopify.delay(1000), result)) 
  .then((result: Result<DraftOrder.DraftOrder, string>) =>
    (
      console.log(JSON.stringify(result)),
      "ok" in result
        ? DraftOrder.preparePreorderFulfillmentOrder(
          result.ok,
          [lineItem.name],
          )
        : result)
      )
// updates the order, then 1 second delay
  .then((result: Result<string, string>) =>(console.log('Delaying...'),Shopify.delay(1000), result))
  .then((result: Result<string, string>) =>
    "ok" in result ? DraftOrder.complete(result.ok) : result
  )
charles_loder
Shopify Partner
23 1 4

@ShopifyDevSup  just following up with this.

 

Note that the above code isn't completely correct, but even when corrected, the delays (even up to 3 seconds) don't remedy the issue

ShopifyDevSup
Shopify Staff
Shopify Staff
1200 190 418

Hey @charles_loder - thanks for sharing that info. This is a little out of my team's scope as I'm not a JS developer and my experience is with APIs (REST/GraphQL syntax, architecture, schemas more generally, but I do have some basic JS understanding). From what I can see even adding that await delay isn't helping as you mentioned - so it does seem like this might be related to something on our end. I can't totally confirm that's the case based on the info above, but I am definitely happy to do some more digging into this - and thanks for waiting on the reply here, I know it's been a bit of a wait. 

If you're still encountering the issue, could you share a recent X-Request-ID from within the last ~10 days that's attached to an example of the Internal Server error you're seeing and I'll prioritizing digging into this on our end for you. Like I mentioned, I can't guarantee response times through our forums here and we don't offer code-level support through the forums or more generally, but in this case, I'm happy to get in touch with my team and potentially our product teams to see if we can see why this issue is presenting and if it's related to resources/behaviour on our end. 

I did also notice you may have reached out to our Partner Support team directly - what I might recommend here for the best next steps is reaching out again on that same email thread and linking directly to this forum post along with a new, more recent X-Request ID. We can ask the Partner Specialist that you'll speak with to reach out directly to my team (API Support) internally with the updated information and we should be able to investigate that way. This would speed up the support process as we have processes internally to facilitate cross-team collaboration, especially if we can tie it to this forum post directly for the extra context.  

Hope this helps and hope to hear from you soon. If you do prefer to go through the forums, I'll monitor this thread for your reply - it may just be easier to troubleshoot if we can through email.

Al | Shopify Developer Support

Developer Support @ Shopify
- Was this reply helpful? Click Like to let us know!
- Was your question answered? Mark it as an Accepted Solution
- To learn more visit Shopify.dev or the Shopify Web Design and Development Blog