Newlines not allowed anymore in GraphQl query

Hi all,

Since yesterday (1st of august 2024), I get the following error when running Bulk Queries in GraphQl.

syntax error, unexpected invalid token ("\"") at [2, 32]

My query is as follows:

mutation MyMutation {
  bulkOperationRunQuery(query: "query Orders {
				orders(query: \"created_at:>'2024-07-26T09:21:56Z'\") {
					edges {
						node {
							id
							name
							totalDiscounts
							cartDiscountAmount
							createdAt
							billingAddress {
								address1
								address2
								city
								company
								country
								countryCode
								firstName
								id
								lastName
								name
								phone
								zip
							}
							shippingAddress {
								address1
								address2
								city
								company
								country
								countryCode
								firstName
								id
								lastName
								name
								phone
								zip
							}
							currentTotalPriceSet {
								shopMoney {
									amount
									currencyCode
								}
							}
							lineItems {
								edges {
									node {
										id
										name
										originalTotal
										originalUnitPrice
										quantity
										sku
										taxable
										title
										totalDiscount
										product {
											id
										}
										discountAllocations {
											discountApplication {
												allocationMethod
												index
												targetSelection
												targetType
												value {
													... on MoneyV2 {
														amount
														currencyCode
													}
													... on PricingPercentageValue {
														percentage
													}
												}
											}
										}
									}
								}
							}
							shippingLine {
								carrierIdentifier
								code
								custom
								deliveryCategory
								id
								phone
								price
								shippingRateHandle
								source
								title
							}
							fulfillmentOrders {
								edges {
									node {
										channelId
										createdAt
										fulfillAt
										fulfillBy
										id
										orderId
										orderName
										orderProcessedAt
										requestStatus
										status
										updatedAt
									}
								}
							}
							discountApplications {
								edges {
									node {
										allocationMethod
										index
										targetSelection
										targetType
										value {
											... on MoneyV2 {
												amount
												currencyCode
											}
											... on PricingPercentageValue {
												percentage
											}
										}
									}
								}
							}
						}
					}
				}
			}") {
    bulkOperation {
      id
    }
  }
}

I solved this by removing all the new lines.
However I wonder if this is as intended. This makes the query much less readable.

Am I missing a setting or some documentation stating this change?

Kind regards,

Robert

4 Likes

Same here, except for…

GraphqlQueryError: syntax error, unexpected invalid token ("\"") at [3, 31]

didn’t find a workaround yet, it broke basically everything for us, can’t update anything anymore.

3 Likes

Hi JoonasS,

I don’t know which language you are using, but I fixed it by using a simple regex replace.

Regex.Replace(s, @"\t|\n|\r", " ");

Have you tried this? Or is it not possible in your solutions.

2 Likes

Thanks for the suggestion, but I’m updating metafields which have json values, so I need to add the " for it to parse the values properly, I don’t know what would work to go around this, and at the same time maintain the proper structure for the fields.

I was “fixing” the prerequest, which was fine, the actual mutation was the one that needed fixing
For anyone else, here’s an example how we fix the query so it passes
Thanks @RobertTres for the tip!

const bulkUpdate = {
                        data: `mutation {
                    bulkOperationRunMutation(
                    mutation: "mutation call($input: ProductVariantInput!) { 
                        productVariantUpdate(input: $input) { 
                            userErrors {
                                message
                                field 
                            } 
                        }
                    } ",
                    stagedUploadPath: "${stagedUploadPath}") {
                        bulkOperation {
                            id
                            url
                            status
                        }
                        userErrors {
                            message
                            field
                        }
                    }
                }
                `.replace(/\n/g, '').replace(/\t/g, '').replace(/\r/g, '')
3 Likes

Thanks, we also do something similar to fi xit. But it’s really terrible something like is changed in a stable API. I hope Shopify will roll it back

2 Likes

Yes getting same error and it is fixed by removing all the new lines. You are right!

1 Like

@Liam Just to make sure someone at Shopify is aware :slightly_smiling_face:

2 Likes

I’ve done some more digging and can confirm it is indeed only bulkMutations that are affected, not bulk queries. As far as I see it’s the same for all api versions

2 Likes

@Mickeydtails FYI…We have get this issue in the productCreate mutation. There is a new line in the product description that i have removed and all good now.

Same, luckily we have the ability to supply hotfix DLL drops for our software.

Has anyone from Shopify posted anything on why this has happened? A rollback plan? or something?

This fix worked for me, thank you.

My web app broke due to this unannounced change. I’m surprised Shopify allowed this to happen.

1 Like

Yeah, they broke it.

I had to replace the escaped double quote (") with an unescaped one (")

Before:

mutation { bulkOperationRunQuery(query: """query { products(query: \"updated_at:>'1999-12-31T23:00:00Z' AND published_status:published\") {

After:

mutation { bulkOperationRunQuery(query: """query { products(query: "updated_at:>'1999-12-31T23:00:00Z' AND published_status:published") {
1 Like

Hi - is this still ongoing? Looking into this issue now.

Hi Robert,

Are you still seeing this issue? Connecting with our team on this now.

Hi Liam,
I just checked and all the queries work again!
Did you already fix the problem?

Hi again Robert - it’s possible this was a temporary bug on our side and may have already been resolved.

1 Like

Hi Liam,
Thanks for looking into it!

1 Like

I just re-tested our integration and still seeing the same issue

We do have a work around, removing newlines in the status query, however this has worked for a long time and just stopped working last week.

Update: The error we now get with the newlines is now: “Internal_Server_Error” instead of the unexpected invalid token ("\"") at [2, 32] type error

@Liam I did a quick test and the problem seem to have disappeared. Thanks